diff --git a/.github/workflows/build-artifacts.yml b/.github/workflows/build-artifacts.yml index f65294d05..4ec3a7c34 100644 --- a/.github/workflows/build-artifacts.yml +++ b/.github/workflows/build-artifacts.yml @@ -636,6 +636,7 @@ jobs: NEXT_PUBLIC_GITHUB_REPO: ${{ vars.NEXT_PUBLIC_GITHUB_REPO }} run: pnpm tinacms search-index + - name: Install Algolia Python dependencies run: pip install pyyaml "algoliasearch>=3,<4" @@ -645,4 +646,14 @@ jobs: NEXT_PUBLIC_ALGOLIA_APP_ID: ${{ inputs.NEXT_PUBLIC_ALGOLIA_APP_ID }} NEXT_PUBLIC_ALGOLIA_ADMIN_KEY: ${{ secrets.NEXT_PUBLIC_ALGOLIA_ADMIN_KEY }} NEXT_PUBLIC_ALGOLIA_INDEX_NAME: ${{ inputs.NEXT_PUBLIC_ALGOLIA_INDEX_NAME }} - run: python algolia_sync.py \ No newline at end of file + run: python algolia_sync.py + + - name: Patch rule body content in Algolia index + env: + NEXT_PUBLIC_ALGOLIA_APP_ID: ${{ secrets.NEXT_PUBLIC_ALGOLIA_APP_ID }} + NEXT_PUBLIC_ALGOLIA_ADMIN_KEY: ${{ secrets.NEXT_PUBLIC_ALGOLIA_ADMIN_KEY }} + NEXT_PUBLIC_ALGOLIA_INDEX_NAME: ${{ secrets.NEXT_PUBLIC_ALGOLIA_INDEX_NAME }} + run: | + cd content/scripts/tina-migration/algolia-indexer + npm install + node update_algolia_index.js diff --git a/app/search/client-page.tsx b/app/search/client-page.tsx index b01b9bd69..87122d135 100644 --- a/app/search/client-page.tsx +++ b/app/search/client-page.tsx @@ -22,6 +22,15 @@ interface SearchResult { objectID: string; title: string; slug: string; + _snippetResult?: { + content?: { value: string; matchLevel: string }; + [key: string]: any; + }; + _highlightResult?: { + title?: { value: string; matchLevel: string }; + content?: { value: string; matchLevel: string }; + [key: string]: any; + }; [key: string]: any; } @@ -163,6 +172,11 @@ export default function RulesSearchClientPage({ ruleCount, latestRulesByUpdated lastUpdated={result.lastUpdated ?? result.created ?? null} index={index} authorUrl={getAuthorUrl(result)} + snippet={ + result._snippetResult?.content?.matchLevel !== "none" + ? result._snippetResult?.content?.value + : null + } /> ))} diff --git a/components/RuleCard.tsx b/components/RuleCard.tsx index d86b7ef2c..bbd3f7ac4 100644 --- a/components/RuleCard.tsx +++ b/components/RuleCard.tsx @@ -11,6 +11,7 @@ interface RuleCardProps { index?: number; authorUrl?: string | null; skeletonMeta?: boolean; + snippet?: string | null; } function isHttpUrl(value?: string | null) { @@ -18,7 +19,7 @@ function isHttpUrl(value?: string | null) { return /^https?:\/\//i.test(value.trim()); } -export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, index, authorUrl, skeletonMeta }: RuleCardProps) { +export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, index, authorUrl, skeletonMeta, snippet }: RuleCardProps) { const showLink = !skeletonMeta && isHttpUrl(authorUrl) && (lastUpdatedBy || "Unknown") !== "Unknown"; return ( @@ -31,6 +32,13 @@ export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, inde