From def78ab7097c50c8a2749698b28e49ba404879b9 Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Thu, 6 Mar 2025 19:30:54 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A024.03=5FLTS=5FSP1?= =?UTF-8?q?=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/nginx/nginx.conf | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/deploy/nginx/nginx.conf b/deploy/nginx/nginx.conf index 80ce476..2dbe327 100644 --- a/deploy/nginx/nginx.conf +++ b/deploy/nginx/nginx.conf @@ -176,5 +176,16 @@ http { proxy_pass https://dsapi.test.osinfra.cn/; # proxy_pass https://dsapi.osinfra.cn/; } + + location ^~ /zh/docs/24.03_LTS_SP1/ { + proxy_set_header X-Forwarded-For $http_x_real_ip; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_ssl_protocols TLSv1.3; + proxy_ssl_verify off; + # 转发后移除前缀 + rewrite ^/zh/docs/24.03_LTS_SP1(/.*)$ $1 break; + proxy_pass http://openeuler-docs-website-stable2-24-03-lts-sp1.openeuler-website-docs:8080; + } } } \ No newline at end of file -- Gitee From c0e3c495a5b3ffd153a550b4ef58dc48718a5eff Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Thu, 6 Mar 2025 19:55:54 +0800 Subject: [PATCH 2/5] fix: update nginx --- deploy/nginx/nginx.conf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deploy/nginx/nginx.conf b/deploy/nginx/nginx.conf index 2dbe327..3bd3291 100644 --- a/deploy/nginx/nginx.conf +++ b/deploy/nginx/nginx.conf @@ -183,8 +183,7 @@ http { proxy_set_header Connection ""; proxy_ssl_protocols TLSv1.3; proxy_ssl_verify off; - # 转发后移除前缀 - rewrite ^/zh/docs/24.03_LTS_SP1(/.*)$ $1 break; + proxy_pass http://openeuler-docs-website-stable2-24-03-lts-sp1.openeuler-website-docs:8080; } } -- Gitee From 62fa9f08bd8b3c877fab76860f71a294a018fab5 Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Fri, 7 Mar 2025 11:32:20 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=E8=8F=9C=E5=8D=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/src/layouts/LayoutDoc.vue | 16 +++++++-- docs/.vitepress/src/stores/menu.ts | 13 ++++--- scripts/build.js | 42 ++++++++++++++++------- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/docs/.vitepress/src/layouts/LayoutDoc.vue b/docs/.vitepress/src/layouts/LayoutDoc.vue index 20327d0..bc86892 100644 --- a/docs/.vitepress/src/layouts/LayoutDoc.vue +++ b/docs/.vitepress/src/layouts/LayoutDoc.vue @@ -101,7 +101,9 @@ const onClickMenuItem = (item: DocMenuNodeT, newOpener?: boolean) => { } if (pathname === window.location.pathname && hash) { - window.location.hash = hash; + window.history.replaceState({}, '', '#' + hash); + scrollIntoTitle(); + window.dispatchEvent(new HashChangeEvent('hashchange')); } else { router.go(href); } @@ -173,8 +175,18 @@ const onScrollAnchor = () => { return; } + const allChildren: DocMenuNodeT[] = []; + parentNode.children.forEach((item) => { + allChildren.push(item); + if (item.children.length > 0) { + item.children.forEach((e) => { + allChildren.push(e); + }); + } + }); + const distances: Array<{ item: DocMenuNodeT; top: number }> = []; - for (const item of parentNode.children) { + for (const item of allChildren) { if (!item.href || !item.href.includes('#')) { continue; } diff --git a/docs/.vitepress/src/stores/menu.ts b/docs/.vitepress/src/stores/menu.ts index d0b3dd2..ddf52b5 100644 --- a/docs/.vitepress/src/stores/menu.ts +++ b/docs/.vitepress/src/stores/menu.ts @@ -44,14 +44,15 @@ export const useMenuStore = defineStore('menu', () => { const menuExpanded = ref([]); const updateExpanded = () => { - if (!currentNode.value || currentNode.value?.depth < 3) { + const node = rootTree.getNodeByHref(rootTree.root, menuValue.value); + if (!node || node.depth < 3) { menuExpanded.value = []; return; } - const arr = prevNodes.value; - if (currentNode.value.children?.length > 0) { - arr.push(currentNode.value); + const arr = rootTree.getPrevNodes(node, 1); + if (node.children?.length > 0) { + arr.push(node); } menuExpanded.value = arr.map((item) => item.id); @@ -59,11 +60,13 @@ export const useMenuStore = defineStore('menu', () => { onMounted(() => { menuValue.value = currentNode.value?.id || ''; - updateExpanded(); }); watch(currentNode, () => { menuValue.value = currentNode.value?.id || ''; + }); + + watch(menuValue, () => { updateExpanded(); }); diff --git a/scripts/build.js b/scripts/build.js index 5f3d7fd..cc7d196 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -67,9 +67,9 @@ function parseHref(href, label) { /** * 获取以 title 为 label 的节点 - * @param {number} level 标题等级 + * @param {string} filePath 文件路径 */ -function getTitleNodes(filePath, level) { +function getTitleNodes(filePath) { // 检测文件是否存在 if (!fs.existsSync(filePath)) { errors.push({ @@ -88,22 +88,38 @@ function getTitleNodes(filePath, level) { // 解析获取 md 指定等级的标题 const md = markdownIt().use(markdownItAnchor, { permalink: false, - level: [level], + level: [2, 3], slugify: (str) => slugify(getMarkdownOrignalContent(str)), }); const tokens = md.parse(markdownContent, {}); const headings = []; + let lastH2; tokens.forEach((token, index) => { - if (token.type === 'heading_open' && token.tag === `h${level}`) { + if (token.type === 'heading_open' && token.attrs?.find(([key]) => key === 'id')?.[1]) { const id = token.attrs.find(([key]) => key === 'id')[1]; const mdPath = parseHref(`${filePath}#${id}`, ''); - headings.push({ - type: 'anchor', - label: getMarkdownOrignalContent(tokens[index + 1].content), - id: mdPath, - href: mdPath, - }); + if (token.tag === 'h2') { + if (lastH2 && lastH2.children.length === 0) { + delete lastH2.children; + } + + lastH2 = { + type: 'anchor', + label: getMarkdownOrignalContent(tokens[index + 1].content), + id: mdPath, + href: mdPath, + children: [], + }; + headings.push(lastH2); + } else if (token.tag === 'h3' && lastH2) { + lastH2.children.push({ + type: 'anchor', + label: getMarkdownOrignalContent(tokens[index + 1].content), + id: mdPath, + href: mdPath, + }); + } } }); @@ -152,7 +168,7 @@ function getId(item) { /** * 转换子节点 - * @param {string} 父目录 + * @param {string} dirname 父目录 * @param {array} children 子节点 */ async function parseNodeChildren(dirname, children) { @@ -210,7 +226,7 @@ async function parseNodeChildren(dirname, children) { } if (!child.children) { - const nodes = getTitleNodes(mdPath, 2); + const nodes = getTitleNodes(mdPath); if (nodes?.length > 0) { child.children = nodes; } @@ -233,7 +249,7 @@ async function parseNodeChildren(dirname, children) { /** * 合并文件内容的递归函数(同步) - * @param {string} 文件路径 + * @param {string} filePath 文件路径 */ async function mergeReferences(filePath) { // 检测文件是否存在 -- Gitee From 444a6450e930d2a2355f0fdb9e2d8b02d7964743 Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Fri, 7 Mar 2025 11:32:29 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96nginx=E8=BD=AC?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/nginx/nginx.conf | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/deploy/nginx/nginx.conf b/deploy/nginx/nginx.conf index 3bd3291..08d084b 100644 --- a/deploy/nginx/nginx.conf +++ b/deploy/nginx/nginx.conf @@ -101,18 +101,6 @@ http { index index.html; } - location ^~ /zh/docs/24.03_LTS_SP1/ { - proxy_set_header X-Forwarded-For $http_x_real_ip; - proxy_http_version 1.1; - proxy_set_header Connection ""; - proxy_ssl_protocols TLSv1.3; - proxy_ssl_verify off; - - proxy_pass https://openeuler-website-docs-zh.openeuler-website-docs:8080/zh/docs/24.03_LTS_SP1/; - } - - # include ./confd/nginx*.conf; - error_page 401 402 403 405 406 407 413 414 /error.html; error_page 500 501 502 503 504 505 /error.html; error_page 404 /404.html; -- Gitee From 4f2ef6316b0a90917e729fbf4fff2632e1baff84 Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Fri, 7 Mar 2025 16:30:45 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96nginx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/nginx/nginx.conf | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/deploy/nginx/nginx.conf b/deploy/nginx/nginx.conf index 08d084b..9f753b7 100644 --- a/deploy/nginx/nginx.conf +++ b/deploy/nginx/nginx.conf @@ -165,6 +165,46 @@ http { # proxy_pass https://dsapi.osinfra.cn/; } + location ^~ /zh/docs/24.03_LTS_SP1/css/ { + proxy_set_header X-Forwarded-For $http_x_real_ip; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_ssl_protocols TLSv1.3; + proxy_ssl_verify off; + + proxy_pass http://openeuler-docs-website-stable2-24-03-lts-sp1.openeuler-website-docs:8080/css/; + } + + location ^~ /zh/docs/24.03_LTS_SP1/fonts/ { + proxy_set_header X-Forwarded-For $http_x_real_ip; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_ssl_protocols TLSv1.3; + proxy_ssl_verify off; + + proxy_pass http://openeuler-docs-website-stable2-24-03-lts-sp1.openeuler-website-docs:8080/fonts/; + } + + location ^~ /zh/docs/24.03_LTS_SP1/img/ { + proxy_set_header X-Forwarded-For $http_x_real_ip; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_ssl_protocols TLSv1.3; + proxy_ssl_verify off; + + proxy_pass http://openeuler-docs-website-stable2-24-03-lts-sp1.openeuler-website-docs:8080/img/; + } + + location ^~ /zh/docs/24.03_LTS_SP1/js/ { + proxy_set_header X-Forwarded-For $http_x_real_ip; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_ssl_protocols TLSv1.3; + proxy_ssl_verify off; + + proxy_pass http://openeuler-docs-website-stable2-24-03-lts-sp1.openeuler-website-docs:8080/js/; + } + location ^~ /zh/docs/24.03_LTS_SP1/ { proxy_set_header X-Forwarded-For $http_x_real_ip; proxy_http_version 1.1; -- Gitee