From 19f2cbf48bf9e5849a476a0c58d02a0bca2778f3 Mon Sep 17 00:00:00 2001 From: wuyiping0628 <1106773985@qq.com> Date: Mon, 12 Oct 2026 05:26:09 -0700 Subject: [PATCH] feat: modify the pointing of the tiny-pro submodule --- .github/workflows/build-docs.yml | 3 +- .github/workflows/deploy-github.yml | 1 + .github/workflows/deploy-obs.yml | 1 + .gitmodules | 6 +-- .vitepress/config.mts | 42 ++++++--------- .vitepress/theme/Layout.vue | 12 +++++ .vitepress/theme/markdown/tinypro-docs.ts | 62 ++++++++++++++++------- opentiny.design | 1 - tiny-pro | 1 + 9 files changed, 78 insertions(+), 51 deletions(-) delete mode 160000 opentiny.design create mode 160000 tiny-pro diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index d0ff0cd..6cac376 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -9,8 +9,7 @@ on: - 'tiny-vue/examples/sites/demos/pc/webdoc/**' - 'tiny-engine/docs/**' - '.vitepress/**' - - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/**' - - 'opentiny.design/packages/opentiny-docs/src/assets/images/vue-pro/**' + - 'tiny-pro' workflow_dispatch: {} # 支持手动触发 permissions: diff --git a/.github/workflows/deploy-github.yml b/.github/workflows/deploy-github.yml index 0d11e61..6e03c43 100644 --- a/.github/workflows/deploy-github.yml +++ b/.github/workflows/deploy-github.yml @@ -8,6 +8,7 @@ on: - 'tiny-robot/docs/**' - 'tiny-vue/examples/sites/demos/pc/webdoc/**' - 'tiny-engine/docs/**' + - 'tiny-pro' - '.vitepress/**' workflow_dispatch: {} # 支持手动触发 repository_dispatch: diff --git a/.github/workflows/deploy-obs.yml b/.github/workflows/deploy-obs.yml index 9ab903c..9a665df 100644 --- a/.github/workflows/deploy-obs.yml +++ b/.github/workflows/deploy-obs.yml @@ -8,6 +8,7 @@ on: - 'next-sdk/docs/**' - 'tiny-robot/docs/**' - 'tiny-vue/examples/sites/demos/pc/webdoc/**' + - 'tiny-pro' - '.vitepress/**' workflow_dispatch: diff --git a/.gitmodules b/.gitmodules index 56b4ca7..47880f6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,8 +19,8 @@ [submodule "web-agent"] path = web-agent url = git@github.com:opentiny/web-agent.git -[submodule "opentiny.design"] - path = opentiny.design - url = git@github.com:opentiny/opentiny.design.git +[submodule "tiny-pro"] + path = tiny-pro + url = git@github.com:opentiny/tiny-pro.git branch = dev shallow = true diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 796f579..39baf35 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -19,14 +19,14 @@ const TinyProSidebar = [ { text: '后端指南', link: '/tiny-pro/guide/back-end-guide' }, { text: '前端指南', link: '/tiny-pro/guide/front-end-guide' }, { text: '目录结构', link: '/tiny-pro/guide/directory' }, - { text: '路由与菜单', link: '/tiny-pro/guide/menus' }, + { text: '路由与菜单', link: '/tiny-pro/guide/menu' }, { text: '新增页面', link: '/tiny-pro/guide/newpage' }, - { text: 'Mock数据', link: '/tiny-pro/guide/mock' }, + { text: 'Mock数据', link: '/tiny-pro/guide/request' }, { text: '国际化', link: '/tiny-pro/guide/international' }, { text: '个性化主题', link: '/tiny-pro/guide/theme' }, { text: '布局', link: '/tiny-pro/guide/layout' }, { text: '状态管理', link: '/tiny-pro/guide/status' }, - { text: '权限控制', link: '/tiny-pro/guide/role' } + { text: '权限控制', link: '/tiny-pro/guide/permissions' } ] } ] @@ -185,27 +185,11 @@ export default defineConfig({ 'next-sdk/packages/**/*.md', 'genui-sdk/packages/**/*.md', // tinyglobby 的 ignore 会丢掉 ! 反选,不能用「整仓排除再放行」。 - // 只排除 TinyPro Vue 中文文档以外的 markdown。 - // opentiny.design 自带一份 genui-sdk 子模块。站点已用 genui/genui-sdk, - // 这份文档的 demo 解析不到物料包,不能编进本站。 - 'opentiny.design/genui-sdk/**', - 'opentiny.design/packages/common/**', - 'opentiny.design/packages/home/**', - 'opentiny.design/packages/tech-college/**', - 'opentiny.design/packages/tiny-engine-portal/**', - 'opentiny.design/packages/opentiny-docs/src/views/ng-pro/**', - 'opentiny.design/packages/opentiny-docs/src/views/theme/**', - 'opentiny.design/packages/opentiny-docs/src/views/tiny-cli/**', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/*-us.md', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/quick.md', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/plugin.md', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/library.md', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/practiced.md', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/backEnd.md', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/back-end-design.md', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/back-end-api-specification.md', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/back-end-guide-spring-boot.md', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/responsive-adaptation-guide.md' + // TinyPro 文档只取 tiny-pro/docs 下的指南。首页和仓库里其余 markdown 不编进本站。 + 'tiny-pro/template/**', + 'tiny-pro/.github/**', + 'tiny-pro/CONTRIBUTING.md', + 'tiny-pro/docs/index.md' ], base: process.env.VITEPRESS_BASE || '/', head: [['link', { rel: 'icon', href: '/images/logo-mini.svg' }]], @@ -221,7 +205,13 @@ export default defineConfig({ } ]) ], - server: { open: true }, + server: { + open: true, + watch: { + // Vite 已忽略 .git、node_modules 和构建目录。这里只避开模板源码。 + ignored: ['**/tiny-pro/template/**'] + } + }, // 子模块里有大量独立站点的 index.html。依赖扫描如果把它们都当成入口, // 会扫到无效的 import.meta.glob,导致文档站起不来。 optimizeDeps: { @@ -287,7 +277,7 @@ export default defineConfig({ 'tiny-editor/packages/docs/fluent-editor/docs/api/:path*': 'tiny-editor/api/:path*', 'tiny-editor/packages/docs/fluent-editor/docs/modules/:path*': 'tiny-editor/modules/:path*', 'web-agent/docs/:path*': 'web-agent/guide/:path*', - 'opentiny.design/packages/opentiny-docs/src/views/vue-pro/:path*': 'tiny-pro/guide/:path*' + 'tiny-pro/docs/:path*': 'tiny-pro/guide/:path*' }, themeConfig: { // https://vitepress.dev/reference/default-theme-config diff --git a/.vitepress/theme/Layout.vue b/.vitepress/theme/Layout.vue index 1f9f8fe..4fef3e7 100644 --- a/.vitepress/theme/Layout.vue +++ b/.vitepress/theme/Layout.vue @@ -105,6 +105,18 @@ const redirectMap = [ { patterns: ['/tiny-pro.html', '/tiny-pro/', '/tiny-pro/guide.html', '/tiny-pro/guide/'], target: '/tiny-pro/guide/start' + }, + { + patterns: ['/tiny-pro/guide/menus', '/tiny-pro/guide/menus.html'], + target: '/tiny-pro/guide/menu' + }, + { + patterns: ['/tiny-pro/guide/mock', '/tiny-pro/guide/mock.html'], + target: '/tiny-pro/guide/request' + }, + { + patterns: ['/tiny-pro/guide/role', '/tiny-pro/guide/role.html'], + target: '/tiny-pro/guide/permissions' } ]; diff --git a/.vitepress/theme/markdown/tinypro-docs.ts b/.vitepress/theme/markdown/tinypro-docs.ts index 7a82c18..9ec9fa1 100644 --- a/.vitepress/theme/markdown/tinypro-docs.ts +++ b/.vitepress/theme/markdown/tinypro-docs.ts @@ -1,5 +1,5 @@ /** - * 子模块里的 TinyPro 文档沿用 opentiny.design 的写法。 + * TinyPro 文档来自 tiny-pro 仓库的 docs 目录,图片在 docs/public/images。 * 这里只在渲染时改链接、图片路径和 HTML 标题,不复制源文件。 */ @@ -18,7 +18,7 @@ const slugify = (str: string) => .replace(/^(\d)/, '_$1') .toLowerCase() -const isVueProDoc = (filePath = '') => filePath.replace(/\\/g, '/').includes('/views/vue-pro/') +const isTinyProDoc = (filePath = '') => filePath.replace(/\\/g, '/').includes('/tiny-pro/docs/') const mapOutsideFences = (src: string, transform: (part: string) => string) => { const re = /(^|\n)(```[\s\S]*?\n```)/g @@ -37,9 +37,7 @@ const mapOutsideFences = (src: string, transform: (part: string) => string) => { const inlineHeading = (inner: string) => inner - .replace(/]*href\s*=\s*['"]([^'"]+)['"][^>]*>([\s\S]*?)<\/a>/gi, '[$2]($1)') .replace(/([\s\S]*?)<\/code>/gi, '`$1`') - .replace(//gi, ' ') .replace(/<[^>]+>/g, '') .replace(/\s+/g, ' ') .trim() @@ -54,21 +52,45 @@ const convertHtmlHeadings = (src: string) => return `${heading} {#${id}}` }) -const rewriteVueProUrls = (src: string) => - src - // 高级章节已不在本站发布,总览里的入口回到上游文档 - .replaceAll('](/vue-pro/docs/advanced/', '](https://opentiny.design/vue-pro/docs/advanced/') - .replaceAll('/src/assets/images/vue-pro/', '../../assets/images/vue-pro/') - .replaceAll('](/tiny-vue)', '](/tiny-vue/guide/introduce)') - .replaceAll('](/tiny-cli/', '](https://opentiny.design/tiny-cli/') - .replaceAll('](./tiny-pro.md)', '](./quick-start)') - .replace(/!\[([^\]]*)\]\(([^)\s]*?%20[^)\s]*)\)/g, (_match, alt: string, url: string) => { - const decoded = decodeURIComponent(url) - return /\s/.test(decoded) ? `![${alt}](<${decoded}>)` : `![${alt}](${decoded})` +const rewriteImageDestination = (url: string) => { + const trimmed = url.trim() + const wrapped = trimmed.startsWith('<') && trimmed.endsWith('>') + const raw = wrapped ? trimmed.slice(1, -1).trim() : trimmed + if (!raw.startsWith('/images/')) return null + let next = `./public/images/${raw.slice('/images/'.length)}` + try { + next = decodeURIComponent(next) + } catch { + // 保留原始编码 + } + return /\s/.test(next) ? `<${next}>` : next +} + +const rewriteTinyProBody = (part: string) => + part + .replace(/!\[([^\]]*)\]\(([^)\n]+)\)/g, (match, alt: string, url: string) => { + const next = rewriteImageDestination(url) + return next ? `![${alt}](${next})` : match }) + .replaceAll('](/quick-start)', '](/tiny-pro/guide/quick-start)') + +function transformTinyProMarkdown(src: string) { + return mapOutsideFences(src, (part) => rewriteTinyProBody(convertHtmlHeadings(part))) +} + +type MarkdownToken = { + attrs?: [string, string][] | null + children?: MarkdownToken[] | null +} -function transformVueProMarkdown(src: string) { - return rewriteVueProUrls(mapOutsideFences(src, convertHtmlHeadings)) +const stripHeadingAttrFromLabel = (tokens: MarkdownToken[]) => { + for (const token of tokens) { + for (const attr of token.attrs || []) { + // 锚点文案在解析时就已经写进 aria-label,这里只清掉 {#id} + if (attr[0] === 'aria-label') attr[1] = attr[1].replace(/ \{#[^{}]+\}/g, '') + } + if (token.children?.length) stripHeadingAttrFromLabel(token.children) + } } export function tinyproDocsPlugin(md: { parse: (src: string, env: Record) => unknown }) { @@ -76,7 +98,9 @@ export function tinyproDocsPlugin(md: { parse: (src: string, env: Record) => { // VitePress 会把 env.path 改成重写后的 tiny-pro/guide/*.md,源文件在 realPath const filePath = String(env?.realPath || env?.path || '') - const next = isVueProDoc(filePath) ? transformVueProMarkdown(src) : src - return parse(next, env) + if (!isTinyProDoc(filePath)) return parse(src, env) + const tokens = parse(transformTinyProMarkdown(src), env) + if (Array.isArray(tokens)) stripHeadingAttrFromLabel(tokens) + return tokens } } diff --git a/opentiny.design b/opentiny.design deleted file mode 160000 index 96a54b7..0000000 --- a/opentiny.design +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 96a54b75198d9dd03445bafc86f25edf0ae9e761 diff --git a/tiny-pro b/tiny-pro new file mode 160000 index 0000000..442562d --- /dev/null +++ b/tiny-pro @@ -0,0 +1 @@ +Subproject commit 442562d4e60e25cc1ecb8527808f4228703eb30b