Skip to content

Workflow - Add step to refresh Algolia index#2614

Merged
Freego1783 merged 5 commits intomainfrom
2592-refresh-algolia-index
Apr 28, 2026
Merged

Workflow - Add step to refresh Algolia index#2614
Freego1783 merged 5 commits intomainfrom
2592-refresh-algolia-index

Conversation

@Aibono1225
Copy link
Copy Markdown
Member

@Aibono1225 Aibono1225 commented Apr 27, 2026

#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:

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].title and authors[0].url) as fallbacks.
  • app/search/client-page.tsx: Updated the way lastUpdatedBy and lastUpdated are passed to components, now using the improved display name logic and providing fallbacks for missing dates.

Date Parsing and Formatting:

  • lib/dateUtils.ts: Introduced a parseDateInput function to robustly handle timestamps in seconds, milliseconds, or ISO string formats, and updated timeAgo and formatDateLong to use this function. [1] [2]

Code Cleanup:

@Aibono1225
Copy link
Copy Markdown
Member Author

/deploy

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .github/workflows/build-artifacts.yml Outdated
Comment thread .github/workflows/build-artifacts.yml
Comment thread lib/dateUtils.ts Outdated
Comment on lines +2 to +5
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);
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lib/dateUtils.ts
Comment on lines 23 to 26
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", {
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread app/search/client-page.tsx Outdated
Comment on lines +116 to +123
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);
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SSWConsulting SSWConsulting deleted a comment from github-actions Bot Apr 27, 2026
@Aibono1225 Aibono1225 changed the title 2592 refresh algolia index Workflow - Add step to refresh Algolia index Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants