From 53f29bac911b13b2bef0125de22773bf26ce5a90 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 15 Aug 2023 19:15:27 +0100 Subject: Adds homepage --- src/data/contactDetails.ts | 8 +++ src/i18n/translations/pages/home.ts | 110 ++++++++++++++++++++++++++++++++++++ src/i18n/translations/site.ts | 4 ++ src/lib/newsUtils.ts | 35 ++++++++++++ src/pages/[locale]/index.astro | 95 +++++++++++++++++-------------- src/pages/[locale]/news/index.astro | 9 +-- 6 files changed, 213 insertions(+), 48 deletions(-) create mode 100644 src/data/contactDetails.ts create mode 100644 src/lib/newsUtils.ts (limited to 'src') diff --git a/src/data/contactDetails.ts b/src/data/contactDetails.ts new file mode 100644 index 0000000..f5de6f5 --- /dev/null +++ b/src/data/contactDetails.ts @@ -0,0 +1,8 @@ +export default { + membershipSecretary: { + emailAddress: 'lallans@hotmail.co.uk', + }, + generalEnquiries: { + emailAddress: 'lallans@hotmail.co.uk', + }, +}; diff --git a/src/i18n/translations/pages/home.ts b/src/i18n/translations/pages/home.ts index 635b33a..302d643 100644 --- a/src/i18n/translations/pages/home.ts +++ b/src/i18n/translations/pages/home.ts @@ -5,6 +5,116 @@ const tPage = { sco: () => 'Hame', 'en-GB': () => 'Home', }, + news: { + sco: () => 'Recent News', + 'en-GB': () => 'Recent News', + }, + 'aw-news': { + sco: () => 'Aw news', + 'en-GB': () => 'All news', + }, + furthsettins: { + sco: () => 'Furthsettins', + 'en-GB': () => 'Publications', + }, + 'furthsettins-para': { + sco: () => ` + We ar ane o the foremaist furthsetters o new Scots leitratur. + Oor maist important furthsettins ar + Lallans an + Scotsoun. + `, + 'en-GB': () => ` + We are one of the leading publishers of new Scots literature. + Our most important publications are + Lallans and + Scotsoun. + `, + }, + 'aw-furthsettins': { + sco: () => 'Aw furthsettins', + 'en-GB': () => 'All publications', + }, + jyne: { + sco: () => 'Jyne', + 'en-GB': () => 'Join', + }, + 'why-jyne': { + sco: () => 'Why jyne the Scots Leid Associe?', + 'en-GB': () => 'Why join the Scots Language Society?', + }, + 'why-jyne-para-1': { + sco: () => ` + Bi jynin us, ye ar helpin us tae heize up the Scots leid, maistly bi giein + Scots scrievers a place tae lairn frae anither an finnd their ain Scots vyce. + `, + 'en-GB': () => ` + By joining us, you are helping us to champion the Scots language, + especially by giving Scots writers a place to learn from one + another and to find their own Scots voice. + `, + }, + 'why-jyne-para-2': { + sco: () => ` + Forby, memmers get biannual issues o our aesome Lallans magazine gratis, + an hae the richt tae atten our Annual Collogues, whaur we haud our AGM an + enjoy talks frae kenspeckle spikkers on thochtie maiters effeirin til Scots + leid an leiteratur. + `, + 'en-GB': () => ` + In addition, members get biannual issues of our unique Lallans + magazine gratis, and have the right to attend our Annual Conferences, where + we hold our AGM and enjoy talks from highly regarded speakers on + thought-provoking subjects relating to Scots language and literature. + `, + }, + 'why-jyne-para-3': { + sco: () => ` + Gin whit ye ar seekin is a community o prose-scrievers, makars, pleywreichts + an owersetters, aw wi muckle care fur the Scots leid, the ar nae peer wi hus, + the auldest Scots-leid activist organisation that’s about eenou an the anely + fully dedicatit til the forderance o new Scots leiteratur. + `, + 'en-GB': () => ` + If what you’re looking for is a community of prose-writers, poets, + playwrights and translators with a passion for the Scots language, we have + no equal. We are the oldest extant Scots-language activist organisation and + the only one solely dedicated to the development of new Scots literature. + `, + }, + 'hou-jyne': { + sco: () => 'Hou can A jyne?', + 'en-GB': () => 'How can I join?', + }, + 'hou-jyne-para-1': { + sco: () => ` + Fur individuals, memmership costs £20 per annum. Fur aw ithers, the stent is £25 per annum. + `, + 'en-GB': () => ` + For individuals, membership costs £20 per annum. For all others, the fee is £25 per annum. + `, + }, + 'hou-jyne-para-2': { + sco: ({ membershipEmail }: { membershipEmail: string }) => ` + Fur tae become a memmer, simply get in titch wi us at + ${membershipEmail} + an we’ll provide ye wi our bank details; or ye can jyne bi sendin us a cheque + made peyable til The Scots Language Society. See + Contact us + fur our address. + `, + 'en-GB': ({ membershipEmail }: { membershipEmail: string }) => ` + To become a member, simply get in touch with us at + ${membershipEmail} + and we’ll provide you with our bank details; or you can join by sending us + a cheque made payable to The Scots Language Society. See + Contact us for our address. + `, + }, + contact: { + sco: () => 'Contact us', + 'en-GB': () => 'Contact us', + }, }; type Raw = typeof tPage; diff --git a/src/i18n/translations/site.ts b/src/i18n/translations/site.ts index 5c18786..95b7f8e 100644 --- a/src/i18n/translations/site.ts +++ b/src/i18n/translations/site.ts @@ -29,6 +29,10 @@ const tSite = { sco: () => 'bi', 'en-GB': () => 'by', }, + and: { + sco: () => 'an', + 'en-GB': () => 'and', + }, locale: { sco: ({ locale }: { locale: Locale }) => { switch (locale) { diff --git a/src/lib/newsUtils.ts b/src/lib/newsUtils.ts new file mode 100644 index 0000000..ededb52 --- /dev/null +++ b/src/lib/newsUtils.ts @@ -0,0 +1,35 @@ +import type Locale from '$types/Locale'; +import { CollectionEntry, getCollection } from 'astro:content'; + +export async function getMostRecentNewsItem(locale: Locale) { + const allNews = await getCollection('news'); + const allNewsInLocale = allNews.filter((item) => isNewsItemInLocale(item, locale)); + const someNewsItem = allNewsInLocale.at(0); + if (!someNewsItem) { + return null; + } + return allNewsInLocale.reduce((prev, curr) => (isBefore(curr, prev) ? curr : prev), someNewsItem); +} + +export function isNewsItemInLocale(newsItem: CollectionEntry<'news'>, locale: Locale) { + const srcPath = newsItem.id; + const newsItemLocale = srcPath.slice(0, srcPath.indexOf('/')); + return newsItemLocale === locale; +} + +function isBefore(item1: CollectionEntry<'news'>, item2: CollectionEntry<'news'>) { + const date1 = dateOf(item1); + const date2 = dateOf(item2); + if (!date2) { + return false; + } + if (!date1) { + return true; + } + return date1.valueOf() < date2.valueOf(); +} + +function dateOf(newsItem: CollectionEntry<'news'>) { + const match = newsItem.id.match(/(?<=(en-GB|sco))\/(\d\d\d\d-\d\d-\d\d)/)?.[2]; + return match ? new Date(match) : null; +} diff --git a/src/pages/[locale]/index.astro b/src/pages/[locale]/index.astro index c32ddf6..3674b9f 100644 --- a/src/pages/[locale]/index.astro +++ b/src/pages/[locale]/index.astro @@ -2,9 +2,11 @@ import Page from '$layouts/Page.astro'; import localeStaticPaths from '$lib/localeStaticPaths'; import translate from '$i18n/translate'; -import site from '$i18n/translations/site'; -import home from '$i18n/translations/pages/home'; +import tPage from '$i18n/translations/pages/home'; import type Locale from '$types/Locale'; +import { getMostRecentNewsItem } from '$lib/newsUtils'; +import NewsPreviewLink from '$components/NewsPreviewLink.astro'; +import contactDetails from '$data/contactDetails'; export async function getStaticPaths() { return localeStaticPaths; @@ -12,49 +14,60 @@ export async function getStaticPaths() { const locale = Astro.params.locale as Locale; const t = translate(locale); +const mostRecentNewsItem = await getMostRecentNewsItem(locale); --- - +
-

{t(site, { key: 'title' })}

-

Tap-level heidin

-

Seicont-level heidin

-

Third-level heidin

-

Fowert-level heidin

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut - labore et dolore magna aliqua. -

- Lairn mair! -

- Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea - commodo consequat. -

- -

- Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla - pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt - mollit anim id est laborum. -

+

+ {mostRecentNewsItem && } +

+ +
+

+

+

+

+
-

Seicont-level heidin

-

Third-level heidin

-

Fowert-level heidin

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut - labore et dolore magna aliqua. -

- Lairn mair! -

- Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea - commodo consequat. -

- -

- Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla - pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt - mollit anim id est laborum. -

+

+ +

+

+

+

+ +

+

+

+

+ +
+

+ + {contactDetails.generalEnquiries.emailAddress} + +
+ Scots Language Society
+ c/o 61 Cliffburn Road
+ Arbroath
+ Angus
+ DD11 5BA
+ United Kingdom
+

diff --git a/src/pages/[locale]/news/index.astro b/src/pages/[locale]/news/index.astro index 0c81fd9..c64fbdb 100644 --- a/src/pages/[locale]/news/index.astro +++ b/src/pages/[locale]/news/index.astro @@ -6,18 +6,13 @@ import getLocaleFromPath from '$lib/getLocaleFromPath'; import localeStaticPaths from '$lib/localeStaticPaths'; import { getCollection } from 'astro:content'; import NewsPreviewLink from '$components/NewsPreviewLink.astro'; +import { isNewsItemInLocale } from '$lib/newsUtils'; const allNews = await getCollection('news'); const locale = getLocaleFromPath(Astro.url.pathname); -const allNewsInLocale = allNews.filter(isInLocale); +const allNewsInLocale = allNews.filter((item) => isNewsItemInLocale(item, locale)); const t = translate(locale); -function isInLocale(newsItem: (typeof allNews)[number]) { - const srcPath = newsItem.id; - const newsItemLocale = srcPath.slice(0, srcPath.indexOf('/')); - return newsItemLocale === locale; -} - export async function getStaticPaths() { return localeStaticPaths; } -- cgit v1.2.3