Workflow - Add step to refresh Algolia index#2614
Conversation
|
/deploy |
There was a problem hiding this comment.
Pull request overview
Updates the search/Algolia indexing pipeline and UI to better handle refreshed Algolia records (notably timestamp serialization changes) and improve author metadata display on search results.
Changes:
- Update date parsing utilities to support Unix-second timestamps (expected from Algolia Python client v3).
- Improve search result author display/URL resolution and provide a timestamp fallback (created vs lastUpdated).
- Extend the build workflow to install Algolia Python deps and run an Algolia sync step; remove an unused import.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
lib/dateUtils.ts |
Adds Unix-seconds parsing when building Date objects for UI formatting. |
app/search/page.tsx |
Removes an unused Layout import. |
app/search/client-page.tsx |
Enhances author name/url selection and falls back to created when lastUpdated is missing. |
.github/workflows/build-artifacts.yml |
Installs Algolia Python client and runs a Python sync step after generating the Tina search index. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const raw = Number(isoString); | ||
| // Algolia's Python v3 client serialises datetime objects as Unix seconds. | ||
| // A 10-digit number is seconds (year ~2001-2286); multiply to get ms. | ||
| const date = !isNaN(raw) && raw < 1e12 ? new Date(raw * 1000) : new Date(isoString); |
There was a problem hiding this comment.
The Unix timestamp detection is too broad and can mis-parse non-timestamp numeric strings (e.g., "2024" or other short numeric IDs) as seconds. It also doesn't correctly handle millisecond timestamps when they arrive as a numeric string (13 digits): those fall through to new Date(isoString), which is not reliably parsed. Consider detecting ^\d{10}$ as seconds and ^\d{13}$ as milliseconds (or, more generally, if Number.isFinite(raw) then use new Date(raw < 1e12 ? raw * 1000 : raw)), and only fall back to new Date(isoString) for non-numeric strings.
| export function formatDateLong(iso: string): string { | ||
| const date = new Date(iso); | ||
| const raw = Number(iso); | ||
| const date = !isNaN(raw) && raw < 1e12 ? new Date(raw * 1000) : new Date(iso); | ||
| return date.toLocaleDateString("en-AU", { |
There was a problem hiding this comment.
The Unix-seconds parsing logic is duplicated between timeAgo and formatDateLong. To keep behavior consistent (and reduce the chance of future drift), consider extracting a small helper (e.g., parseDateInput) and reusing it in both functions.
| const getAuthorUrl = (r: any): string | null => { | ||
| const name = getDisplayName(r); | ||
| if (name) return `https://ssw.com.au/people/${toSlug(name)}/`; | ||
| return r.authors?.[0]?.url || null; | ||
| }; | ||
|
|
||
| const getResolvedAuthorUrl = (r: any): string | null => { | ||
| if (r.lastUpdatedBy || r.createdBy) return getAuthorUrl(r); |
There was a problem hiding this comment.
getAuthorUrl is only called from getResolvedAuthorUrl when lastUpdatedBy or createdBy is present, so the fallback return r.authors?.[0]?.url || null is effectively redundant for the "authors-only" case (which is already handled in getResolvedAuthorUrl). Consider simplifying the two helpers into a single function (or removing the fallback) to make the branching rules easier to follow.
| const getAuthorUrl = (r: any): string | null => { | |
| const name = getDisplayName(r); | |
| if (name) return `https://ssw.com.au/people/${toSlug(name)}/`; | |
| return r.authors?.[0]?.url || null; | |
| }; | |
| const getResolvedAuthorUrl = (r: any): string | null => { | |
| if (r.lastUpdatedBy || r.createdBy) return getAuthorUrl(r); | |
| const getResolvedAuthorUrl = (r: any): string | null => { | |
| if (r.lastUpdatedBy || r.createdBy) { | |
| const name = getDisplayName(r); | |
| return name ? `https://ssw.com.au/people/${toSlug(name)}/` : null; | |
| } |
#2592
This pull request introduces improvements to the search functionality and Algolia index synchronization, as well as enhancements to date handling for better robustness and accuracy. The main changes include adding a new workflow step to sync the Algolia index, improving author display logic in search results, and updating date parsing utilities to handle multiple input formats.
Algolia Index Synchronization:
.github/workflows/build-artifacts.yml: Added steps to install Python dependencies and run a script (algolia_sync.py) to synchronize the Algolia index during the build process.Search Results Author Handling:
app/search/client-page.tsx: Improved the logic for displaying and linking to authors in search results by considering additional fields (authors[0].titleandauthors[0].url) as fallbacks.app/search/client-page.tsx: Updated the waylastUpdatedByandlastUpdatedare passed to components, now using the improved display name logic and providing fallbacks for missing dates.Date Parsing and Formatting:
lib/dateUtils.ts: Introduced aparseDateInputfunction to robustly handle timestamps in seconds, milliseconds, or ISO string formats, and updatedtimeAgoandformatDateLongto use this function. [1] [2]Code Cleanup:
app/search/page.tsx: Removed an unused import ofLayoutfor minor code cleanup.