使用Astro在github上写blog

添加分页、blog article、deprecated feature

2025-05-29

Written by: tdtc

Also see 使用hugo在gitee上写blog

pagination

Step 1

拷贝blog(src/pages/blog)中的文件:

[page].astro
index.astro

Step 2

修改index.astro:

import BlogPost from '../../components/BlogPost.astro';
import BaseLayout from '../../layouts/BaseLayout.astro';
import BlogPost from '../components/BlogPost.astro';
import BaseLayout from '../layouts/BaseLayout.astro';

Step 3

astro.config.mjs

site: "https://tdtc-hrb.github.io",
base: "ops-win",

hard-coded URLs

<a href="/blog">First</a>

Replace with

<a href={baseUrl} >First</a>
  <a href="/blog/2">Next</a>

Replace with

<a href={baseUrl + '/page/2'} >First</a>

blog article

Required

option

row limit

return paginate(all, { pageSize: 8 });
const allPosts = (Object.values(import.meta.glob('../../pages/posts/*.md', { eager: true }))).slice(
  0,
  8
);

deprecated feature

astroglob

await Astro.glob('../../pages/posts/*.md');

instead of

Object.values(import.meta.glob('../pages/posts/*.md', { eager: true }))
await Astro.glob('../../pages/posts/*.md');

instead of

Object.values(import.meta.glob('../../pages/posts/*.md', { eager: true }));

Run

npm install
npm run build
npm run preview