feat(tags): this adds support for post, link, book, show and movie tags with a tag list view and per tag pages
This commit is contained in:
parent
3d866262ca
commit
6fdc0b56b9
35 changed files with 500 additions and 70 deletions
36
src/data/tags.js
Normal file
36
src/data/tags.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||
|
||||
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
|
||||
|
||||
export default async function () {
|
||||
const res = await EleventyFetch(`${POSTGREST_URL}/optimized_all_tags?order=tag.asc`, {
|
||||
duration: "1h",
|
||||
type: "json",
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${POSTGREST_API_KEY}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
const tags = await res;
|
||||
const groupedMap = new Map();
|
||||
|
||||
for (const tag of tags) {
|
||||
const letter = /^[a-zA-Z]/.test(tag.tag) ? tag.tag[0].toUpperCase() : "#";
|
||||
|
||||
if (!groupedMap.has(letter)) groupedMap.set(letter, []);
|
||||
|
||||
groupedMap.get(letter).push(tag);
|
||||
}
|
||||
|
||||
const grouped = [...groupedMap.entries()]
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
.map(([letter, tags]) => ({
|
||||
letter,
|
||||
tags: tags.sort((a, b) => a.tag.localeCompare(b.tag)),
|
||||
}));
|
||||
|
||||
return grouped;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue