From 90cac4102b01774f2c1d6b36fa841ec2a503938a Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 11 Dec 2022 00:23:05 +0000 Subject: [PATCH] feat: re-add archive page pagination Refs: #28 --- website/src/pages/archive/[...page].astro | 39 +++++++++++++++++++ website/src/pages/archive/[...slug].astro | 28 ------------- .../archive/[year]/[month]/[day]/[slug].astro | 36 +++++++++++++++++ website/src/pages/archive/index.astro | 28 ------------- 4 files changed, 75 insertions(+), 56 deletions(-) create mode 100644 website/src/pages/archive/[...page].astro delete mode 100644 website/src/pages/archive/[...slug].astro create mode 100644 website/src/pages/archive/[year]/[month]/[day]/[slug].astro delete mode 100644 website/src/pages/archive/index.astro diff --git a/website/src/pages/archive/[...page].astro b/website/src/pages/archive/[...page].astro new file mode 100644 index 00000000..2c916e36 --- /dev/null +++ b/website/src/pages/archive/[...page].astro @@ -0,0 +1,39 @@ +--- +import DailyEmailForm from '../../components/DailyEmailForm.astro' +import Layout from '../../layouts/DailyEmailLayout.astro' + +export async function getStaticPaths({ paginate }) { + const emails = await Astro.glob('../../daily-emails/*.md') + const sortedEmails = emails + .sort((a, b) => + new Date(b.frontmatter.pubDate).valueOf() - + new Date(a.frontmatter.pubDate).valueOf() + ) + + return paginate(sortedEmails, { pageSize: 20 }) +} + +const { page } = Astro.props +--- + + + + + + diff --git a/website/src/pages/archive/[...slug].astro b/website/src/pages/archive/[...slug].astro deleted file mode 100644 index 73bc6b30..00000000 --- a/website/src/pages/archive/[...slug].astro +++ /dev/null @@ -1,28 +0,0 @@ ---- -import DailyEmailForm from '../../components/DailyEmailForm.astro' -import Layout from '../../layouts/DailyEmailLayout.astro' - -export async function getStaticPaths() { - const emails = await Astro.glob('../../daily-emails/*.md') - - return emails.map(email => { - return { - params: { - slug: email.frontmatter.permalink - .replace('archive/', '') - .replace('\n', ''), - }, - props: { - email, - } - } - }) -} - -const { Content } = Astro.props.email -const { title } = Astro.props.email.frontmatter ---- - - - - diff --git a/website/src/pages/archive/[year]/[month]/[day]/[slug].astro b/website/src/pages/archive/[year]/[month]/[day]/[slug].astro new file mode 100644 index 00000000..2f8bb2bc --- /dev/null +++ b/website/src/pages/archive/[year]/[month]/[day]/[slug].astro @@ -0,0 +1,36 @@ +--- +import DailyEmailForm from '../../../../../components/DailyEmailForm.astro' +import Layout from '../../../../../layouts/DailyEmailLayout.astro' + +export async function getStaticPaths() { + const emails = await Astro.glob('../../../../../daily-emails/*.md') + + return emails.map(email => { + const pubDate = email.frontmatter.pubDate.split('T')[0].split('-') + + const slug = email.frontmatter.permalink + .replace('archive/', '') + .replace('\n', '') + .split('/')[3] + + return { + params: { + day: pubDate[2], + month: pubDate[1], + slug, + year: pubDate[0], + }, + props: { + email, + } + } + }) +} + +const { Content } = Astro.props.email +const { title } = Astro.props.email.frontmatter +--- + + + + diff --git a/website/src/pages/archive/index.astro b/website/src/pages/archive/index.astro deleted file mode 100644 index e0041d95..00000000 --- a/website/src/pages/archive/index.astro +++ /dev/null @@ -1,28 +0,0 @@ ---- -import PageLayout from '../../layouts/PageLayout.astro' - -const emails = await Astro.glob('../../daily-emails/*.md'); - -const sortedEmails = emails - .sort((a, b) => - new Date(b.frontmatter.pubDate).valueOf() - - new Date(a.frontmatter.pubDate).valueOf() - ) ---- - - - -