Skip to content

Commit

Permalink
Use date_published in website
Browse files Browse the repository at this point in the history
  • Loading branch information
gherkster committed Feb 27, 2025
1 parent 19268da commit 1e080e8
Show file tree
Hide file tree
Showing 8 changed files with 3,897 additions and 3,625 deletions.
2,520 changes: 1,261 additions & 1,259 deletions common/types/directus-schema.d.ts

Large diffs are not rendered by default.

4,552 changes: 2,282 additions & 2,270 deletions openapi/directus.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions website/clients/useDirectusApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const useDirectusApi = () => {
query: {
fields: searchFields,
filter: `{"status":{"_eq":"published"}}`,
sort: ["-date_created"],
sort: ["-date_published"],
},
},
querySerializer: {
Expand All @@ -66,7 +66,14 @@ export const useDirectusApi = () => {
}

const mapper = useMapper();
return { data: data.data?.map((r) => mapper.toRecipePreview(r)) };
const now = new Date();

return {
data: data.data
?.map((r) => mapper.toRecipePreview(r))
// A missing date_published value means the recipe is brand new and the publish date has not been set in the record yet, so use the current time.
.sort((a, b) => (b.date_published ?? now).getTime() - (a.date_published ?? now).getTime()),
};
},
getRecipe: async (slug: string) => {
const { data, error } = await client.GET("/items/recipes", {
Expand Down
2 changes: 1 addition & 1 deletion website/composables/useMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function toRecipePreview(serverRecipe: ServerRecipe): RecipePreview {
descriptionSnippet: serverRecipe.description_snippet,
course: serverRecipe.course ?? undefined,
cuisine: serverRecipe.cuisine ?? undefined,
date_created: serverRecipe.date_created!,
date_published: serverRecipe.date_published ? new Date(serverRecipe.date_published) : undefined,
favourite: serverRecipe.favourite ?? undefined,
featuredTag: getRandomTag(tags, serverRecipe.id!),
preparationDuration: serverRecipe.preparationDuration ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"typescript": "5.6.3",
"unplugin-icons": "^0.19.3",
"vue-tsc": "^2.2.4",
"wrangler": "3.19.0"
"wrangler": "3.111.0"
},
"packageManager": "[email protected]"
}
Loading

0 comments on commit 1e080e8

Please sign in to comment.