refactor: Post type
This commit is contained in:
parent
5cc122bf39
commit
c647fd62c3
3 changed files with 5 additions and 5 deletions
|
|
@ -2,7 +2,7 @@ import type { CollectionEntry } from 'astro:content';
|
|||
import { DEFAULT_CATEGORY } from './consts';
|
||||
import { sortEntries } from './format';
|
||||
|
||||
type Post = CollectionEntry<'md'>;
|
||||
export type Post = CollectionEntry<'md'> & { body?: string };
|
||||
|
||||
export function getSlug(postId: string): string {
|
||||
const parts = postId.split('/');
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import { getCollection, render } from 'astro:content';
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
import { formatDate, formatListItem, excerpt } from '../lib/format';
|
||||
import { getSlug, resolveRelatedPosts } from '../lib/md';
|
||||
import { getSlug, resolveRelatedPosts, type Post } from '../lib/md';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const allPosts = await getCollection('md');
|
||||
|
|
@ -15,7 +15,7 @@ export async function getStaticPaths() {
|
|||
const { post, allPosts } = Astro.props;
|
||||
const { Content } = await render(post);
|
||||
const related = post.data.related ? resolveRelatedPosts(post.data.related, allPosts) : [];
|
||||
const description = excerpt((post as any).body) || undefined;
|
||||
const description = excerpt((post as Post).body) || undefined;
|
||||
---
|
||||
<Layout title={`${post.data.title} - lewis m.w.`} description={description}>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import rss from '@astrojs/rss';
|
||||
import { getCollection } from 'astro:content';
|
||||
import type { APIContext } from 'astro';
|
||||
import { getSlug } from '../lib/md';
|
||||
import { getSlug, type Post } from '../lib/md';
|
||||
import { getTxtFiles } from '../lib/txt';
|
||||
import { excerpt } from '../lib/format';
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ export async function GET(context: APIContext) {
|
|||
title: post.data.title,
|
||||
pubDate: post.data.date,
|
||||
link: `/${getSlug(post.id)}`,
|
||||
description: excerpt((post as any).body) || post.data.title,
|
||||
description: excerpt((post as Post).body) || post.data.title,
|
||||
})),
|
||||
...txtFiles.map(txt => ({
|
||||
title: txt.name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue