diff --git a/src/components/Post.astro b/src/components/Post.astro
index 0622507..8bdf141 100644
--- a/src/components/Post.astro
+++ b/src/components/Post.astro
@@ -36,7 +36,7 @@ const url = !post.data.original
{t("posted_at")}
-
+
{
post.data.categories &&
post.data.categories.map((category) => (
diff --git a/src/content/config.ts b/src/content/config.ts
index beb1f90..326448e 100644
--- a/src/content/config.ts
+++ b/src/content/config.ts
@@ -6,7 +6,7 @@ const posts = defineCollection({
z.object({
title: z.string(),
description: z.string().optional(),
- pubDate: z.coerce.date(),
+ date: z.coerce.date(),
customData: z.string().optional(),
banner: image()
.refine((img) => Math.max(img.width, img.height) <= 4096, {
diff --git a/src/content/posts b/src/content/posts
index ab894f0..409074c 160000
--- a/src/content/posts
+++ b/src/content/posts
@@ -1 +1 @@
-Subproject commit ab894f0e24457b29a3ecc33c0067cc6f109a9085
+Subproject commit 409074cbfbe2f8fe2ac79de92994aaa63b80ec43
diff --git a/src/pages/archive.astro b/src/pages/archive.astro
index ba1001f..196b233 100644
--- a/src/pages/archive.astro
+++ b/src/pages/archive.astro
@@ -1,21 +1,20 @@
---
-import LayoutDefault from '~/layouts/LayoutDefault.astro'
-import ListSection from '~/components/ListSection.astro'
-import ListItem from '~/components/ListItem.astro'
-import { getPosts, formatDate } from '~/utils'
+import LayoutDefault from "~/layouts/LayoutDefault.astro";
+import ListSection from "~/components/ListSection.astro";
+import ListItem from "~/components/ListItem.astro";
+import { getPosts, formatDate } from "~/utils";
-const posts = await getPosts()
+const posts = await getPosts();
-const postByYear = new Map()
+const postByYear = new Map();
posts.forEach((post: Post) => {
- const pubDate = post.data.pubDate ?? new Date()
- const year = pubDate.getFullYear()
+ const pubDate = post.data.date ?? new Date();
+ const year = pubDate.getFullYear();
if (!postByYear.has(year)) {
- postByYear.set(year, [])
+ postByYear.set(year, []);
}
- postByYear.get(year)!.push(post)
-})
-
+ postByYear.get(year)!.push(post);
+});
---
@@ -24,7 +23,11 @@ posts.forEach((post: Post) => {
Array.from(postByYear.entries()).map(([year, posts]) => (
{posts.map((post) => (
-
+
))}
))
diff --git a/src/pages/atom.xml.ts b/src/pages/atom.xml.ts
index fa03699..517be91 100644
--- a/src/pages/atom.xml.ts
+++ b/src/pages/atom.xml.ts
@@ -1,18 +1,17 @@
-import rss from '@astrojs/rss';
-import { getPosts } from '~/utils';
+import rss from "@astrojs/rss";
+import { getPosts } from "~/utils";
import { THEME_CONFIG } from "~/theme.config";
-import type { APIContext } from 'astro';
-import sanitizeHtml from 'sanitize-html';
-import MarkdownIt from 'markdown-it';
+import type { APIContext } from "astro";
+import sanitizeHtml from "sanitize-html";
+import MarkdownIt from "markdown-it";
const parser = new MarkdownIt();
-const { title, desc, website, author } = THEME_CONFIG
-
+const { title, desc, website, author } = THEME_CONFIG;
export async function GET(_context: APIContext) {
- const posts = await getPosts()
- const allowedTags = sanitizeHtml.defaults.allowedTags.concat(['img'])
+ const posts = await getPosts();
+ const allowedTags = sanitizeHtml.defaults.allowedTags.concat(["img"]);
return rss({
title: title,
description: desc,
@@ -21,17 +20,17 @@ export async function GET(_context: APIContext) {
return {
link: `/posts/${post.slug}/`,
author: author,
- content: sanitizeHtml(parser.render(post.body), { allowedTags, }),
+ content: sanitizeHtml(parser.render(post.body), { allowedTags }),
title: post.data.title,
- pubDate: post.data.pubDate,
+ pubDate: post.data.date,
description: post.data.description,
customData: post.data.customData,
categories: post.data.categories,
commentsUrl: post.data.commentsUrl,
source: post.data.source,
enclosure: post.data.enclosure,
- }
+ };
}),
- stylesheet: '/pretty-feed-v3.xsl',
+ stylesheet: "/pretty-feed-v3.xsl",
});
}
diff --git a/src/pages/categories/[...category].astro b/src/pages/categories/[...category].astro
index 3974eb9..8bb3b75 100644
--- a/src/pages/categories/[...category].astro
+++ b/src/pages/categories/[...category].astro
@@ -27,7 +27,7 @@ const { name } = Astro.params;
))
}
diff --git a/src/utils/index.ts b/src/utils/index.ts
index b6a1f69..ac6b6d8 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -1,57 +1,60 @@
-import { getCollection } from 'astro:content'
-import sanitizeHtml from 'sanitize-html'
-import MarkdownIt from 'markdown-it'
+import { getCollection } from "astro:content";
+import sanitizeHtml from "sanitize-html";
+import MarkdownIt from "markdown-it";
export async function getCategories() {
- const posts = await getPosts()
+ const posts = await getPosts();
- const categories = new Map()
+ const categories = new Map();
posts.forEach((post) => {
if (post.data.categories) {
post.data.categories.forEach((c) => {
- const posts = categories.get(c) || []
- posts.push(post)
- categories.set(c, posts)
- })
+ const posts = categories.get(c) || [];
+ posts.push(post);
+ categories.set(c, posts);
+ });
}
- })
+ });
- return categories
+ return categories;
}
export async function getPosts() {
- const posts = await getCollection('posts')
+ const posts = await getCollection("posts");
posts.sort((a, b) => {
- const aDate = a.data.pubDate || new Date()
- const bDate = b.data.pubDate || new Date()
- return bDate.getTime() - aDate.getTime()
- })
- return posts
+ const aDate = a.data.date || new Date();
+ const bDate = b.data.date || new Date();
+ return bDate.getTime() - aDate.getTime();
+ });
+ return posts;
}
-const parser = new MarkdownIt()
+const parser = new MarkdownIt();
export function getPostDescription(post: Post) {
if (post.data.description) {
- return post.data.description
+ return post.data.description;
}
- const html = parser.render(post.body)
- const sanitized = sanitizeHtml(html, { allowedTags: [] })
- return sanitized.slice(0, 400)
+ const html = parser.render(post.body);
+ const sanitized = sanitizeHtml(html, { allowedTags: [] });
+ return sanitized.slice(0, 400);
}
export function formatDate(date?: Date) {
- if(!date) return '--'
- const year = date.getFullYear().toString().padStart(4, '0')
- const month = (date.getMonth() + 1).toString().padStart(2, '0')
- const day = date.getDate().toString().padStart(2, '0')
+ if (!date) return "--";
+ const year = date.getFullYear().toString().padStart(4, "0");
+ const month = (date.getMonth() + 1).toString().padStart(2, "0");
+ const day = date.getDate().toString().padStart(2, "0");
- return `${year}-${month}-${day}`
+ return `${year}-${month}-${day}`;
}
-export function getPathFromCategory(category: string, category_map: {name: string, path: string}[]) {
- const mappingPath = category_map.find(l => l.name === category)
- return mappingPath ? mappingPath.path : category
-}
\ No newline at end of file
+export function getPathFromCategory(
+ category: string,
+ category_map: { name: string; path: string }[]
+) {
+ const mappingPath = category_map.find((l) => l.name === category);
+ return mappingPath ? mappingPath.path : category;
+}