refactor: renamed md to posts, and plaintext to files
This commit is contained in:
parent
20811f107b
commit
e4052fc145
7 changed files with 13 additions and 13 deletions
|
|
@ -28,4 +28,4 @@ const bookmarks = defineCollection({
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
export const collections = { md, bookmarks };
|
export const collections = { posts, bookmarks };
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ export const SUBDOMAINS = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export const SECTIONS = {
|
export const SECTIONS = {
|
||||||
plaintext: 'plaintext',
|
files: 'files',
|
||||||
bookmarks: 'bookmarks',
|
bookmarks: 'bookmarks',
|
||||||
guestbook: 'guestbook',
|
guestbook: 'guestbook',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import type { CollectionEntry } from 'astro:content';
|
||||||
import { DEFAULT_CATEGORY } from './consts';
|
import { DEFAULT_CATEGORY } from './consts';
|
||||||
import { sortEntries } from './format';
|
import { sortEntries } from './format';
|
||||||
|
|
||||||
export type Post = CollectionEntry<'md'> & { body?: string };
|
export type Post = CollectionEntry<'posts'> & { body?: string };
|
||||||
|
|
||||||
export function getSlug(postId: string): string {
|
export function getSlug(postId: string): string {
|
||||||
const parts = postId.split('/');
|
const parts = postId.split('/');
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
import { getCollection, render } from 'astro:content';
|
import { getCollection, render } from 'astro:content';
|
||||||
import Layout from '../layouts/Layout.astro';
|
import Layout from '../layouts/Layout.astro';
|
||||||
import { formatDate, formatListItem, excerpt, wordCount } from '../lib/format';
|
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() {
|
export async function getStaticPaths() {
|
||||||
const allPosts = await getCollection('md');
|
const allPosts = await getCollection('posts');
|
||||||
return allPosts.map(post => ({
|
return allPosts.map(post => ({
|
||||||
params: { slug: getSlug(post.id) },
|
params: { slug: getSlug(post.id) },
|
||||||
props: { post, allPosts }
|
props: { post, allPosts }
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import rss from '@astrojs/rss';
|
import rss from '@astrojs/rss';
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
import type { APIContext } from 'astro';
|
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 { getTxtFiles } from '../lib/txt';
|
||||||
import { excerpt } from '../lib/format';
|
import { excerpt } from '../lib/format';
|
||||||
|
|
||||||
export async function GET(context: APIContext) {
|
export async function GET(context: APIContext) {
|
||||||
const posts = await getCollection('md');
|
const posts = await getCollection('posts');
|
||||||
const txtFiles = getTxtFiles();
|
const txtFiles = getTxtFiles();
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@ import { getCollection } from 'astro:content';
|
||||||
import Layout from '../layouts/Layout.astro';
|
import Layout from '../layouts/Layout.astro';
|
||||||
import { getApprovedEntries, type GuestbookEntry } from '../lib/db';
|
import { getApprovedEntries, type GuestbookEntry } from '../lib/db';
|
||||||
import { formatDate, formatListItem, extractDomain, wordCount, escapeHtml } from '../lib/format';
|
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 { getTxtFiles } from '../lib/txt';
|
||||||
import { DEFAULT_CATEGORY, SECTIONS, SUBDOMAINS } from '../lib/consts';
|
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 { grouped, categories: sortedCategories } = organizePostsByCategory(posts);
|
||||||
|
|
||||||
const bookmarksCollection = await getCollection('bookmarks');
|
const bookmarksCollection = await getCollection('bookmarks');
|
||||||
|
|
@ -43,8 +43,8 @@ const urls = [
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<section data-section={SECTIONS.plaintext}>
|
<section data-section={SECTIONS.files}>
|
||||||
<a class="section-label" href={`?just=${SECTIONS.plaintext}`}>{SECTIONS.plaintext}</a>
|
<a class="section-label" href={`?just=${SECTIONS.files}`}>{SECTIONS.files}</a>
|
||||||
<div class="entry-list" set:html={txtFiles.map(f => {
|
<div class="entry-list" set:html={txtFiles.map(f => {
|
||||||
const name = f.name.replace(/\.txt$/, '');
|
const name = f.name.replace(/\.txt$/, '');
|
||||||
return `<span class="entry">${formatListItem(f.date, `/${f.name}`, name, { suffix: f.description })}</span>`;
|
return `<span class="entry">${formatListItem(f.date, `/${f.name}`, name, { suffix: f.description })}</span>`;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
import type { APIContext } from 'astro';
|
import type { APIContext } from 'astro';
|
||||||
import { getSlug } from '../lib/md';
|
import { getSlug } from '../lib/posts';
|
||||||
import { getTxtFiles } from '../lib/txt';
|
import { getTxtFiles } from '../lib/txt';
|
||||||
import { SUBDOMAINS } from '../lib/consts';
|
import { SUBDOMAINS } from '../lib/consts';
|
||||||
|
|
||||||
export async function GET(context: APIContext) {
|
export async function GET(context: APIContext) {
|
||||||
const site = context.site?.origin ?? 'https://wynne.rs';
|
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 txtFiles = getTxtFiles().map(f => f.name);
|
||||||
|
|
||||||
const urls = [
|
const urls = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue