Skip to content

Commit 437834b

Browse files
committed
test version:graph
1 parent 026c77b commit 437834b

File tree

28 files changed

+1029
-168
lines changed

28 files changed

+1029
-168
lines changed

astro.config.mjs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import starlightGiscus from 'starlight-giscus'
88
import tailwind from "@astrojs/tailwind";
99
import vercel from '@astrojs/vercel';
1010
import starlightFullViewMode from 'starlight-fullview-mode'
11+
import starlightSiteGraph from 'starlight-site-graph'
1112

1213
// https://astro.build/config
1314
export default defineConfig({
@@ -20,7 +21,45 @@ export default defineConfig({
2021

2122
integrations: [starlight({
2223
plugins: [
23-
starlightFullViewMode({ leftSidebarEnabled: false, rightSidebarEnabled: false}),
24+
starlightSiteGraph({
25+
debug: false,
26+
graphConfig: {
27+
depth: 1,
28+
scale: 1,
29+
labelOpacityScale: 1.5,
30+
labelFontSize: 11,
31+
labelHoverScale: 1.3,
32+
renderArrows: true,
33+
tagRenderMode: 'same',
34+
actions: ['fullscreen', 'depth', 'reset-zoom', 'render-arrows', 'render-external', 'settings'],
35+
nodeDefaultStyle: {
36+
shape: 'star',
37+
cornerType: 'round',
38+
shapeCornerRadius: "25%",
39+
nodeScale: 1.6,
40+
neighbourScale: 30.0,
41+
shapeRotation: 'random',
42+
},
43+
nodeExternalStyle: {
44+
shape: 'star',
45+
shapePoints: 4,
46+
nodeScale: 0.9,
47+
},
48+
nodeVisitedStyle: {
49+
nodeScale: 1.1,
50+
},
51+
nodeCurrentStyle: {
52+
shapePoints: 6,
53+
nodeScale: 2.2,
54+
shapeRotation: 0,
55+
colliderScale: 1.4
56+
}
57+
},
58+
sitemapConfig: {
59+
includeExternalLinks: true
60+
}
61+
}),
62+
//starlightFullViewMode({ leftSidebarEnabled: false, rightSidebarEnabled: false}),
2463
starlightGiscus({
2564
repo: 'maindraster/docgiscus',
2665
repoId: 'R_kgDON-oOVQ',
@@ -77,7 +116,7 @@ export default defineConfig({
77116
collapsed: true,
78117
items: [{
79118
label: '首页',
80-
slug: 'tr_index'
119+
slug: 'trindex'
81120
},{
82121
label: '基础教程',
83122
autogenerate: {
@@ -101,7 +140,7 @@ export default defineConfig({
101140
collapsed: true,
102141
items: [{
103142
label: '电子电路设计篇',
104-
slug: 'electronics/index_ecd'
143+
slug: 'electronics/indexecd'
105144
},{
106145
label: '嵌入式开发篇',
107146
collapsed: true,
@@ -123,10 +162,10 @@ export default defineConfig({
123162
}]
124163
},{
125164
label: '人工智能篇',
126-
slug: 'ai/index_ai'
165+
slug: 'ai/indexai'
127166
},{
128167
label: '项目实战篇',
129-
slug: 'project/index_pro'
168+
slug: 'project/indexpro'
130169
},],
131170
}
132171
],

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
"@astrojs/check": "^0.9.4",
1515
"@astrojs/markdown-remark": "^6.3.1",
1616
"@astrojs/rss": "^4.0.11",
17-
"@astrojs/starlight": "^0.33.2",
17+
"@astrojs/starlight": "^0.34.2",
1818
"@astrojs/starlight-tailwind": "^3.0.1",
1919
"@astrojs/tailwind": "^6.0.2",
2020
"@astrojs/vercel": "^8.1.3",
2121
"@tsparticles/engine": "^3.8.1",
22-
"astro": "^5.7.6",
22+
"astro": "^5.7.10",
2323
"gsap": "^3.12.7",
2424
"hastscript": "^9.0.1",
2525
"micromark-util-symbol": "^2.0.1",
26+
"path-to-regexp": ">=6.3.0",
2627
"prismjs": "^1.29.0",
2728
"rehype-katex": "^7.0.1",
2829
"rehype-mathjax": "^6.0.0",
@@ -36,6 +37,7 @@
3637
"starlight-giscus": "^0.5.1",
3738
"starlight-image-zoom": "^0.8.0",
3839
"starlight-showcases": "^0.2.0",
40+
"starlight-site-graph": "^0.3.1",
3941
"tailwindcss": "^3.4.17",
4042
"typescript": "^5.8.2",
4143
"unist-util-visit": "^5.0.0"

pnpm-lock.yaml

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

src/components/Header.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const navItems = [
1616
{
1717
title: "文档",
1818
items: [
19-
{ name: "万能工科生教程", href: "/tr_index" },
20-
{ name: "篇章学习", href: "/electronics/index_ecd/" },
19+
{ name: "万能工科生教程", href: "/trindex" },
20+
{ name: "篇章学习", href: "/electronics/indexecd/" },
2121
]
2222
},
2323
{

src/content/combine.ts

Lines changed: 132 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,60 @@
1-
//import { AstroError } from 'astro/errors'
2-
import { z, type ZodLiteral, type ZodNumber, type ZodObject, type ZodString, type ZodUnion } from 'astro/zod'
31

4-
// 定义博客作者 schema
2+
import { z, type ZodLiteral, type ZodNumber, type ZodObject, type ZodString, type ZodUnion } from 'astro/zod';
3+
import { graphConfigSchema, nodeStyleSchema } from 'starlight-site-graph/config'; // 来自 starlight-site-graph
4+
5+
// 从 starlight-site-graph 的 schema
6+
const pageGraphConfigSchema = graphConfigSchema.extend({
7+
/**
8+
* Whether the graph component should be visible for this page, has precedence over global rules
9+
*/
10+
visible: z.boolean().optional(),
11+
12+
/**
13+
* Custom styles for the node defined by this page
14+
* Overrides any other styles that may be applied to this node
15+
*/
16+
nodeStyle: nodeStyleSchema.partial().optional(),
17+
});
18+
export type PageGraphConfig = z.infer<typeof pageGraphConfigSchema>;
19+
20+
const pageSitemapConfigSchema = z.object({
21+
/**
22+
* Whether the page should be included in the sitemap, has precedence over global rules
23+
*
24+
* @optional
25+
*/
26+
include: z.boolean().optional(),
27+
/**
28+
* Specifies the title of the page in the sitemap (and thus graph and backlinks). \
29+
* If not provided, either the `title` frontmatter field, the global `pageTitles` setting,
30+
* or the last part of the page's path is used as the title
31+
* Otherwise, the `pageTitle` overrides all other title sources.
32+
*
33+
* @optional
34+
*/
35+
pageTitle: z.string().optional(),
36+
/**
37+
* Determine for this page which links are included in the sitemap.
38+
* The link is included/excluded if the link's target _path_ matches one of the rules.
39+
* When a rule starts with `!`, the link is _excluded_ if matched.
40+
* Rules are evaluated in order, the first matching rule determines the inclusion of the link.
41+
* These rules have precedence over global rules.
42+
*
43+
* @optional
44+
*/
45+
linkInclusionRules: z.array(z.string()).default([]),
46+
});
47+
export type PageSitemapConfig = z.infer<typeof pageSitemapConfigSchema>;
48+
49+
const pageBacklinksConfigSchema = z.object({
50+
/**
51+
* Whether the backlinks component should be visible for this page, has precedence over global rules
52+
*/
53+
visible: z.boolean().optional(),
54+
});
55+
export type PageBacklinksConfig = z.infer<typeof pageBacklinksConfigSchema>;
56+
57+
// 从 starlight-blog 的 schema
558
export const blogAuthorSchema = z.object({
659
/**
760
* The name of the author.
@@ -19,22 +72,8 @@ export const blogAuthorSchema = z.object({
1972
* The URL to the author's website.
2073
*/
2174
url: z.string().url().optional(),
22-
})
75+
});
2376

24-
// 定义主题 schema
25-
export const topicSchema = z.object({
26-
/**
27-
* ID of the topic to associate with the current page if the page is not listed in any topic sidebar configuration.
28-
*
29-
* @see https://starlight-sidebar-topics.netlify.app/docs/guides/unlisted-pages/
30-
*/
31-
topic: z.string().optional(),
32-
})
33-
34-
export type TopicFrontmatterSchema = z.input<typeof topicSchema>
35-
export type StarlightBlogAuthor = z.infer<typeof blogAuthorSchema>
36-
37-
// 定义博客条目 schema
3877
export const blogEntrySchema = ({ image }: SchemaContext) =>
3978
z.object({
4079
/**
@@ -92,46 +131,80 @@ export const blogEntrySchema = ({ image }: SchemaContext) =>
92131
* Featured blog posts are displayed in a dedicated sidebar group above recent blog posts.
93132
*/
94133
featured: z.boolean().optional(),
95-
/**
96-
* ID of the topic to associate with the current page if the page is not listed in any topic sidebar configuration.
97-
*
98-
* @see https://starlight-sidebar-topics.netlify.app/docs/guides/unlisted-pages/
99-
*/
100-
topic: z.string().optional(),
101-
})
134+
});
102135

103-
// 合并后的 schema 函数
136+
// 融合的 schema
104137
export function combinedSchema(context: SchemaContext) {
105-
// 检查上下文以提供更好的迁移错误消息
106-
if (!context) {
107-
// throw new AstroError(
108-
// 'Missing schema validation context.',
109-
// `You may need to update your content collections configuration in the \`src/content.config.ts\` file and pass the context to the schema function:
138+
// 检查 context 是否存在
110139

111-
// \`docs: defineCollection({ loader: docsLoader(), schema: docsSchema({ extend: (context) => combinedSchema(context) }) })\`
140+
// 创建 blog 部分的 schema
141+
const blogPart = blogEntrySchema(context).partial();
112142

113-
// If you believe this is a bug, please file an issue at https://github.com/HiDeoo/starlight-blog/issues/new/choose`,
114-
// )
115-
}
143+
// 创建 site-graph 部分的 schema
144+
const siteGraphPart = z.object({
145+
/**
146+
* The title of the page
147+
*
148+
* @required
149+
*/
150+
title: z.string().optional(),
151+
/**
152+
* Specify direct links to other pages of the site
153+
*
154+
* @optional
155+
*/
156+
links: z.array(z.string()).optional(),
157+
/**
158+
* Tags linked to this page (重复的字段,但保留以兼容两个插件)
159+
*
160+
* @optional
161+
*/
162+
tags: z.array(z.string()).optional(),
163+
/**
164+
* Configuration for the sitemap
165+
*
166+
* @optional
167+
*/
168+
sitemap: pageSitemapConfigSchema.optional().default({
169+
linkInclusionRules: ['**/*'],
170+
}),
171+
/**
172+
* Configuration for the graph component for this page
173+
*
174+
* Overrides global graph configuration
175+
*
176+
* @optional
177+
*/
178+
graph: pageGraphConfigSchema.optional(),
179+
/**
180+
* Configuration for the backlinks component for this page
181+
*
182+
* Overrides global backlinks configuration
183+
*
184+
* @optional
185+
*/
186+
backlinks: pageBacklinksConfigSchema.optional(),
187+
});
116188

117-
// 返回合并了 blog 和 topic 属性的 schema
118-
return blogEntrySchema(context).partial()
189+
// 返回融合后的 schema
190+
return z.object({
191+
...blogPart.shape,
192+
...siteGraphPart.shape,
193+
});
119194
}
120195

121-
// 用于向后兼容的 blogSchema 函数
122-
export function blogSchema(context: SchemaContext) {
123-
return combinedSchema(context)
124-
}
196+
export type StarlightBlogAuthor = z.infer<typeof blogAuthorSchema>;
197+
export type PageSiteGraphFrontmatter = z.infer<typeof pageSiteGraphSchema>;
125198

126199
interface SchemaContext {
127-
image: ImageFunction
200+
image: ImageFunction;
128201
}
129202

130203
// https://github.com/withastro/astro/blob/7d597506615fa5a34327304e8321be7b9c4b799d/packages/astro/src/assets/types.ts#L34-L42
131204
type ImageFunction = () => ZodObject<{
132-
src: ZodString
133-
width: ZodNumber
134-
height: ZodNumber
205+
src: ZodString;
206+
width: ZodNumber;
207+
height: ZodNumber;
135208
format: ZodUnion<
136209
[
137210
ZodLiteral<'png'>,
@@ -143,5 +216,17 @@ type ImageFunction = () => ZodObject<{
143216
ZodLiteral<'svg'>,
144217
ZodLiteral<'avif'>,
145218
]
146-
>
147-
}>
219+
>;
220+
}>;
221+
222+
// 导出合并后的 pageSiteGraphSchema,以便向外部提供兼容性
223+
export const pageSiteGraphSchema = z.object({
224+
title: z.string().optional(),
225+
links: z.array(z.string()).optional(),
226+
tags: z.array(z.string()).optional(),
227+
sitemap: pageSitemapConfigSchema.optional().default({
228+
linkInclusionRules: ['**/*'],
229+
}),
230+
graph: pageGraphConfigSchema.optional(),
231+
backlinks: pageBacklinksConfigSchema.optional(),
232+
});

src/content/config.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import { defineCollection } from 'astro:content';
22
import { docsSchema,i18nSchema } from '@astrojs/starlight/schema';
33
import { docsLoader} from '@astrojs/starlight/loaders';
44
import { blogSchema } from 'starlight-blog/schema';
5+
import { pageSiteGraphSchema } from 'starlight-site-graph/schema';
6+
import { combinedSchema } from './combine';
7+
8+
const graph = defineCollection({
9+
loader: docsLoader(),//glob({ pattern: "**/*.(md|mdx)", base: "./src/content/docs" }),
10+
schema: docsSchema({
11+
extend: combinedSchema
12+
})
13+
});
514

615
export const collections = {
716
docs: defineCollection({
@@ -10,5 +19,4 @@ export const collections = {
1019
extend: (context) => blogSchema(context)
1120
}) }),
1221
i18n: defineCollection({ type: 'data', schema: i18nSchema() }),
13-
};
14-
22+
};
File renamed without changes.

src/content/docs/blog/blog7.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
title: 📕图书馆
33
date: 2025-04-14
4-
tags: [目录页]
4+
tags:
5+
- 书籍
56
featured: true
67
---
78

src/content/docs/books/book1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
title: 穷查理宝典
33
lastupdate: 2025-02-03
4+
tags:
5+
- 书籍
46
---
57

68
```
File renamed without changes.

0 commit comments

Comments
 (0)