From 41d5ac1173f027c2074d84dcd381fd1c8b3af2df Mon Sep 17 00:00:00 2001 From: ykiko Date: Sun, 17 Aug 2025 11:47:44 +0800 Subject: [PATCH] Fix docs and improve ci (#182) --- .github/workflows/check-format.yml | 14 +++++++++++++- .github/workflows/cmake.yml | 23 +++++++++++++---------- .github/workflows/xmake.yml | 25 +++++++++++++------------ docs/.vitepress/config.ts | 13 ++++++------- docs/.vitepress/theme/sidebar.ts | 13 +++++++++++-- docs/en/index.md | 6 +++--- 6 files changed, 59 insertions(+), 35 deletions(-) diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml index 2eeca1a9..17e3902c 100644 --- a/.github/workflows/check-format.yml +++ b/.github/workflows/check-format.yml @@ -1,9 +1,21 @@ name: format on: - pull_request: push: branches: [main] + paths: + - .clang-format + - "include/**" + - "src/**" + - "tests/**" + + pull_request: + branches: [main] + paths: + - .clang-format + - "include/**" + - "src/**" + - "tests/**" jobs: check: diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index e1bd11f1..e178a35c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -3,18 +3,21 @@ name: cmake on: push: branches: [main] + paths: + - ".github/workflows/cmake.yml" + - "include/**" + - "src/**" + - "tests/**" + - "CMakeLists.txt" + pull_request: branches: [main] - paths-ignore: - - "docs" - - "scripts" - - ".clang-format" - - ".clangd" - - ".gitignore" - - "LICENSE" - - "README.md" - - ".github/workflows/xmake.yml" - - "xmake.lua" + paths: + - ".github/workflows/cmake.yml" + - "include/**" + - "src/**" + - "tests/**" + - "CMakeLists.txt" jobs: build: diff --git a/.github/workflows/xmake.yml b/.github/workflows/xmake.yml index e85329c3..19c32340 100644 --- a/.github/workflows/xmake.yml +++ b/.github/workflows/xmake.yml @@ -3,20 +3,21 @@ name: xmake on: push: branches: [main] + paths: + - ".github/workflows/xmake.yml" + - "include/**" + - "src/**" + - "tests/**" + - "xmake.lua" + pull_request: branches: [main] - paths-ignore: - - "docs" - - "scripts" - - ".clang-format" - - ".clangd" - - ".gitignore" - - "LICENSE" - - "README.md" - - ".github/workflows/cmake.yml" - - "CMakeLists.txt" - - "CMakePresets.json" - - "cmake" + paths: + - ".github/workflows/xmake.yml" + - "include/**" + - "src/**" + - "tests/**" + - "xmake.lua" jobs: linux: diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 7c60670e..40e66f06 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -18,17 +18,16 @@ export default defineConfig({ nav: [ { text: 'Home', link: '/' }, ], - sidebar: { "/zh/": [ - genSidebar('zh/design', { title: 'Design' }), - genSidebar('zh/dev', { title: 'Development' }), - genSidebar('zh/guide', { title: 'Guide' }), + genSidebar('zh', 'design', { title: 'Design' }), + genSidebar('zh', 'dev', { title: 'Development' }), + genSidebar('zh', 'guide', { title: 'Guide' }), ], "/": [ - genSidebar('en/design', { title: 'Design' }), - genSidebar('en/dev', { title: 'Development' }), - genSidebar('en/guide', { title: 'Guide' }), + genSidebar('en', 'design', { title: 'Design' }), + genSidebar('en', 'dev', { title: 'Development' }), + genSidebar('en', 'guide', { title: 'Guide' }), ], }, socialLinks: [ diff --git a/docs/.vitepress/theme/sidebar.ts b/docs/.vitepress/theme/sidebar.ts index 37788f63..95214ddb 100644 --- a/docs/.vitepress/theme/sidebar.ts +++ b/docs/.vitepress/theme/sidebar.ts @@ -3,6 +3,7 @@ import path from 'path' import { DefaultTheme } from 'vitepress' export const genSidebar = ( + lang: string, dirPath: string, options: { title: string @@ -10,7 +11,7 @@ export const genSidebar = ( ignore?: string[] } ): DefaultTheme.SidebarItem => { - const sidebarPath = path.resolve(process.cwd(), dirPath) + const sidebarPath = path.resolve(process.cwd(), lang, dirPath) const ignore = options.ignore || ['index.md'] const files = fs @@ -22,9 +23,17 @@ export const genSidebar = ( const match = content.match(/^#\s+(.*)/) const title = match ? match[1] : file.replace('.md', '') + let prefix = '/'; + if (lang != 'en') { + prefix += lang; + prefix += '/'; + } + return { text: title, - link: `/${dirPath}/${file.replace('.md', '')}` + /// Make sure link for en is actually root, beacuse Github Pages + /// doesn't support redirect url. + link: `${prefix}${dirPath}/${file.replace('.md', '')}` } }) diff --git a/docs/en/index.md b/docs/en/index.md index 9d3e7e47..81c6bebc 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -8,13 +8,13 @@ hero: actions: - theme: brand text: What is clice? - link: /en/guide/what-is-clice + link: /guide/what-is-clice - theme: alt text: Quick Start - link: /en/guide/quick-start + link: /guide/quick-start - theme: alt text: Contribution - link: /en/dev/contribution + link: /dev/contribution image: src: /image.png alt: clice