revert: add pagination to the daily posts archive
This reverts commit 8527e7fb89
.
This commit is contained in:
parent
7b25c2d9b1
commit
85a07e11ac
|
@ -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 }>← Newer emails</a> : null }
|
||||
{ page.url.next ? <a class="px-2" href={ page.url.next }>Older emails →</a> : null }
|
||||
</nav>
|
||||
</Layout>
|
28
website/src/pages/archive/[...slug].astro
Normal file
28
website/src/pages/archive/[...slug].astro
Normal 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>
|
28
website/src/pages/archive/index.astro
Normal file
28
website/src/pages/archive/index.astro
Normal 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>
|
Loading…
Reference in a new issue