revert: add pagination to the daily posts archive

This reverts commit 8527e7fb89.
This commit is contained in:
Oliver Davies 2022-12-10 01:02:11 +00:00
parent 7b25c2d9b1
commit 85a07e11ac
3 changed files with 56 additions and 39 deletions

View file

@ -1,39 +0,0 @@
---
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;
---
<Layout title="Daily emails archive">
<ul>
{page.data.map(email => (
<li>
<a href={`/${email.frontmatter.permalink}`}>
{new Date(email.frontmatter.pubDate).toLocaleDateString('en-GB', {
day: 'numeric',
month: 'long',
year: 'numeric',
})} -
{email.frontmatter.title}
</a>
</li>
))}
</ul>
<nav class="mt-12 flex justify-center">
{ page.url.prev ? <a class="px-2" href={ page.url.prev }>&larr; Newer emails</a> : null }
{ page.url.next ? <a class="px-2" href={ page.url.next }>Older emails &rarr;</a> : null }
</nav>
</Layout>

View file

@ -0,0 +1,28 @@
---
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
---
<Layout title={title}>
<Content />
</Layout>

View file

@ -0,0 +1,28 @@
---
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()
)
---
<PageLayout title="Daily emails archive">
<ul>
{sortedEmails.map(email => (
<li>
<a href={`/${email.frontmatter.permalink}`}>
{new Date(email.frontmatter.pubDate).toLocaleDateString('en-GB', {
day: 'numeric',
month: 'long',
year: 'numeric',
})} -
{email.frontmatter.title}
</a>
</li>
))}
</ul>
</PageLayout>