feat: optional dates, otherwise fetched from git
This commit is contained in:
parent
4d9e3c56da
commit
cc6eff22a8
8 changed files with 90 additions and 31 deletions
|
|
@ -5,27 +5,28 @@ import { getCollection, render } from 'astro:content';
|
|||
import { requireAdminSession } from '../../lib/auth';
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import { formatDate } from '../../lib/format';
|
||||
import { getSlug } from '../../lib/md';
|
||||
import { getSlug, enrichPostWithDates } from '../../lib/md';
|
||||
|
||||
const { session, error } = await requireAdminSession(Astro.request);
|
||||
if (error) return error;
|
||||
if (!session) return Astro.redirect('/api/auth/signin');
|
||||
|
||||
const slug = Astro.params.slug;
|
||||
const posts = await getCollection('md', ({ data }) => data.draft === true);
|
||||
const post = posts.find(p => getSlug(p.id) === slug);
|
||||
const rawPosts = await getCollection('md', ({ data }) => data.draft === true);
|
||||
const rawPost = rawPosts.find(p => getSlug(p.id) === slug);
|
||||
|
||||
if (!post) {
|
||||
if (!rawPost) {
|
||||
return new Response('Not found', { status: 404 });
|
||||
}
|
||||
|
||||
const post = enrichPostWithDates(rawPost);
|
||||
const { Content } = await render(post);
|
||||
---
|
||||
<Layout title={`${post.data.title} - lewis m.w.`}>
|
||||
|
||||
<article>
|
||||
<h1>{post.data.title}</h1>
|
||||
<p class="muted" style="margin-top: 0;">{formatDate(post.data.date)}</p>
|
||||
<p class="muted" style="margin-top: 0;">{formatDate(post.dates.created)}{post.dates.updated && ` (updated ${formatDate(post.dates.updated)})`}</p>
|
||||
<Content />
|
||||
</article>
|
||||
</Layout>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
import rss from '@astrojs/rss';
|
||||
import { getCollection } from 'astro:content';
|
||||
import type { APIContext } from 'astro';
|
||||
import { getSlug } from '../lib/md';
|
||||
import { getSlug, enrichPostsWithDates } from '../lib/md';
|
||||
import { getTxtFiles } from '../lib/txt';
|
||||
|
||||
export async function GET(context: APIContext) {
|
||||
const posts = await getCollection('md', ({ data }) => data.draft !== true);
|
||||
const rawPosts = await getCollection('md', ({ data }) => data.draft !== true);
|
||||
const posts = enrichPostsWithDates(rawPosts);
|
||||
const bookmarks = await getCollection('bookmarks');
|
||||
const txtFiles = getTxtFiles();
|
||||
|
||||
const items = [
|
||||
...posts.map(post => ({
|
||||
title: post.data.title,
|
||||
pubDate: post.data.date,
|
||||
pubDate: post.dates.created,
|
||||
link: `/md/${getSlug(post.id)}`,
|
||||
description: post.data.title,
|
||||
})),
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
import { getCollection, render } from 'astro:content';
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import { formatDate } from '../../lib/format';
|
||||
import { getSlug } from '../../lib/md';
|
||||
import { getSlug, enrichPostWithDates } from '../../lib/md';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection('md', ({ data }) => data.draft !== true);
|
||||
return posts.map(post => ({
|
||||
params: { slug: getSlug(post.id) },
|
||||
props: { post }
|
||||
props: { post: enrichPostWithDates(post) }
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ const { Content } = await render(post);
|
|||
|
||||
<article>
|
||||
<h1>{post.data.title}</h1>
|
||||
<p class="muted" style="margin-top: 0;">{formatDate(post.data.date)}</p>
|
||||
<p class="muted" style="margin-top: 0;">{formatDate(post.dates.created)}{post.dates.updated && ` (updated ${formatDate(post.dates.updated)})`}</p>
|
||||
<Content />
|
||||
</article>
|
||||
</Layout>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@
|
|||
import { getCollection } from 'astro:content';
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import { formatListItem } from '../../lib/format';
|
||||
import { organizePostsByCategory, getSlug } from '../../lib/md';
|
||||
import { organizePostsByCategory, getSlug, enrichPostsWithDates } from '../../lib/md';
|
||||
|
||||
const posts = await getCollection('md', ({ data }) => data.draft !== true);
|
||||
const rawPosts = await getCollection('md', ({ data }) => data.draft !== true);
|
||||
const posts = enrichPostsWithDates(rawPosts);
|
||||
const { grouped, categories: sortedCategories } = organizePostsByCategory(posts);
|
||||
---
|
||||
<Layout title="md - lewis m.w.">
|
||||
|
|
@ -12,7 +13,7 @@ const { grouped, categories: sortedCategories } = organizePostsByCategory(posts)
|
|||
{sortedCategories.map(category => (
|
||||
<details open>
|
||||
<summary>{category}</summary>
|
||||
<pre set:html={grouped[category].map(post => formatListItem(post.data.date, `/md/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })).join('\n')} />
|
||||
<pre set:html={grouped[category].map(post => formatListItem(post.dates.created, `/md/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })).join('\n')} />
|
||||
</details>
|
||||
))}
|
||||
</Layout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue