refactor: rename blog app to www
This commit is contained in:
parent
5ff2a3056e
commit
87c8260c80
40 changed files with 6 additions and 6 deletions
30
apps/www/src/pages/md/[slug].astro
Normal file
30
apps/www/src/pages/md/[slug].astro
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
import { getCollection, render } from 'astro:content';
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection('posts');
|
||||
return posts.map(post => ({
|
||||
params: { slug: post.id },
|
||||
props: { post }
|
||||
}));
|
||||
}
|
||||
|
||||
const { post } = Astro.props;
|
||||
const { Content } = await render(post);
|
||||
|
||||
function formatDate(date: Date): string {
|
||||
const d = String(date.getDate()).padStart(2, '0');
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const y = String(date.getFullYear()).slice(-2);
|
||||
return `${d}/${m}/${y}`;
|
||||
}
|
||||
---
|
||||
<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>
|
||||
<Content />
|
||||
</article>
|
||||
</Layout>
|
||||
46
apps/www/src/pages/md/index.astro
Normal file
46
apps/www/src/pages/md/index.astro
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
|
||||
const posts = await getCollection('posts');
|
||||
|
||||
// Group by category (default: "posts")
|
||||
const grouped = posts.reduce((acc, post) => {
|
||||
const category = post.data.category ?? 'posts';
|
||||
if (!acc[category]) acc[category] = [];
|
||||
acc[category].push(post);
|
||||
return acc;
|
||||
}, {} as Record<string, typeof posts>);
|
||||
|
||||
// Sort categories: "posts" first, then alphabetically
|
||||
const sortedCategories = Object.keys(grouped).sort((a, b) => {
|
||||
if (a === 'posts') return -1;
|
||||
if (b === 'posts') return 1;
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
|
||||
// Sort posts within each category: pinned first, then by date descending
|
||||
for (const category of sortedCategories) {
|
||||
grouped[category].sort((a, b) => {
|
||||
if (a.data.pinned && !b.data.pinned) return -1;
|
||||
if (!a.data.pinned && b.data.pinned) return 1;
|
||||
return b.data.date.getTime() - a.data.date.getTime();
|
||||
});
|
||||
}
|
||||
|
||||
function formatDate(date: Date): string {
|
||||
const d = String(date.getDate()).padStart(2, '0');
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const y = String(date.getFullYear()).slice(-2);
|
||||
return `${d}/${m}/${y}`;
|
||||
}
|
||||
---
|
||||
<Layout title="md - lewis m.w.">
|
||||
|
||||
{sortedCategories.map(category => (
|
||||
<details open>
|
||||
<summary>{category}</summary>
|
||||
<pre set:html={grouped[category].map(post => `<span class="muted">${formatDate(post.data.date)}</span> <a href="/md/${post.id}">${post.data.title}</a>${post.data.pinned ? ' [pinned]' : ''}`).join('\n')} />
|
||||
</details>
|
||||
))}
|
||||
</Layout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue