Skip to content

Commit 6480953

Browse files
committed
fix blog url & giscus
1 parent cc720f7 commit 6480953

7 files changed

Lines changed: 94 additions & 5 deletions

File tree

astro.config.mjs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,33 @@ import starlightImageZoom from 'starlight-image-zoom';
44
import remarkMath from "remark-math";
55
import rehypeMathjax from 'rehype-mathjax';
66
import starlightBlog from 'starlight-blog'
7+
import starlightGiscus from 'starlight-giscus'
78

89
import tailwind from "@astrojs/tailwind";
910

1011
// https://astro.build/config
1112
export default defineConfig({
12-
site: 'https://maindraster.github.io',
13+
site: 'https://maindraster.netlify.app',
1314
base: "/",
1415

1516
integrations: [starlight({
16-
plugins: [starlightBlog({
17+
plugins: [
18+
starlightGiscus({
19+
repo: 'maindraster/docgiscus',
20+
repoId: 'R_kgDON-oOVQ',
21+
category: 'Announcement',
22+
categoryId: 'DIC_kwDON-oOVc4CnRoe',
23+
theme:'catppuccin_latte'
24+
}),
25+
starlightBlog({
1726
title: "博客",
1827
postCount: 5,
1928
recentPostCount: 10,
29+
blog: {
30+
dir: 'src/content/blog',
31+
// 确保路由模式正确
32+
routePattern: '/blog/[...slug]'
33+
}
2034
}),starlightImageZoom(),
2135
// starlightUtils({
2236
// navLinks: {
@@ -34,8 +48,9 @@ export default defineConfig({
3448
}
3549
},
3650
customCss: [
37-
'./src/tailwind2.css',
51+
'./src/tailwind2.css',
3852
// 你的自定义 CSS 文件的相对路径
53+
'./src/styles/giscus.css',
3954
'./src/styles/root.css',
4055
'./src/styles/search.css',
4156
'./src/styles/iconfont.css',
@@ -93,3 +108,19 @@ export default defineConfig({
93108
remarkRehype: { footnoteLabel: '参考', footnoteBackLabel: '返回正文' },
94109
}
95110
});
111+
112+
// <script src="https://giscus.app/client.js"
113+
// data-repo="maindraster/docgiscus"
114+
// data-repo-id="R_kgDON-oOVQ"
115+
// data-category="Announcements"
116+
// data-category-id="DIC_kwDON-oOVc4CnRoe"
117+
// data-mapping="title"
118+
// data-strict="0"
119+
// data-reactions-enabled="1"
120+
// data-emit-metadata="0"
121+
// data-input-position="bottom"
122+
// data-theme="light_tritanopia"
123+
// data-lang="zh-CN"
124+
// crossorigin="anonymous"
125+
// async>
126+
// </script>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"remark-math": "^6.0.0",
3131
"sharp": "^0.33.5",
3232
"starlight-blog": "^0.17.2",
33+
"starlight-giscus": "^0.5.1",
3334
"starlight-image-zoom": "^0.8.0",
3435
"starlight-showcases": "^0.2.0",
3536
"starlight-site-graph": "^0.1.8",

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/content/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { defineCollection } from 'astro:content';
22
import { docsSchema,i18nSchema } from '@astrojs/starlight/schema';
3+
import { docsLoader} from '@astrojs/starlight/loaders';
34
import { blogSchema } from 'starlight-blog/schema';
45

56
export const collections = {
6-
docs: defineCollection({ schema: docsSchema({
7+
docs: defineCollection({
8+
loader: docsLoader(),
9+
schema: docsSchema({
710
extend: (context) => blogSchema(context)
811
}) }),
912
i18n: defineCollection({ type: 'data', schema: i18nSchema() }),

src/scripts/theme.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// src/scripts/giscus-theme.js
2+
function updateGiscusTheme() {
3+
const frame = document.querySelector('iframe.giscus-frame');
4+
if (frame) {
5+
// 从 localStorage 获取当前主题
6+
const currentTheme = localStorage.getItem('starlight-theme') || 'auto';
7+
// 根据主题设置对应的 giscus 主题
8+
const giscusTheme = currentTheme === 'dark' ? 'dark_dimmed' : 'light';
9+
10+
frame.contentWindow.postMessage(
11+
{
12+
giscus: {
13+
setConfig: {
14+
theme: giscusTheme
15+
}
16+
}
17+
},
18+
'https://giscus.app'
19+
);
20+
}
21+
}
22+
23+
// 监听主题选择器变化
24+
document.addEventListener('DOMContentLoaded', function() {
25+
const themeSelect = document.querySelector('starlight-theme-select');
26+
if (themeSelect) {
27+
themeSelect.addEventListener('change', updateGiscusTheme);
28+
}
29+
});
30+
31+
// 监听 localStorage 变化
32+
window.addEventListener('storage', (e) => {
33+
if (e.key === 'starlight-theme') {
34+
updateGiscusTheme();
35+
}
36+
});
37+
38+
// 初始化时执行一次
39+
document.addEventListener('DOMContentLoaded', updateGiscusTheme);
40+

src/styles/giscus.css

Whitespace-only changes.

src/styles/root.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ top: 0;
8080
justify-content: center;
8181
align-items: center;
8282
height: 400px;
83-
}
83+
}
84+

0 commit comments

Comments
 (0)