Skip to content

Commit

Permalink
feat: add unicode range to algolia index
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Apr 13, 2024
1 parent 7b1c502 commit 5c791ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions scripts/algolia.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import algoliasearch from 'algoliasearch';
import metadataImport from '../metadata/fontsource.json';
import { compress } from 'smol-string';

interface AlgoliaMetadata {
objectID: string;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5c791ba

Please sign in to comment.