diff --git a/package.json b/package.json index c0e6adc4d2b..07e6e60416a 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "google-font-metadata": "^5.2.1", "json-stringify-pretty-compact": "^4.0.0", "pathe": "^1.1.1", + "smol-string": "^1.0.0", "tsx": "^3.12.7" }, "homepage": "https://fontsource.org", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf4475f885c..da44b8b8ae1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ dependencies: pathe: specifier: ^1.1.1 version: 1.1.1 + smol-string: + specifier: ^1.0.0 + version: 1.0.0 tsx: specifier: ^3.12.7 version: 3.12.7 @@ -1885,6 +1888,10 @@ packages: engines: {node: '>= 6.0.0', npm: '>= 3.0.0'} dev: false + /smol-string@1.0.0: + resolution: {integrity: sha512-rfStKm6kcqIqjWbBqhA6vvjJoVloy+dRqBzo+IA2qdCZgi/qmEEkBxJ6UjQsW8sTQ+IK4EVBBrSobSMPbL7qkA==} + dev: false + /socks-proxy-agent@8.0.2: resolution: {integrity: sha512-8zuqoLv1aP/66PHF5TqwJ7Czm3Yv32urJQHrVyhD7mmA6d61Zv8cIXQYPTWwmg6qlupnPvs/QKDmfa4P/qct2g==} engines: {node: '>= 14'} diff --git a/scripts/algolia.ts b/scripts/algolia.ts index a25da696ee7..8e1913f7bcc 100644 --- a/scripts/algolia.ts +++ b/scripts/algolia.ts @@ -1,5 +1,6 @@ import algoliasearch from 'algoliasearch'; import metadataImport from '../metadata/fontsource.json'; +import { compress } from 'smol-string'; interface AlgoliaMetadata { objectID: string; @@ -64,6 +65,8 @@ const updateAlgoliaIndex = async (force?: boolean) => { category: metadata.category, defSubset: metadata.defSubset, variable: Boolean(metadata.variable), + // We need to compress the unicode range to fit in Algolia's 10kb limit + unicodeRange: compress(JSON.stringify(metadata.unicodeRange)), // Algolia sorts date using a unix timestamp instead lastModified: Math.floor( new Date(metadata.lastModified).getTime() / 1000