Skip to content

Commit

Permalink
fix: admin document ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Oct 27, 2024
1 parent 3ac9cfb commit b8a6235
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/assets/js/lib/albums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Album = {
}

function sort(albums: Album[]): Album[] {
return albums.sort((a, b) => a.date.localeCompare(b.date) * -1)
return albums.sort((a, b) => b.date.localeCompare(a.date))
}

export function read(): Album[] {
Expand Down
22 changes: 12 additions & 10 deletions src/functions/admin/files/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@ import { minimal } from "../../../layouts/minimal"
export const admin = defineAkteFile<GlobalData>().from({
path: "/admin",
async data() {
const [albums, docs] = await Promise.all([
getClient().getAllByType("post__album"),
let [docs, albums] = await Promise.all([
getClient().getAllByType("post__document--private"),
getClient().getAllByType("post__album"),
])

for (const album of albums) {
if (!album.url) {
for (const doc of docs) {
if (!doc.url) {
throw new Error(
`Unable to resolve URL for album: ${JSON.stringify(album)}`,
`Unable to resolve URL for doc: ${JSON.stringify(doc)}`,
)
}
album.url = `${album.url}-${await sha256(album.uid!, process.env.PRISMIC_TOKEN!, 7)}`
doc.url = `${doc.url}-${await sha256(doc.uid!, process.env.PRISMIC_TOKEN!, 7)}`
}
docs = docs.sort((a, b) => b.first_publication_date.localeCompare(a.first_publication_date))

for (const doc of docs) {
if (!doc.url) {
for (const album of albums) {
if (!album.url) {
throw new Error(
`Unable to resolve URL for doc: ${JSON.stringify(doc)}`,
`Unable to resolve URL for album: ${JSON.stringify(album)}`,
)
}
doc.url = `${doc.url}-${await sha256(doc.uid!, process.env.PRISMIC_TOKEN!, 7)}`
album.url = `${album.url}-${await sha256(album.uid!, process.env.PRISMIC_TOKEN!, 7)}`
}
albums = albums.sort((a, b) => b.data.published_date.localeCompare(a.data.published_date))

return { albums, docs }
},
Expand Down

0 comments on commit b8a6235

Please sign in to comment.