diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index a3f1265..bb0b180 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -1,4 +1,4 @@ -name: 自动部署 +name: 鑷姩閮ㄧ讲 on: push: branches: @@ -13,11 +13,11 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - name: 检查分支 + - name: 妫€鏌ュ垎鏀? uses: actions/checkout@v4 with: ref: master - - name: 缓存项目 npm 包 + - name: 缂撳瓨椤圭洰 npm 鍖? id: cache-node-modules uses: actions/cache@v3 with: @@ -25,32 +25,29 @@ jobs: key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} restore-keys: | ${{ runner.os }}-nodeModules- - - name: 安装 Node + - name: 瀹夎 Node uses: actions/setup-node@v4 with: node-version: "22.x" - - name: 安装 Hexo - run: | - npm install hexo-cli --global - - name: 安装依赖 + - name: 瀹夎渚濊禆 if: steps.cache-node-modules.outputs.cache-hit != 'true' run: | npm install - - name: 清理文件树 + - name: 娓呯悊鏂囦欢鏍? run: | npm run clean - - name: 生成静态文件并压缩 + - name: 鐢熸垚闈欐€佹枃浠跺苟鍘嬬缉 run: | npm run build - - name: 部署 + - name: 閮ㄧ讲 run: | - cd ./public + cd ./dist git init git config user.name "${{ gitea.actor }}" git config user.email "${{ gitea.actor }}@noreply.gitea.io" git add . - git commit -m "${{ gitea.event.head_commit.message }}··[$(date +"%Z %Y-%m-%d %A %H:%M:%S")]" + git commit -m "${{ gitea.event.head_commit.message }}路路[$(date +"%Z %Y-%m-%d %A %H:%M:%S")]" git push --force --quiet "https://${{ gitea.actor }}:${{ secrets.DEPLOY_TOKEN }}@git.biss.click/biss/blog.git" master:page - name: Deploy to Server run: | - curl -k -X POST "https://panel.biss.click/hook?access_key=1XJG8IvYTSZVvD5dpm86GYIpQxgxBcucULnX1MFskZSKayXU" \ No newline at end of file + curl -k -X POST "https://panel.biss.click/hook?access_key=1XJG8IvYTSZVvD5dpm86GYIpQxgxBcucULnX1MFskZSKayXU" diff --git a/.gitignore b/.gitignore index 414b6b8..c877d4f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ db.json *.log node_modules/ .astro/ -public/ +dist/ .deploy*/ _multiconfig.yml .hintrc diff --git a/astro.config.mjs b/astro.config.mjs index d4faba4..972300e 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -8,8 +8,6 @@ import remarkHexoLinkCards from './src/lib/remarkHexoLinkCards.mjs'; export default defineConfig({ site: 'https://blog.biss.click', output: 'static', - outDir: './public', - publicDir: './static', integrations: [sitemap()], markdown: { processor: unified({ diff --git a/static/images/Bi.ico b/public/images/Bi.ico similarity index 100% rename from static/images/Bi.ico rename to public/images/Bi.ico diff --git a/static/images/background.png b/public/images/background.png similarity index 100% rename from static/images/background.png rename to public/images/background.png diff --git a/static/img/404.jpg b/public/img/404.jpg similarity index 100% rename from static/img/404.jpg rename to public/img/404.jpg diff --git a/static/img/butterfly-icon.png b/public/img/butterfly-icon.png similarity index 100% rename from static/img/butterfly-icon.png rename to public/img/butterfly-icon.png diff --git a/static/img/error-page.png b/public/img/error-page.png similarity index 100% rename from static/img/error-page.png rename to public/img/error-page.png diff --git a/static/img/favicon.ico b/public/img/favicon.ico similarity index 100% rename from static/img/favicon.ico rename to public/img/favicon.ico diff --git a/static/img/friend_404.gif b/public/img/friend_404.gif similarity index 100% rename from static/img/friend_404.gif rename to public/img/friend_404.gif diff --git a/static/js/external-links.js b/public/js/external-links.js similarity index 100% rename from static/js/external-links.js rename to public/js/external-links.js diff --git a/static/js/random.js b/public/js/random.js similarity index 100% rename from static/js/random.js rename to public/js/random.js diff --git a/static/js/search/typesense-search.js b/public/js/search/typesense-search.js similarity index 100% rename from static/js/search/typesense-search.js rename to public/js/search/typesense-search.js diff --git a/static/js/shuoshuo.js b/public/js/shuoshuo.js similarity index 100% rename from static/js/shuoshuo.js rename to public/js/shuoshuo.js diff --git a/static/js/shuoshuoshouye.js b/public/js/shuoshuoshouye.js similarity index 100% rename from static/js/shuoshuoshouye.js rename to public/js/shuoshuoshouye.js diff --git a/static/js/weather.js b/public/js/weather.js similarity index 100% rename from static/js/weather.js rename to public/js/weather.js diff --git a/scripts/generate-abbrlinks.mjs b/scripts/generate-abbrlinks.mjs index efda223..459e328 100644 --- a/scripts/generate-abbrlinks.mjs +++ b/scripts/generate-abbrlinks.mjs @@ -1,7 +1,7 @@ import { readdir, readFile, writeFile } from 'node:fs/promises'; import { basename, extname, join, relative } from 'node:path'; -const POSTS_DIR = join(process.cwd(), 'posts'); +const POSTS_DIR = join(process.cwd(), 'src', 'content', 'posts'); const CRC32_TABLE = new Uint32Array(256); diff --git a/src/content.config.ts b/src/content.config.ts new file mode 100644 index 0000000..51dfff7 --- /dev/null +++ b/src/content.config.ts @@ -0,0 +1,19 @@ +import { defineCollection, z } from 'astro:content'; +import { glob } from 'astro/loaders'; + +const posts = defineCollection({ + loader: glob({ pattern: '**/*.md', base: './src/content/posts' }), + schema: z.object({ + title: z.any().optional(), + date: z.any().optional(), + abbrlink: z.any().optional(), + tags: z.any().optional(), + categories: z.any().optional(), + summary: z.any().optional(), + description: z.any().optional(), + comments: z.any().optional(), + cover: z.any().optional(), + }).passthrough(), +}); + +export const collections = { posts }; diff --git a/posts/2025/2025.08/add-ai-summary.md b/src/content/posts/2025/2025.08/add-ai-summary.md similarity index 100% rename from posts/2025/2025.08/add-ai-summary.md rename to src/content/posts/2025/2025.08/add-ai-summary.md diff --git a/posts/2025/2025.08/add-calendar-side.md b/src/content/posts/2025/2025.08/add-calendar-side.md similarity index 100% rename from posts/2025/2025.08/add-calendar-side.md rename to src/content/posts/2025/2025.08/add-calendar-side.md diff --git a/posts/2025/2025.08/add-cms-system.md b/src/content/posts/2025/2025.08/add-cms-system.md similarity index 100% rename from posts/2025/2025.08/add-cms-system.md rename to src/content/posts/2025/2025.08/add-cms-system.md diff --git a/posts/2025/2025.08/add-own-app-to-1panel.md b/src/content/posts/2025/2025.08/add-own-app-to-1panel.md similarity index 100% rename from posts/2025/2025.08/add-own-app-to-1panel.md rename to src/content/posts/2025/2025.08/add-own-app-to-1panel.md diff --git a/posts/2025/2025.08/add-welcome-message-in-sidebar.md b/src/content/posts/2025/2025.08/add-welcome-message-in-sidebar.md similarity index 100% rename from posts/2025/2025.08/add-welcome-message-in-sidebar.md rename to src/content/posts/2025/2025.08/add-welcome-message-in-sidebar.md diff --git a/posts/2025/2025.08/c-first-in-first.md b/src/content/posts/2025/2025.08/c-first-in-first.md similarity index 100% rename from posts/2025/2025.08/c-first-in-first.md rename to src/content/posts/2025/2025.08/c-first-in-first.md diff --git a/posts/2025/2025.08/cs-2.md b/src/content/posts/2025/2025.08/cs-2.md similarity index 100% rename from posts/2025/2025.08/cs-2.md rename to src/content/posts/2025/2025.08/cs-2.md diff --git a/posts/2025/2025.08/custom-bottom.md b/src/content/posts/2025/2025.08/custom-bottom.md similarity index 100% rename from posts/2025/2025.08/custom-bottom.md rename to src/content/posts/2025/2025.08/custom-bottom.md diff --git a/posts/2025/2025.08/custom-category-bar.md b/src/content/posts/2025/2025.08/custom-category-bar.md similarity index 100% rename from posts/2025/2025.08/custom-category-bar.md rename to src/content/posts/2025/2025.08/custom-category-bar.md diff --git a/posts/2025/2025.08/custom-font.md b/src/content/posts/2025/2025.08/custom-font.md similarity index 100% rename from posts/2025/2025.08/custom-font.md rename to src/content/posts/2025/2025.08/custom-font.md diff --git a/posts/2025/2025.08/custom-footer.md b/src/content/posts/2025/2025.08/custom-footer.md similarity index 100% rename from posts/2025/2025.08/custom-footer.md rename to src/content/posts/2025/2025.08/custom-footer.md diff --git a/posts/2025/2025.08/custom-navbar.md b/src/content/posts/2025/2025.08/custom-navbar.md similarity index 100% rename from posts/2025/2025.08/custom-navbar.md rename to src/content/posts/2025/2025.08/custom-navbar.md diff --git a/posts/2025/2025.08/custom-right-menu.md b/src/content/posts/2025/2025.08/custom-right-menu.md similarity index 100% rename from posts/2025/2025.08/custom-right-menu.md rename to src/content/posts/2025/2025.08/custom-right-menu.md diff --git a/posts/2025/2025.08/deploy-owncloud-and-onlyoffice.md b/src/content/posts/2025/2025.08/deploy-owncloud-and-onlyoffice.md similarity index 100% rename from posts/2025/2025.08/deploy-owncloud-and-onlyoffice.md rename to src/content/posts/2025/2025.08/deploy-owncloud-and-onlyoffice.md diff --git a/posts/2025/2025.08/en250811.md b/src/content/posts/2025/2025.08/en250811.md similarity index 100% rename from posts/2025/2025.08/en250811.md rename to src/content/posts/2025/2025.08/en250811.md diff --git a/posts/2025/2025.08/go-to-random-page.md b/src/content/posts/2025/2025.08/go-to-random-page.md similarity index 100% rename from posts/2025/2025.08/go-to-random-page.md rename to src/content/posts/2025/2025.08/go-to-random-page.md diff --git a/posts/2025/2025.08/how-to-deploy.md b/src/content/posts/2025/2025.08/how-to-deploy.md similarity index 100% rename from posts/2025/2025.08/how-to-deploy.md rename to src/content/posts/2025/2025.08/how-to-deploy.md diff --git a/posts/2025/2025.08/set-shuoshuo-page.md b/src/content/posts/2025/2025.08/set-shuoshuo-page.md similarity index 100% rename from posts/2025/2025.08/set-shuoshuo-page.md rename to src/content/posts/2025/2025.08/set-shuoshuo-page.md diff --git a/posts/2025/2025.08/tr3000-openwrt.md b/src/content/posts/2025/2025.08/tr3000-openwrt.md similarity index 100% rename from posts/2025/2025.08/tr3000-openwrt.md rename to src/content/posts/2025/2025.08/tr3000-openwrt.md diff --git a/posts/2025/2025.08/use-github-to-deploy-on-server.md b/src/content/posts/2025/2025.08/use-github-to-deploy-on-server.md similarity index 100% rename from posts/2025/2025.08/use-github-to-deploy-on-server.md rename to src/content/posts/2025/2025.08/use-github-to-deploy-on-server.md diff --git a/posts/2025/2025.09/install-adguardhome-on-openwrt.md b/src/content/posts/2025/2025.09/install-adguardhome-on-openwrt.md similarity index 100% rename from posts/2025/2025.09/install-adguardhome-on-openwrt.md rename to src/content/posts/2025/2025.09/install-adguardhome-on-openwrt.md diff --git a/posts/2025/2025.09/install-openclash-on-openwrt.md b/src/content/posts/2025/2025.09/install-openclash-on-openwrt.md similarity index 100% rename from posts/2025/2025.09/install-openclash-on-openwrt.md rename to src/content/posts/2025/2025.09/install-openclash-on-openwrt.md diff --git a/posts/2025/2025.10/adguard-and-openclash.md b/src/content/posts/2025/2025.10/adguard-and-openclash.md similarity index 100% rename from posts/2025/2025.10/adguard-and-openclash.md rename to src/content/posts/2025/2025.10/adguard-and-openclash.md diff --git a/posts/2025/2025.10/adguard-rules.md b/src/content/posts/2025/2025.10/adguard-rules.md similarity index 100% rename from posts/2025/2025.10/adguard-rules.md rename to src/content/posts/2025/2025.10/adguard-rules.md diff --git a/posts/2026/2026.1/about-my-friends.md b/src/content/posts/2026/2026.1/about-my-friends.md similarity index 100% rename from posts/2026/2026.1/about-my-friends.md rename to src/content/posts/2026/2026.1/about-my-friends.md diff --git a/posts/2026/2026.2/add-float-menu.md b/src/content/posts/2026/2026.2/add-float-menu.md similarity index 100% rename from posts/2026/2026.2/add-float-menu.md rename to src/content/posts/2026/2026.2/add-float-menu.md diff --git a/posts/2026/2026.2/add-renovate-bot.md b/src/content/posts/2026/2026.2/add-renovate-bot.md similarity index 100% rename from posts/2026/2026.2/add-renovate-bot.md rename to src/content/posts/2026/2026.2/add-renovate-bot.md diff --git a/posts/2026/2026.2/add-typesense-search.md b/src/content/posts/2026/2026.2/add-typesense-search.md similarity index 100% rename from posts/2026/2026.2/add-typesense-search.md rename to src/content/posts/2026/2026.2/add-typesense-search.md diff --git a/posts/2026/2026.2/happy-new-year-2026.md b/src/content/posts/2026/2026.2/happy-new-year-2026.md similarity index 100% rename from posts/2026/2026.2/happy-new-year-2026.md rename to src/content/posts/2026/2026.2/happy-new-year-2026.md diff --git a/posts/2026/2026.2/install-bitwarden.md b/src/content/posts/2026/2026.2/install-bitwarden.md similarity index 100% rename from posts/2026/2026.2/install-bitwarden.md rename to src/content/posts/2026/2026.2/install-bitwarden.md diff --git a/posts/2026/2026.2/install-gitea.md b/src/content/posts/2026/2026.2/install-gitea.md similarity index 100% rename from posts/2026/2026.2/install-gitea.md rename to src/content/posts/2026/2026.2/install-gitea.md diff --git a/posts/2026/2026.2/remove-to-gitea.md b/src/content/posts/2026/2026.2/remove-to-gitea.md similarity index 100% rename from posts/2026/2026.2/remove-to-gitea.md rename to src/content/posts/2026/2026.2/remove-to-gitea.md diff --git a/posts/2026/2026.3/opencv-1.md b/src/content/posts/2026/2026.3/opencv-1.md similarity index 100% rename from posts/2026/2026.3/opencv-1.md rename to src/content/posts/2026/2026.3/opencv-1.md diff --git a/posts/2026/2026.3/opencv-2.md b/src/content/posts/2026/2026.3/opencv-2.md similarity index 100% rename from posts/2026/2026.3/opencv-2.md rename to src/content/posts/2026/2026.3/opencv-2.md diff --git a/posts/2026/2026.3/opencv-install.md b/src/content/posts/2026/2026.3/opencv-install.md similarity index 100% rename from posts/2026/2026.3/opencv-install.md rename to src/content/posts/2026/2026.3/opencv-install.md diff --git a/posts/2026/2026.4/gpt-img2.md b/src/content/posts/2026/2026.4/gpt-img2.md similarity index 100% rename from posts/2026/2026.4/gpt-img2.md rename to src/content/posts/2026/2026.4/gpt-img2.md diff --git a/posts/2026/2026.4/install-opengl.md b/src/content/posts/2026/2026.4/install-opengl.md similarity index 100% rename from posts/2026/2026.4/install-opengl.md rename to src/content/posts/2026/2026.4/install-opengl.md diff --git a/posts/2026/2026.4/msp-1.md b/src/content/posts/2026/2026.4/msp-1.md similarity index 100% rename from posts/2026/2026.4/msp-1.md rename to src/content/posts/2026/2026.4/msp-1.md diff --git a/posts/2026/2026.4/opengl-1.md b/src/content/posts/2026/2026.4/opengl-1.md similarity index 100% rename from posts/2026/2026.4/opengl-1.md rename to src/content/posts/2026/2026.4/opengl-1.md diff --git a/posts/2026/2026.4/opengl-2.md b/src/content/posts/2026/2026.4/opengl-2.md similarity index 100% rename from posts/2026/2026.4/opengl-2.md rename to src/content/posts/2026/2026.4/opengl-2.md diff --git a/posts/2026/2026.4/opengl-3.md b/src/content/posts/2026/2026.4/opengl-3.md similarity index 100% rename from posts/2026/2026.4/opengl-3.md rename to src/content/posts/2026/2026.4/opengl-3.md diff --git a/posts/2026/2026.5/ordinary-day-own-rhythm.md b/src/content/posts/2026/2026.5/ordinary-day-own-rhythm.md similarity index 100% rename from posts/2026/2026.5/ordinary-day-own-rhythm.md rename to src/content/posts/2026/2026.5/ordinary-day-own-rhythm.md diff --git a/src/lib/pages.ts b/src/lib/pages.ts deleted file mode 100644 index 303243a..0000000 --- a/src/lib/pages.ts +++ /dev/null @@ -1,37 +0,0 @@ -type PageModule = { - frontmatter: Record; - Content: unknown; - rawContent?: () => string; -}; - -export type SitePage = PageModule & { - title: string; - slug: string; -}; - -const modules = import.meta.glob('/source/**/index.md', { eager: true }); - -export function getSitePages(): SitePage[] { - return Object.entries(modules) - .filter(([path]) => { - if (path.includes('/_posts/') || path.includes('/_drafts/')) return false; - return ![ - '/source/about/index.md', - '/source/cc/index.md', - '/source/cookie/index.md', - '/source/link/index.md', - '/source/privacy/index.md', - '/source/categories/index.md', - '/source/tags/index.md', - '/source/shuoshuo/index.md', - ].includes(path); - }) - .map(([path, module]) => { - const slug = path.replace('/source/', '').replace('/index.md', ''); - return { - ...module, - title: String(module.frontmatter.title ?? slug), - slug, - }; - }); -} diff --git a/src/lib/posts.ts b/src/lib/posts.ts index bb08fea..29d086d 100644 --- a/src/lib/posts.ts +++ b/src/lib/posts.ts @@ -1,11 +1,8 @@ -type MarkdownModule = { - frontmatter: Record; - Content: unknown; - rawContent?: () => string; - file?: string; -}; +import type { CollectionEntry } from 'astro:content'; +import { getCollection } from 'astro:content'; -export type BlogPost = MarkdownModule & { +export type BlogPost = { + entry: CollectionEntry<'posts'>; title: string; slug: string; date: Date; @@ -16,10 +13,9 @@ export type BlogPost = MarkdownModule & { comments: boolean; cover?: string; href: string; + body: string; }; -const modules = import.meta.glob('/posts/**/*.md', { eager: true }); - function asArray(value: unknown): string[] { if (Array.isArray(value)) return value.map(String).filter(Boolean); if (typeof value === 'string' && value.trim()) return [value.trim()]; @@ -43,20 +39,19 @@ function formatDate(date: Date): string { }).format(date); } -function fallbackSlug(path: string): string { - return path +function fallbackSlug(id: string): string { + return id .split('/') .pop() ?.replace(/\.md$/, '') .toLowerCase() ?? 'post'; } -function makeSummary(module: MarkdownModule): string { - const explicit = module.frontmatter.summary ?? module.frontmatter.description; +function makeSummary(entry: CollectionEntry<'posts'>): string { + const explicit = entry.data.summary ?? entry.data.description; if (typeof explicit === 'string' && explicit.trim()) return explicit.trim(); - const raw = module.rawContent?.() ?? ''; - return raw + return entry.body .replace(/```[\s\S]*?```/g, '') .replace(/<[^>]+>/g, '') .replace(/[#>*_`~\-\[\]\(\)]/g, '') @@ -65,34 +60,37 @@ function makeSummary(module: MarkdownModule): string { .slice(0, 120); } -export function getAllPosts(): BlogPost[] { - return Object.entries(modules) - .map(([path, module]) => { - const date = toDate(module.frontmatter.date); - const slug = String(module.frontmatter.abbrlink ?? fallbackSlug(path)); - const title = String(module.frontmatter.title ?? slug); +export async function getAllPosts(): Promise { + const entries = await getCollection('posts'); + + return entries + .map((entry) => { + const date = toDate(entry.data.date); + const slug = String(entry.data.abbrlink ?? fallbackSlug(entry.id)); + const title = String(entry.data.title ?? slug); return { - ...module, + entry, title, slug, date, dateText: formatDate(date), - tags: asArray(module.frontmatter.tags), - categories: asArray(module.frontmatter.categories), - summary: makeSummary(module), - comments: module.frontmatter.comments !== false, - cover: typeof module.frontmatter.cover === 'string' ? module.frontmatter.cover : undefined, + tags: asArray(entry.data.tags), + categories: asArray(entry.data.categories), + summary: makeSummary(entry), + comments: entry.data.comments !== false, + cover: typeof entry.data.cover === 'string' ? entry.data.cover : undefined, href: `/posts/${slug}/`, + body: entry.body, }; }) .sort((a, b) => b.date.valueOf() - a.date.valueOf()); } -export function getAllTags(): string[] { - return [...new Set(getAllPosts().flatMap((post) => post.tags))].sort((a, b) => a.localeCompare(b, 'zh-CN')); +export async function getAllTags(): Promise { + return [...new Set((await getAllPosts()).flatMap((post) => post.tags))].sort((a, b) => a.localeCompare(b, 'zh-CN')); } -export function getAllCategories(): string[] { - return [...new Set(getAllPosts().flatMap((post) => post.categories))].sort((a, b) => a.localeCompare(b, 'zh-CN')); +export async function getAllCategories(): Promise { + return [...new Set((await getAllPosts()).flatMap((post) => post.categories))].sort((a, b) => a.localeCompare(b, 'zh-CN')); } diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro deleted file mode 100644 index 7166103..0000000 --- a/src/pages/[...slug].astro +++ /dev/null @@ -1,26 +0,0 @@ ---- -import BaseLayout from '@/layouts/BaseLayout.astro'; -import PageHeaderCard from '@/components/PageHeaderCard.astro'; -import { getSitePages } from '@/lib/pages'; - -export function getStaticPaths() { - return getSitePages().map((page) => ({ - params: { slug: page.slug }, - props: { page }, - })); -} - -const { page } = Astro.props; -const { Content } = page; ---- - - -
- -
-
-
- -
-
-
diff --git a/src/pages/api/posts.json.js b/src/pages/api/posts.json.js index c7e8e44..5714201 100644 --- a/src/pages/api/posts.json.js +++ b/src/pages/api/posts.json.js @@ -1,7 +1,7 @@ import { getAllPosts } from '@/lib/posts'; -export function GET() { - const posts = getAllPosts().map((post) => ({ +export async function GET() { + const posts = (await getAllPosts()).map((post) => ({ title: post.title, href: post.href, })); diff --git a/src/pages/archives/index.astro b/src/pages/archives/index.astro index 5feac45..5a7898f 100644 --- a/src/pages/archives/index.astro +++ b/src/pages/archives/index.astro @@ -5,7 +5,7 @@ import PageHeaderCard from '@/components/PageHeaderCard.astro'; import { getAllPosts } from '@/lib/posts'; import { getPageSlice } from '@/lib/pagination'; -const posts = getAllPosts(); +const posts = await getAllPosts(); const pageData = getPageSlice(posts, 1); --- diff --git a/src/pages/archives/page/[page].astro b/src/pages/archives/page/[page].astro index 429ae98..b09cfcc 100644 --- a/src/pages/archives/page/[page].astro +++ b/src/pages/archives/page/[page].astro @@ -5,8 +5,8 @@ import PageHeaderCard from '@/components/PageHeaderCard.astro'; import { getAllPosts } from '@/lib/posts'; import { getPageSlice, getPaginationPaths } from '@/lib/pagination'; -export function getStaticPaths() { - const posts = getAllPosts(); +export async function getStaticPaths() { + const posts = await getAllPosts(); return getPaginationPaths(posts).map((page) => ({ params: { page: String(page) }, @@ -15,7 +15,7 @@ export function getStaticPaths() { } const { page } = Astro.props; -const posts = getAllPosts(); +const posts = await getAllPosts(); const pageData = getPageSlice(posts, page); --- diff --git a/src/pages/categories/[category].astro b/src/pages/categories/[category].astro index 7104d64..7e146f1 100644 --- a/src/pages/categories/[category].astro +++ b/src/pages/categories/[category].astro @@ -4,15 +4,15 @@ import PageHeaderCard from '@/components/PageHeaderCard.astro'; import PostCard from '@/components/PostCard.astro'; import { getAllCategories, getAllPosts } from '@/lib/posts'; -export function getStaticPaths() { - return getAllCategories().map((category) => ({ +export async function getStaticPaths() { + return (await getAllCategories()).map((category) => ({ params: { category }, props: { category }, })); } const { category } = Astro.props; -const posts = getAllPosts().filter((post) => post.categories.includes(category)); +const posts = (await getAllPosts()).filter((post) => post.categories.includes(category)); --- diff --git a/src/pages/categories/index.astro b/src/pages/categories/index.astro index fc75480..f1cdffc 100644 --- a/src/pages/categories/index.astro +++ b/src/pages/categories/index.astro @@ -3,8 +3,8 @@ import BaseLayout from '@/layouts/BaseLayout.astro'; import PageHeaderCard from '@/components/PageHeaderCard.astro'; import { getAllCategories, getAllPosts } from '@/lib/posts'; -const posts = getAllPosts(); -const categories = getAllCategories(); +const posts = await getAllPosts(); +const categories = await getAllCategories(); --- diff --git a/src/pages/index.astro b/src/pages/index.astro index 6c7595e..92bd849 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -6,9 +6,9 @@ import PostCard from '@/components/PostCard.astro'; import { getAllCategories, getAllPosts, getAllTags } from '@/lib/posts'; import { getPageSlice } from '@/lib/pagination'; -const posts = getAllPosts(); -const tags = getAllTags(); -const categories = getAllCategories(); +const posts = await getAllPosts(); +const tags = await getAllTags(); +const categories = await getAllCategories(); const pageData = getPageSlice(posts, 1); --- diff --git a/src/pages/page/[page].astro b/src/pages/page/[page].astro index bbfe36f..f9b440d 100644 --- a/src/pages/page/[page].astro +++ b/src/pages/page/[page].astro @@ -6,8 +6,8 @@ import BaseLayout from '@/layouts/BaseLayout.astro'; import { getAllCategories, getAllPosts, getAllTags } from '@/lib/posts'; import { getPageSlice, getPaginationPaths } from '@/lib/pagination'; -export function getStaticPaths() { - const posts = getAllPosts(); +export async function getStaticPaths() { + const posts = await getAllPosts(); return getPaginationPaths(posts).map((page) => ({ params: { page: String(page) }, @@ -16,9 +16,9 @@ export function getStaticPaths() { } const { page } = Astro.props; -const posts = getAllPosts(); -const tags = getAllTags(); -const categories = getAllCategories(); +const posts = await getAllPosts(); +const tags = await getAllTags(); +const categories = await getAllCategories(); const pageData = getPageSlice(posts, page); --- diff --git a/src/pages/posts/[slug].astro b/src/pages/posts/[slug].astro index 4e2eade..4e32b07 100644 --- a/src/pages/posts/[slug].astro +++ b/src/pages/posts/[slug].astro @@ -3,19 +3,20 @@ import ArticleSidebar from '@/components/ArticleSidebar.astro'; import PostCopyrightCard from '@/components/PostCopyrightCard.astro'; import TwikooComments from '@/components/TwikooComments.astro'; import BaseLayout from '@/layouts/BaseLayout.astro'; +import { render } from 'astro:content'; import { getAllPosts } from '@/lib/posts'; -export function getStaticPaths() { - return getAllPosts().map((post) => ({ +export async function getStaticPaths() { + return (await getAllPosts()).map((post) => ({ params: { slug: post.slug }, props: { post }, })); } const { post } = Astro.props; -const { Content } = post; -const allPosts = getAllPosts(); -const rawContent = post.rawContent?.() ?? ''; +const { Content } = await render(post.entry); +const allPosts = await getAllPosts(); +const rawContent = post.body; const textContent = rawContent .replace(/```[\s\S]*?```/g, '') .replace(/<[^>]+>/g, '') @@ -69,7 +70,7 @@ function makeToc(raw: string) { }); } -const toc = makeToc(post.rawContent?.() ?? ''); +const toc = makeToc(post.body); const relatedPosts = allPosts .filter((item) => item.slug !== post.slug) .filter((item) => item.categories.some((category) => post.categories.includes(category))) diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 0644a3e..178fa2a 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -1,8 +1,8 @@ import rss from '@astrojs/rss'; import { getAllPosts } from '@/lib/posts'; -export function GET(context) { - const posts = getAllPosts(); +export async function GET(context) { + const posts = await getAllPosts(); return rss({ title: "Bi's Blog", diff --git a/src/pages/tags/[tag].astro b/src/pages/tags/[tag].astro index 921b30c..e848fd5 100644 --- a/src/pages/tags/[tag].astro +++ b/src/pages/tags/[tag].astro @@ -4,15 +4,15 @@ import PageHeaderCard from '@/components/PageHeaderCard.astro'; import PostCard from '@/components/PostCard.astro'; import { getAllPosts, getAllTags } from '@/lib/posts'; -export function getStaticPaths() { - return getAllTags().map((tag) => ({ +export async function getStaticPaths() { + return (await getAllTags()).map((tag) => ({ params: { tag }, props: { tag }, })); } const { tag } = Astro.props; -const posts = getAllPosts().filter((post) => post.tags.includes(tag)); +const posts = (await getAllPosts()).filter((post) => post.tags.includes(tag)); --- diff --git a/src/pages/tags/index.astro b/src/pages/tags/index.astro index d9bc971..583397a 100644 --- a/src/pages/tags/index.astro +++ b/src/pages/tags/index.astro @@ -3,8 +3,8 @@ import BaseLayout from '@/layouts/BaseLayout.astro'; import PageHeaderCard from '@/components/PageHeaderCard.astro'; import { getAllPosts, getAllTags } from '@/lib/posts'; -const posts = getAllPosts(); -const tags = getAllTags(); +const posts = await getAllPosts(); +const tags = await getAllTags(); ---