Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 65 additions & 6 deletions goat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const starlightPath = path.join(curDirname, 'node_modules/@astrojs/starlight');
// 获取docs目录下的一级文件夹
let docsFile = await fs.readdir('src/content/docs');
docsFile = docsFile.filter((item) => item !== '.DS_Store')
// 按长度降序排序,确保正则匹配时长模式优先(如 2025.1.x 在 2025 之前匹配)
docsFile.sort((a, b) => b.length - a.length)

/**
* @description: 替换 utils/route-data.ts
Expand All @@ -30,14 +32,51 @@ const replaceRouteData = async () => {
*
*/
const replaceNavigation = async () => {
const originFile = path.join(starlightPath, "/utils/navigation.ts");
const originContent = (await fs.readFile(originFile)).toString();
const isPatched = originContent.includes('categories: any');

if (isPatched) {
/**
* 已经打过补丁,只需更新版本列表
* 从 versionRegex 行提取旧版本列表,然后全部替换为新列表
*/
let content = originContent;
const versionMatch = content.match(/versionRegex = \/.*?\(([^)]+)\)/);
if (versionMatch && versionMatch[1]) {
const oldList = versionMatch[1];
const newList = docsFile.join('|');
if (oldList !== newList) {
content = content.replaceAll(oldList, newList);
}
}

// linkFromRoute 的正则已经是幂等的,可以直接重新应用
const linkFromRouteRegex = /function linkFromRoute\(route: Route, currentPathname: string\): Link {[\s\S]*?}/;
content = content.replace(
linkFromRouteRegex,
`function linkFromRoute(route: Route, currentPathname: string): Link {
return makeLink(
slugToPathname(route.slug,route.id),
route.entry.data.sidebar.label || route.entry.data.title,
currentPathname,
route.entry.data.sidebar.badge,
route.entry.data.sidebar.attrs
);
}\n`
);

await fs.writeFile(originFile, content);
return;
}

/**
* 首次打补丁 - 原始逻辑
* 获取当前页面的 sidebar, 左侧菜单动态加载
* 根据页面路由获取sidebar
*/
const originFile = path.join(starlightPath, "/utils/navigation.ts");
const originContent = await fs.readFile(originFile);
const sideBarRegex = /export function getSidebar\(pathname\: string\, locale\: string \| undefined\).+\n(.+)/;
const sideBarContent = originContent.toString().replace(
const sideBarContent = originContent.replace(
sideBarRegex,
`export function getSidebar(pathname: string, locale: string | undefined, categories: any): SidebarEntry[] {
const routes = getLocaleRoutes(locale);
Expand Down Expand Up @@ -131,19 +170,39 @@ const replace404Astro = async () => {
*/
const replaceSlugs = async () => {
const originFile = path.join(starlightPath, "/utils/slugs.ts");
const originContent = await fs.readFile(originFile);
const originContent = (await fs.readFile(originFile)).toString();

// 动态计算需要特殊处理的版本:名称中包含 . 的版本目录 + developer + ebook
const dotVersions = docsFile.filter(f => f.includes('.'));
const slugVersionList = [...dotVersions, 'developer', 'ebook'].join('|');

const isPatched = originContent.includes('slugToPathname(slug: string, id: string)');

if (isPatched) {
/**
* 已经打过补丁,只需更新版本正则
*/
let content = originContent;
content = content.replace(
/const regex = \/([^/]+)\/;/,
`const regex = /${slugVersionList}/;`
);
await fs.writeFile(originFile, content);
return;
}

/**
* 首次打补丁 - 原始逻辑
* 获取当前页面的 id,生成正确的 pathname
* 主要为2.2.x版本的autogenerate生成正确的sidebar
*/
const linkFromRouteRegex = /export function slugToPathname\(slug\: string\)\: string {[\s\S]*?}/;
const linkFromRouteContent = originContent.toString().replace(
const linkFromRouteContent = originContent.replace(
linkFromRouteRegex,
`export function slugToPathname(slug: string, id: string): string {
// 2.2.x/zh-cn/overview/version-explain.md
let param = slugToParam(slug);
const regex = /2.2.x|developer|ebook/;
const regex = /${slugVersionList}/;
const [curVersion,lang, ...rest] = id.split('/');
const match = regex.exec(curVersion);
if (match) {
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export const DOCS_BANNER = {

// TODO: 文档Header数据
export const DOCS_ITEM = [
{
key: "2025.x",
label: "2025.x",
target: "_self",
link: "/docs/2025.x/overview/what-is-sca/",
translations: {
en: "2025.x",
link: "/en/docs/2025.x/overview/what-is-sca/",
}
},
{
key: "2023",
label: "2023.0.x",
Expand Down
9 changes: 0 additions & 9 deletions src/content/docs/2023/_sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@
},
"collapsed": false,
"items": [
{
"label": "AI",
"translations": {
"en": "AI"
},
"autogenerate": {
"directory": "user-guide/ai"
}
},
{
"label": "注册配置中心",
"translations": {
Expand Down
241 changes: 241 additions & 0 deletions src/content/docs/2025.x/_sidebar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
[

{
"label": "概览",
"translations": {
"en": "Overview"
},
"collapsed": false,
"items": [{
"label": "Spring Cloud Alibaba 是什么",
"translations": {
"en": "What is Spring Cloud Alibaba"
},
"link": "docs/overview/what-is-sca"
},
{
"label": "版本发布声明",
"translations": {
"en": "Release Notes"
},
"link": "docs/overview/version-explain/"
},
{
"label": "FAQ",
"translations": {
"en": "FAQ"
},
"link": "docs/overview/faq/"
}

]
},
{
"label": "用户指南",
"translations": {
"en": "User Guide"
},
"collapsed": false,
"items": [
{
"label": "注册配置中心",
"translations": {
"en": "Registration Configuration Center"
},
"items": [{
"label": "概述",
"translations": {
"en": "Overview"
},
"link": "docs/user-guide/nacos/overview/"
},
{
"label": "快速开始",
"translations": {
"en": "Quick Start"
},
"link": "docs/user-guide/nacos/quick-start/"
},
{
"label": "进阶指南",
"translations": {
"en": "Advanced Guide"
},
"link": "docs/user-guide/nacos/advanced-guide/"
}
]
},
{
"label": "分布式定时任务",
"translations": {
"en": "Scheduling Tasks"
},
"items":[
{
"label": "概述",
"translations": {
"en": "Overview"
},
"link": "docs/user-guide/schedulerx/overview/"
},
{
"label": "快速开始",
"translations": {
"en": "Quick Start"
},
"link": "docs/user-guide/schedulerx/quick-start/"
}
]
},
{
"label": "分布式事务",
"translations": {
"en": "Distributed Transaction"
},
"items": [{
"label": "概述",
"translations": {
"en": "Overview"
},
"link": "docs/user-guide/seata/overview/"
},
{
"label": "快速开始",
"translations": {
"en": "Quick Start"
},
"link": "docs/user-guide/seata/quick-start/"
},
{
"label": "进阶指南",
"translations": {
"en": "Advanced Guide"
},
"link": "docs/user-guide/seata/advanced-guide/"
}
]
},
{
"label": "限流降级",
"translations": {
"en": "Flow Control & Circuit Breaker"
},
"items": [{
"label": "概述",
"translations": {
"en": "Overview"
},
"link": "docs/user-guide/sentinel/overview/"
},
{
"label": "快速开始",
"translations": {
"en": "Quick Start"
},
"link": "docs/user-guide/sentinel/quick-start/"
},
{
"label": "进阶指南",
"translations": {
"en": "Advanced Guide"
},
"link": "docs/user-guide/sentinel/advanced-guide/"
}
]
},
{
"label": "分布式消息",
"translations": {
"en": "Distributed Messaging"
},
"items": [{
"label": "概述",
"translations": {
"en": "Overview"
},
"link": "docs/user-guide/rocketmq/overview/"
},
{
"label": "快速开始",
"translations": {
"en": "Quick Start"
},
"link": "docs/user-guide/rocketmq/quick-start/"
},
{
"label": "进阶指南",
"translations": {
"en": "Advanced Guide"
},
"link": "docs/user-guide/rocketmq/advanced-guide/"
}
]
},
{
"label": "异构服务",
"translations": {
"en": "Heterogeneous Services"
},
"items": [{
"label": "概述",
"translations": {
"en": "Overview"
},
"link": "docs/user-guide/sidecar/overview/"
},
{
"label": "快速开始",
"translations": {
"en": "Quick Start"
},
"link": "docs/user-guide/sidecar/quick-start/"
},
{
"label": "进阶指南",
"translations": {
"en": "Advanced Guide"
},
"link": "docs/user-guide/sidecar/advanced-guide/"
}
]
},
{
"label": "静态编译",
"translations": {
"en": "Native Image"
},
"items": [{
"label": "GraalVM概述",
"translations": {
"en": "Overview"
},
"link": "docs/user-guide/graalvm/overview/"
},
{
"label": "快速开始",
"translations": {
"en": "Quick Start"
},
"link": "docs/user-guide/graalvm/quick-start/"
},
{
"label": "进阶指南",
"translations": {
"en": "Advanced Guide"
},
"link": "docs/user-guide/graalvm/advanced-guide/"
}
]
}
]
},
{
"label": "最佳实践",
"translations": {
"en": "Best Practice"
},
"autogenerate": {
"directory": "best-practice"
}
}
]
Loading