diff --git a/src/components/Program.astro b/src/components/Program.astro index 8f13b08..3d766da 100644 --- a/src/components/Program.astro +++ b/src/components/Program.astro @@ -1,16 +1,10 @@ --- import { translations, type Lang } from '@data/i18n'; +import ProgramCard from './ProgramCard.astro'; + const { lang = 'no', data } = Astro.props as { lang?: Lang, data: any }; const t = translations[lang].program; -type ProgramItem = { - time: string; - event: string; - price?: string | null; - cost?: string | null; - url?: string; -}; - const convertDate = (date: string | Date) => { let d = date; if (!(d instanceof Date)) { @@ -30,27 +24,8 @@ const convertDate = (date: string | Date) => {

{convertDate(new Date())}

- {Object.entries(data).map(([date, items]) => ( -
-

{convertDate(date)}

- -
+ {Object.entries(data).map(([date, items], idx) => ( + ))}
@@ -59,9 +34,5 @@ const convertDate = (date: string | Date) => {

) : ( -
No program data available.
+
{t.noProgram}
)} - - \ No newline at end of file diff --git a/src/components/ProgramCard.astro b/src/components/ProgramCard.astro new file mode 100644 index 0000000..8dfc8c8 --- /dev/null +++ b/src/components/ProgramCard.astro @@ -0,0 +1,46 @@ +--- +import { translations, type Lang } from '@data/i18n'; +const { date, items, lang = 'no', even = false } = Astro.props as { date: string | Date, items: ProgramItem[], lang?: Lang, even?: boolean }; +const t = translations[lang].program; + +type ProgramItem = { + time: string; + event: string; + price?: string | null; + cost?: string | null; + url?: string; +}; + +const convertDate = (date: string | Date) => { + let d = date; + if (!(d instanceof Date)) { + d = new Date(d); + } + return d.toLocaleDateString(lang === 'en' ? 'en-GB' : 'nb-NO', { + weekday: 'long', + month: 'long', + day: 'numeric' + }); +}; +--- + +
+

{convertDate(date)}

+ +
\ No newline at end of file diff --git a/src/components/TodayProgram.astro b/src/components/TodayProgram.astro new file mode 100644 index 0000000..bc5d03b --- /dev/null +++ b/src/components/TodayProgram.astro @@ -0,0 +1,22 @@ +--- +import ProgramCard from './ProgramCard.astro'; +import programData from '@data/program.json'; +import { translations, type Lang } from '@data/i18n'; + +const { lang = 'no' } = Astro.props as { lang?: Lang }; +const t = translations[lang].program; + +const typedProgramData = programData as Record; + +const todayStr = new Date().toISOString().slice(0, 10); +const items = typedProgramData[todayStr]; +--- + +
+

{t.today}

+ {items ? ( + + ) : ( +

{t.noProgram}

+ )} +
\ No newline at end of file diff --git a/src/data/i18n.ts b/src/data/i18n.ts index eb7b647..74d96a4 100644 --- a/src/data/i18n.ts +++ b/src/data/i18n.ts @@ -36,6 +36,7 @@ export const translations = { program: { today: "Hva skjer i dag?", programMore: "For arrangementer etter Studio trykk her", + noProgram: "Ingenting på programmet i dag :(", }, vors: { text: "Sett på låta for litt stemning før dere kommer 🔥", @@ -83,6 +84,7 @@ export const translations = { program: { today: "What's happening today?", programMore: "For events after Studio click here", + noProgram: "No events today :(", }, vors: { text: "Play the song to get in the mood before you arrive 🔥", diff --git a/src/pages/en/index.astro b/src/pages/en/index.astro index eb248d3..57bd4bb 100644 --- a/src/pages/en/index.astro +++ b/src/pages/en/index.astro @@ -1,16 +1,16 @@ --- import Layout from '@layouts/Layout.astro'; -import Program from '@components/Program.astro'; import Links from '@components/Links.astro'; import FAQ from '@components/FAQ.astro'; import Hero from '@components/Hero.astro'; +import TodayProgram from '@components/TodayProgram.astro'; import Vors from '@components/Vors.astro'; --- - + \ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index 7eb3e6c..7eaa880 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,16 +1,16 @@ --- import Layout from '@layouts/Layout.astro'; -import Program from '@components/Program.astro'; import Links from '@components/Links.astro'; import FAQ from '@components/FAQ.astro'; import Hero from '@components/Hero.astro'; +import TodayProgram from '@components/TodayProgram.astro'; import Vors from '@components/Vors.astro'; --- - +