{"id":18023992,"url":"https://github.com/lete114/fontmin-spider","last_synced_at":"2025-06-26T20:36:47.431Z","repository":{"id":65231667,"uuid":"588498558","full_name":"Lete114/fontmin-spider","owner":"Lete114","description":"Analyze which fonts are used on the page and eliminate the ones that are not used to get a smaller font file","archived":false,"fork":false,"pushed_at":"2023-02-24T08:11:15.000Z","size":4655,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T18:11:21.329Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lete114.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-13T09:10:47.000Z","updated_at":"2024-11-20T02:22:22.000Z","dependencies_parsed_at":"2024-10-30T07:46:46.015Z","dependency_job_id":null,"html_url":"https://github.com/Lete114/fontmin-spider","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lete114%2Ffontmin-spider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lete114%2Ffontmin-spider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lete114%2Ffontmin-spider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lete114%2Ffontmin-spider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lete114","download_url":"https://codeload.github.com/Lete114/fontmin-spider/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245760562,"owners_count":20667886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T07:11:37.648Z","updated_at":"2025-03-27T00:30:46.695Z","avatar_url":"https://github.com/Lete114.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fontmin-spider\n\nAnalyze which fonts are used on the page and eliminate the ones that are not used to get a smaller font file\n\n## Install\n\n```bash\nnpm install fontmin-spider\n```\n\n## Usage\n\n```js\nconst { spider, parse } = require('fontmin-spider')\n\n;(async () =\u003e {\n  const basePath = '/home/site/'\n  // Recursively read all html files in the /home/site/ directory\n  // default: **/*.html\n  await spider({ basePath })\n\n  /* \n    // css\n    p {\n      font-family: 'fontName';\n    }\n\n    // html\n    \u003cp\u003eAnalyze which fonts are used on the page and eliminate the ones that are not used to get a smaller font file\u003c/p\u003e\n  */\n  const files = ['/home/site/index.html', '/home/site/post/index.html', '/home/site/page/index.html']\n  // It only parses, it does not compress\n  const fontMaps = parse(basePath, files)\n  console.log(fontMaps)\n  /*\n    {\n      fontName: {\n        selector: [ 'p' ],\n        path: '/home/site/font/font-file.ttf',\n        chars: 'Analyzewhicfotsrudpgm'\n      }\n      ....\n    }\n  */\n})()\n```\n\nThis is an example: compress only specified characters, e.g. only [CJK](https://wikipedia.org/wiki/CJK_characters) (CJK Unified Ideographs) characters\n\n```js\nconst { spider } = require('fontmin-spider')\nfunction getCJK(str: string) {\n  const reg =\n    /[\\u4e00-\\u9fa5\\u3040-\\u30ff\\u31f0-\\u31ff\\uff00-\\uff9f\\u3000-\\u303f\\uff01-\\uff0f\\uff1a-\\uff20\\uff3b-\\uff40\\uff5b-\\uff60\\uffe0-\\uffe6]/g\n  const cjkChars = str.match(reg)\n  return cjkChars ? cjkChars.join('') : ''\n}\n;(async () =\u003e {\n  const basePath = '/home/site/'\n  // Recursively read all html files in the /home/site/ directory\n  // default: **/*.html\n  await spider({\n    basePath,\n    /**\n     * Execute the filter function after parsing is complete\n     * @param { { selector: string[]; path: string; chars: string } } declaredFamilyMap Font parameters\n     */\n    afterFilter(declaredFamilyMap) {\n      for (const [, value] of Object.entries(declaredFamilyMap)) {\n        value.chars = getCJK(value.chars)\n      }\n    }\n  })\n})()\n```\n\n## API\n\n### spider(options)\n\nCrawl the fonts referenced by the specified .html file for compression.\nmatching the text used according to the css selector, compressing on demand\n\n#### options.basePath\n\nType: `string`\n\nRequired: `true`\n\nYou can think of it as the root of the website\n\n### options.source\n\nType: `string | string[]`\n\nSee [fast-glob](https://github.com/mrmlnc/fast-glob#patterns) for details\n\n### options.backup\n\nType: `boolean`\n\nDefault: `true`\n\nbackup font (font.backup.ttf)\n\n### options.reserveText\n\nType: `string | object`\n\nReserved text. For example, when using JavaScript to add text dynamically.\nthe fontmin-spider will not be able to parse the text and you will need to add the reserved text manually\n\n```js\nconst { spider, parse } = require('fontmin-spider')\n\n;async () =\u003e {\n  const basePath = '/home/site/'\n  // Even if 'ABCDEFG' is not used, 'fontmin-spider' does not eliminate it and remains in the font file\n  await spider({ basePath, reserveText: 'ABCDEFG' })\n\n  // Settings for specific fonts only\n  /* p {\n      font-family: 'fontName';\n    } \n  */\n  await spider({ basePath, reserveText: { fontName: 'ABCDEFG', fontName2: '1234567890' } })\n}\n```\n\n### options.ignore\n\nType: `string[]`\n\nSee [fast-glob](https://github.com/mrmlnc/fast-glob#ignore) for details\n\n### parse(basePath, files)\n\n#### basePath\n\nType: `string`\n\nRequired: `true`\n\nYou can think of it as the root of the website\n\n#### files\n\nType: `string[]`\n\nRequired: `true`\n\nArray type html file (absolute path)\n\n#### filter\n\nType: `Function`\n\nRequired: `false`\n\nExecute when all the used fonts are parsed (the strings are not parsed, you can use the afterFilter method if you need to process the strings)\n\n#### afterFilter\n\nType: `Function`\n\nRequired: `false`\n\nAfter parsing is complete, execute\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flete114%2Ffontmin-spider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flete114%2Ffontmin-spider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flete114%2Ffontmin-spider/lists"}