Added website config fetched from payload

This commit is contained in:
DrMint 2024-04-05 17:56:37 +02:00
parent 7f7fc4c309
commit 09580f828b
9 changed files with 652 additions and 610 deletions

View File

@ -3,10 +3,7 @@
## Short term
- [Timeline] inline links to pages not working (timeline 2026/06)
- [Timeline] 11940-11 says december on the website.
- [Home] Have the event count reflect the actual number
- Save cookies for longer than just the session
- [Payload] Stop sending Rich text content if it is empty
## Mid term
@ -22,7 +19,7 @@
## Long term
- [Timeline] Some filtering options (by source/languages/)
- [Timeline] Some filtering options (by source/languages)
- The Chronicles
- The Changelog
- Grid view (all files)

View File

@ -1,37 +0,0 @@
import type { WordingKey } from "src/i18n/wordings-keys";
const timelineEras: { name: WordingKey; start: number; end: number }[] = [
{ name: "timeline.eras.cataclysm", start: 856, end: 856 },
{
name: "timeline.eras.drakengard3",
start: 997,
end: 1001,
},
{
name: "timeline.eras.drakengard",
start: 1003,
end: 1099,
},
{
name: "timeline.eras.drakengard2",
start: 1100,
end: 1117,
},
{
name: "timeline.eras.nier",
start: 2003,
end: 5012,
},
{
name: "timeline.eras.nierAutomata",
start: 5012,
end: 12543,
},
];
export const dataConfig = {
timeline: {
yearsWithABreakBefore: [856, 997, 1003, 1118, 1957, 2003, 2049, 2050, 3361, 3463],
eras: timelineEras,
},
};

View File

@ -1,16 +1,15 @@
---
import { payload } from "src/shared/payload/payload-sdk";
import CategoryCard from "./CategoryCard.astro";
import { getI18n } from "src/i18n/i18n";
import { cache } from "src/utils/cachedPayload";
const folders = await payload.getHomeFolders();
const { getLocalizedUrl, getLocalizedMatch } = await getI18n(Astro.locals.currentLocale);
---
{/* ------------------------------------------- HTML ------------------------------------------- */}
{
folders.map(({ slug, translations, darkThumbnail, lightThumbnail }) => (
cache.config.homeFolders.map(({ slug, translations, darkThumbnail, lightThumbnail }) => (
<CategoryCard
img={
darkThumbnail && lightThumbnail

View File

@ -1,6 +1,11 @@
---
import { Collections } from "src/shared/payload/payload-sdk";
import { refreshCurrencies, refreshLocales, refreshWordings } from "src/utils/cachedPayload";
import {
refreshCurrencies,
refreshLocales,
refreshWordings,
refreshWebsiteConfig,
} from "src/utils/cachedPayload";
const auth = Astro.request.headers.get("Authorization");
@ -23,6 +28,10 @@ switch (collectionSlug) {
await refreshLocales();
break;
case Collections.WebsiteConfig:
await refreshWebsiteConfig();
break;
default:
return new Response(null, { status: 400, statusText: "Bad Request" });
}

View File

@ -6,7 +6,7 @@ import LibraryGrid from "./_components/LibraryGrid.astro";
import ChronicleCard from "./_components/ChronicleCard.astro";
import LinkCard from "./_components/LinkCard.astro";
import { getI18n } from "src/i18n/i18n";
import { dataConfig } from "src/dataConfig";
import { cache } from "src/utils/cachedPayload";
const { t, getLocalizedUrl } = await getI18n(Astro.locals.currentLocale);
---
@ -132,8 +132,8 @@ const { t, getLocalizedUrl } = await getI18n(Astro.locals.currentLocale);
icon="material-symbols:calendar-month-outline"
title={t("footer.links.timeline.title")}
subtitle={t("footer.links.timeline.subtitle", {
eraCount: dataConfig.timeline.eras.length,
eventCount: 358,
eraCount: cache.config.timeline.eras.length,
eventCount: cache.config.timeline.eventCount,
})}
href={getLocalizedUrl("/timeline")}
/>

View File

@ -2,7 +2,7 @@
import type { EndpointChronologyEvent } from "src/shared/payload/payload-sdk";
import TimelineEvent from "./TimelineEvent.astro";
import { getI18n } from "src/i18n/i18n";
import { dataConfig } from "src/dataConfig";
import { cache } from "src/utils/cachedPayload";
interface Props {
year: number;
@ -15,7 +15,7 @@ const { formatTimelineDate } = await getI18n(Astro.locals.currentLocale);
{/* ------------------------------------------- HTML ------------------------------------------- */}
{dataConfig.timeline.yearsWithABreakBefore.includes(year) && <hr id={`hr-${year}`} />}
{cache.config.timeline.breaks.includes(year) && <hr id={`hr-${year}`} />}
<h2 id={year.toString()}>
{formatTimelineDate(events.length === 1 ? events[0]!.date : { year })}

View File

@ -7,7 +7,8 @@ import AppLayoutTitle from "components/AppLayout/components/AppLayoutTitle.astro
import Card from "components/Card.astro";
import { getI18n } from "src/i18n/i18n";
import AppLayoutBackgroundImg from "components/AppLayout/components/AppLayoutBackgroundImg.astro";
import { dataConfig } from "src/dataConfig";
import { cache } from "src/utils/cachedPayload";
import type { WordingKey } from "src/i18n/wordings-keys";
const events = await payload.getChronologyEvents();
const groupedEvents = groupBy(events, (event) => event.date.year);
@ -68,11 +69,11 @@ const { getLocalizedUrl, t, formatTimelineDate } = await getI18n(Astro.locals.cu
<h3>{t("timeline.jumpTo")}</h3>
{
dataConfig.timeline.eras.map(({ name, start, end }) => (
cache.config.timeline.eras.map(({ name, startingYear, endingYear }) => (
<p
set:html={t(name, {
start: `<a href="#${start}">${formatTimelineDate({ year: start })}</a>`,
end: `<a href="#${end}">${formatTimelineDate({ year: end })}</a>`,
set:html={t(name as WordingKey, {
start: `<a href="#${startingYear}">${formatTimelineDate({ year: startingYear })}</a>`,
end: `<a href="#${endingYear}">${formatTimelineDate({ year: endingYear })}</a>`,
})}
/>
))

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,22 @@
import { payload, type Language, type EndpointWording } from "src/shared/payload/payload-sdk";
import {
payload,
type Language,
type EndpointWording,
type EndpointWebsiteConfig,
} from "src/shared/payload/payload-sdk";
type Cache = {
locales: Language[];
currencies: string[];
wordings: EndpointWording[];
config: EndpointWebsiteConfig;
};
const fetchNewData = async (): Promise<Cache> => ({
locales: await payload.getLanguages(),
currencies: (await payload.getCurrencies()).map(({ id }) => id),
wordings: await payload.getWordings(),
config: await payload.getConfig(),
});
export let cache = await fetchNewData();
@ -25,3 +32,7 @@ export const refreshCurrencies = async () => {
export const refreshLocales = async () => {
cache.locales = await payload.getLanguages();
};
export const refreshWebsiteConfig = async () => {
cache.config = await payload.getConfig();
};