Improve schema and update tags
- Make constants in schema explicit - Enumerate tag-categories - More i18n utilities - Better anonymous user support without special field - Remove most tuples and unchecked type-casting
This commit is contained in:
parent
579e5879e1
commit
17ef8c652c
34 changed files with 223 additions and 221 deletions
|
|
@ -27,17 +27,17 @@ const categorizedTags = Object.fromEntries(
|
|||
),
|
||||
),
|
||||
);
|
||||
const tags = props.tags.map<[string, string]>((tag) => {
|
||||
const tagSlug = slug(tag);
|
||||
const tags = props.tags.map<{ id: string; name: string }>((tag) => {
|
||||
const id = slug(tag);
|
||||
if (!(tag in categorizedTags)) {
|
||||
console.warn(`Tag "${tag}" doesn't have a category in the "tag-categories" collection`);
|
||||
return [tagSlug, tag];
|
||||
return { id, name: tag };
|
||||
}
|
||||
if (categorizedTags[tag] == null) {
|
||||
console.warn(`No "${props.lang}" translation for tag "${tag}"`);
|
||||
return [tagSlug, tag];
|
||||
return { id, name: tag };
|
||||
}
|
||||
return [tagSlug, categorizedTags[tag]!];
|
||||
return { id, name: categorizedTags[tag]! };
|
||||
});
|
||||
const thumbnail =
|
||||
props.thumbnail &&
|
||||
|
|
@ -217,10 +217,10 @@ const thumbnail =
|
|||
Tags
|
||||
</h2>
|
||||
<ul class="flex flex-wrap gap-x-2 gap-y-2 px-2">
|
||||
{tags.map(([tagSlug, tagText]) => (
|
||||
{tags.map(({ id, name }) => (
|
||||
<li class="rounded-full bg-bm-300 px-3 py-1 text-sm text-black shadow-sm dark:bg-bm-600 dark:text-white print:bg-none">
|
||||
<a class="hover:underline focus:underline" href={`/tags/${tagSlug}`}>
|
||||
{tagText}
|
||||
<a class="hover:underline focus:underline" href={`/tags/${id}`}>
|
||||
{name}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -39,22 +39,22 @@ const categorizedTags = Object.fromEntries(
|
|||
),
|
||||
),
|
||||
);
|
||||
const tags = props.tags.map<[string, string]>((tag) => {
|
||||
const tags = props.tags.map<{ id: string; name: string }>((tag) => {
|
||||
const tagSlug = slug(tag);
|
||||
if (!(tag in categorizedTags)) {
|
||||
console.warn(`Tag "${tag}" doesn't have a category in the "tag-categories" collection`);
|
||||
return [tagSlug, tag];
|
||||
return { id: tagSlug, name: tag };
|
||||
}
|
||||
if (categorizedTags[tag] == null) {
|
||||
console.warn(`No "${props.lang}" translation for tag "${tag}"`);
|
||||
return [tagSlug, tag];
|
||||
return { id: tagSlug, name: tag };
|
||||
}
|
||||
return [tagSlug, categorizedTags[tag]!];
|
||||
return { id: tagSlug, name: categorizedTags[tag]! };
|
||||
});
|
||||
const thumbnail =
|
||||
props.thumbnail &&
|
||||
(await getImage({ src: props.thumbnail, width: props.thumbnailWidth, height: props.thumbnailHeight }));
|
||||
const wordCount = props.wordCount ? `${props.wordCount}` : "???";
|
||||
const wordCount = props.wordCount?.toString();
|
||||
---
|
||||
|
||||
<BaseLayout pageTitle={props.title}>
|
||||
|
|
@ -352,10 +352,10 @@ const wordCount = props.wordCount ? `${props.wordCount}` : "???";
|
|||
{t(props.lang, "story/tags")}
|
||||
</h2>
|
||||
<ul class="flex flex-wrap gap-x-2 gap-y-2 px-2">
|
||||
{tags.map(([tagSlug, tagText]) => (
|
||||
{tags.map(({ id, name }) => (
|
||||
<li class="rounded-full bg-bm-300 px-3 py-1 text-sm text-black shadow-sm dark:bg-bm-600 dark:text-white print:bg-none">
|
||||
<a class="hover:underline focus:underline" href={`/tags/${tagSlug}`}>
|
||||
{tagText}
|
||||
<a class="hover:underline focus:underline" href={`/tags/${id}`}>
|
||||
{name}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue