Sorting options - #331
Sorting options#331maryLLay wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
@maryLLay I'm going to add some issues that Claude flagged in a review of the code.
| echo "No changes to commit." | ||
| else | ||
| git commit -m "chore: update project last-updated dates" | ||
| git push |
There was a problem hiding this comment.
This push to main uses the default GITHUB_TOKEN. GitHub does not fire other on: push workflows for pushes made with that token, so deploy-to-github-pages.yml will never run after the bot commits. The live site will keep stale update_date values until an unrelated human commit lands on main.
Fix: add a final step that triggers the deploy explicitly, and grant the job actions: write:
- name: Trigger deploy
if: steps.commit.outputs.pushed == 'true'
run: gh workflow run deploy-to-github-pages.yml
env:
GH_TOKEN: ${{ github.token }}|
|
||
| let result; | ||
| try { | ||
| result = await graphqlWithAuth(query, variables); |
There was a problem hiding this comment.
All repos are batched into a single GraphQL query. If any one repo has been renamed, deleted, or made private, GitHub returns data.rN: null plus an errors array, and @octokit/graphql throws a GraphqlResponseError even though the partial data for every other repo is available on error.data.data. This catch then calls process.exit(1), so one bad link fails the whole weekly job, and the per-repo console.warn branch below is unreachable for this case.
Fix: recover the partial result in the catch and only exit when there is no data at all:
} catch (error) {
if (error.data?.data) {
console.warn("GraphQL returned partial data:", error.message);
result = error.data.data;
} else {
console.error("GraphQL query failed:", error.message);
process.exit(1);
}
}| ) | ||
| )} | ||
|
|
||
| <div className="mb-4"> |
There was a problem hiding this comment.
Heads up, not a blocker: this new "Sort by" block lives in the shared FilterMenu, which /ecosystems also renders. The ecosystems CardContainers do not receive a sortedTitlesMap, so on that page clicking a sort option highlights it and writes ?sort= to the URL but does not change card order.
We do not currently use the ecosystems route, so this has no user-facing impact today. If we keep the route, the fix is either to gate this block behind a showSort prop or to pass a sortedTitlesMap from the ecosystems page. Alternatively, we could consider removing the ecosystems route entirely in a separate PR.
There was a problem hiding this comment.
Note: This will no longer be an issue if you merge the changes in maryLLay#1
| } | ||
| }); | ||
|
|
||
| writeFileSync(REPO_DATES_PATH, JSON.stringify(repoDates, null, 2) + "\n"); |
There was a problem hiding this comment.
Nothing reads repo-dates.json. The only references in the repo are this write, the REPO_DATES_PATH constant, and the git add in the workflow. The site consumes update_date from each project's frontmatter, and this script regenerates repoDates from the API on every run rather than reading the file back, so it is not a cache either.
Keeping it means every weekly bot commit carries a JSON diff nobody uses, and the same dates now live in two places that can drift after a hand edit or merge conflict.
Suggested fix, all deletions:
- Delete
.github/actions/repo-dates.json. - Remove the
REPO_DATES_PATHconstant (line 9). - Remove this
writeFileSyncand theconsole.logthat follows it. - Drop
.github/actions/repo-dates.jsonfrom thegit addinupdate-project-dates.yml(line 42).
repoDates stays in memory, which is all step 4 needs.
If a record of what the API returned is useful for debugging, log it to the job output instead of committing it:
console.log(JSON.stringify(repoDates, null, 2));Or, if you want a downloadable file, write it to $RUNNER_TEMP and add an actions/upload-artifact step in the workflow. Either way it shows up per run without touching the repo history.
| projectType={content.data["project type"][0]} | ||
| contentType="projects" | ||
| maxLength={allProjects.length} | ||
| sortedTitlesMap={sortedTitlesMap} |
There was a problem hiding this comment.
Each CardContainer is a client:only island, so Astro serializes every prop into that island's HTML. Passing the full sortedTitlesMap here means all three title arrays (roughly 4 KB as JSON) are embedded once per card, about 150 KB of duplicated text on /projects/ today, growing O(n²) with project count. It also makes the client-side indexOf(title) in CardContainer.jsx depend on the display title as an identifier, so two projects with the same title share an order, and a title with stray whitespace returns -1 and pins the card to the front.
The server already knows each card's position in every sort, so compute the three indices once per card and pass three integers instead of three arrays:
allProjects.map((content) => {
const tagsObj = getTagKeysAndValues(content);
const title = content.data.title;
const sortOrder = {
alphabetical: sortedTitlesMap.alphabetical.indexOf(title),
"updated-newest": sortedTitlesMap["updated-newest"].indexOf(title),
"updated-oldest": sortedTitlesMap["updated-oldest"].indexOf(title),
};
return (
<CardContainer
...
sortOrder={sortOrder}
client:only="react"
>Then in CardContainer.jsx:
} else if (sortOrder && Number.isInteger(sortOrder[$selectedSort])) {
itemOrder = sortOrder[$selectedSort];
} else {
itemOrder = Math.floor(Math.random() * maxLength);
}Per-island payload drops to a few dozen bytes and the client does no array scan.
Optional follow-on: build the three sorted arrays from content.id rather than content.data.title so duplicate titles cannot collide on the server side either.
# Conflicts: # .github/actions/package-lock.json # .github/actions/package.json # package-lock.json
🚩 Potential issue - invalid frontmatterOne or more of your committed Markdown files might be missing frontmatter or have an invalid structure. If your PR is to add or edit a project file, please double-check your frontmatter is wrapped in triple dashes (---).
|
🎉 Thank you for your contribution!The website maintainers will review your PR soon. |
Added options to sort alphabetically or by most recent update.
Please look at how sort by last update is implemented: I'm not sure this is the best way to pull this off.