refactor: renamed md to posts, and plaintext to files

This commit is contained in:
Lewis Wynne 2026-03-27 19:11:57 +00:00
parent 20811f107b
commit e4052fc145
7 changed files with 13 additions and 13 deletions

View file

@ -28,4 +28,4 @@ const bookmarks = defineCollection({
})
});
export const collections = { md, bookmarks };
export const collections = { posts, bookmarks };

View file

@ -6,7 +6,7 @@ export const SUBDOMAINS = [
];
export const SECTIONS = {
plaintext: 'plaintext',
files: 'files',
bookmarks: 'bookmarks',
guestbook: 'guestbook',
} as const;

View file

@ -2,7 +2,7 @@ import type { CollectionEntry } from 'astro:content';
import { DEFAULT_CATEGORY } from './consts';
import { sortEntries } from './format';
export type Post = CollectionEntry<'md'> & { body?: string };
export type Post = CollectionEntry<'posts'> & { body?: string };
export function getSlug(postId: string): string {
const parts = postId.split('/');

View file

@ -2,10 +2,10 @@
import { getCollection, render } from 'astro:content';
import Layout from '../layouts/Layout.astro';
import { formatDate, formatListItem, excerpt, wordCount } from '../lib/format';
import { getSlug, resolveRelatedPosts, type Post } from '../lib/md';
import { getSlug, resolveRelatedPosts, type Post } from '../lib/posts';
export async function getStaticPaths() {
const allPosts = await getCollection('md');
const allPosts = await getCollection('posts');
return allPosts.map(post => ({
params: { slug: getSlug(post.id) },
props: { post, allPosts }

View file

@ -1,12 +1,12 @@
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import type { APIContext } from 'astro';
import { getSlug, type Post } from '../lib/md';
import { getSlug, type Post } from '../lib/posts';
import { getTxtFiles } from '../lib/txt';
import { excerpt } from '../lib/format';
export async function GET(context: APIContext) {
const posts = await getCollection('md');
const posts = await getCollection('posts');
const txtFiles = getTxtFiles();
const items = [

View file

@ -3,11 +3,11 @@ import { getCollection } from 'astro:content';
import Layout from '../layouts/Layout.astro';
import { getApprovedEntries, type GuestbookEntry } from '../lib/db';
import { formatDate, formatListItem, extractDomain, wordCount, escapeHtml } from '../lib/format';
import { organizePostsByCategory, getSlug } from '../lib/md';
import { organizePostsByCategory, getSlug } from '../lib/posts';
import { getTxtFiles } from '../lib/txt';
import { DEFAULT_CATEGORY, SECTIONS, SUBDOMAINS } from '../lib/consts';
const posts = await getCollection('md');
const posts = await getCollection('posts');
const { grouped, categories: sortedCategories } = organizePostsByCategory(posts);
const bookmarksCollection = await getCollection('bookmarks');
@ -43,8 +43,8 @@ const urls = [
);
})}
<section data-section={SECTIONS.plaintext}>
<a class="section-label" href={`?just=${SECTIONS.plaintext}`}>{SECTIONS.plaintext}</a>
<section data-section={SECTIONS.files}>
<a class="section-label" href={`?just=${SECTIONS.files}`}>{SECTIONS.files}</a>
<div class="entry-list" set:html={txtFiles.map(f => {
const name = f.name.replace(/\.txt$/, '');
return `<span class="entry">${formatListItem(f.date, `/${f.name}`, name, { suffix: f.description })}</span>`;

View file

@ -1,12 +1,12 @@
import { getCollection } from 'astro:content';
import type { APIContext } from 'astro';
import { getSlug } from '../lib/md';
import { getSlug } from '../lib/posts';
import { getTxtFiles } from '../lib/txt';
import { SUBDOMAINS } from '../lib/consts';
export async function GET(context: APIContext) {
const site = context.site?.origin ?? 'https://wynne.rs';
const posts = await getCollection('md');
const posts = await getCollection('posts');
const txtFiles = getTxtFiles().map(f => f.name);
const urls = [