mirror of
https://github.com/Pantonius/pantosite-astro.git
synced 2026-04-26 09:24:38 +00:00
Updated blog post definition
This commit is contained in:
@@ -1,61 +1,69 @@
|
||||
import type { InferEntrySchema, RenderedContent } from "astro:content";
|
||||
|
||||
export type CollectionPost = {
|
||||
id: string;
|
||||
body?: string;
|
||||
collection: "blog" | "projects";
|
||||
data: InferEntrySchema<"blog"> | InferEntrySchema<"projects">;
|
||||
rendered?: RenderedContent;
|
||||
filePath?: string;
|
||||
id: string;
|
||||
body?: string;
|
||||
collection: "blog" | "projects";
|
||||
data: InferEntrySchema<"blog"> | InferEntrySchema<"projects">;
|
||||
rendered?: RenderedContent;
|
||||
filePath?: string;
|
||||
digest?: string;
|
||||
deferredRender?: boolean;
|
||||
};
|
||||
|
||||
export const isCollectionPost = (post: any): post is CollectionPost => {
|
||||
return post.collection === "blog" || post.collection === "projects";
|
||||
return post.collection === "blog" || post.collection === "projects";
|
||||
}
|
||||
|
||||
export type Post = {
|
||||
id: string;
|
||||
title: string;
|
||||
heroImage?: string;
|
||||
pubDate: Date;
|
||||
updatedDate?: Date;
|
||||
description: string;
|
||||
id: string;
|
||||
title: string;
|
||||
heroImage?: string;
|
||||
pubDate: Date;
|
||||
updatedDate?: Date;
|
||||
description: string;
|
||||
|
||||
rendered?: RenderedContent;
|
||||
filePath?: string;
|
||||
body?: string;
|
||||
collection: "blog" | "projects";
|
||||
rendered?: RenderedContent;
|
||||
filePath?: string;
|
||||
body?: string;
|
||||
digest?: string;
|
||||
deferredRender?: boolean;
|
||||
collection: "blog" | "projects";
|
||||
};
|
||||
|
||||
export const convertPost = (post: CollectionPost): Post => {
|
||||
return {
|
||||
id: post.id,
|
||||
title: post.data.title,
|
||||
heroImage: post.data.heroImage,
|
||||
pubDate: new Date(post.data.pubDate),
|
||||
updatedDate: post.data.updatedDate ? new Date(post.data.updatedDate) : undefined,
|
||||
description: post.data.description,
|
||||
return {
|
||||
id: post.id,
|
||||
title: post.data.title,
|
||||
heroImage: post.data.heroImage,
|
||||
pubDate: new Date(post.data.pubDate),
|
||||
updatedDate: post.data.updatedDate ? new Date(post.data.updatedDate) : undefined,
|
||||
description: post.data.description,
|
||||
|
||||
rendered: post.rendered,
|
||||
filePath: post.filePath,
|
||||
body: post.body,
|
||||
collection: post.collection
|
||||
};
|
||||
rendered: post.rendered,
|
||||
filePath: post.filePath,
|
||||
body: post.body,
|
||||
digest: post.digest,
|
||||
deferredRender: post.deferredRender,
|
||||
collection: post.collection
|
||||
};
|
||||
}
|
||||
|
||||
export const convertCollectionPost = (post: Post): CollectionPost => {
|
||||
return {
|
||||
id: post.id,
|
||||
collection: post.collection,
|
||||
data: {
|
||||
title: post.title,
|
||||
heroImage: post.heroImage,
|
||||
pubDate: post.pubDate,
|
||||
updatedDate: post.updatedDate,
|
||||
description: post.description
|
||||
},
|
||||
rendered: post.rendered,
|
||||
filePath: post.filePath,
|
||||
body: post.body
|
||||
};
|
||||
}
|
||||
return {
|
||||
id: post.id,
|
||||
collection: post.collection,
|
||||
data: {
|
||||
title: post.title,
|
||||
heroImage: post.heroImage,
|
||||
pubDate: post.pubDate,
|
||||
updatedDate: post.updatedDate,
|
||||
description: post.description
|
||||
},
|
||||
rendered: post.rendered,
|
||||
filePath: post.filePath,
|
||||
body: post.body,
|
||||
digest: post.digest,
|
||||
deferredRender: post.deferredRender
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
import { type CollectionEntry, getCollection } from 'astro:content';
|
||||
import { getCollection } from 'astro:content';
|
||||
import BlogPost from '../../layouts/BlogPost.astro';
|
||||
import { render } from 'astro:content';
|
||||
import { convertCollectionPost, convertPost, type Post } from '../../models/Post';
|
||||
@@ -11,7 +11,7 @@ export async function getStaticPaths() {
|
||||
props: post,
|
||||
}));
|
||||
}
|
||||
type Props = CollectionEntry<'blog'>;
|
||||
type Props = Post;
|
||||
|
||||
const post: Post = Astro.props;
|
||||
const { Content } = await render(convertCollectionPost(post));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
import { type CollectionEntry, getCollection } from 'astro:content';
|
||||
import { getCollection } from 'astro:content';
|
||||
import BlogPost from '../../layouts/BlogPost.astro';
|
||||
import { render } from 'astro:content';
|
||||
import { convertCollectionPost, convertPost, type Post } from '../../models/Post';
|
||||
@@ -11,7 +11,7 @@ export async function getStaticPaths() {
|
||||
props: post,
|
||||
}));
|
||||
}
|
||||
type Props = CollectionEntry<'projects'>;
|
||||
type Props = Post;
|
||||
|
||||
const post: Post = Astro.props;
|
||||
const { Content } = await render(convertCollectionPost(post));
|
||||
|
||||
Reference in New Issue
Block a user