Skip to content
Open
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
3 changes: 1 addition & 2 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-obs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- 'next-sdk/docs/**'
- 'tiny-robot/docs/**'
- 'tiny-vue/examples/sites/demos/pc/webdoc/**'
- 'tiny-pro'
- '.vitepress/**'

workflow_dispatch:
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 16 additions & 26 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
]
}
]
Expand Down Expand Up @@ -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' }]],
Expand All @@ -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: {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions .vitepress/theme/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
];

Expand Down
62 changes: 43 additions & 19 deletions .vitepress/theme/markdown/tinypro-docs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* 子模块里的 TinyPro 文档沿用 opentiny.design 的写法。
* TinyPro 文档来自 tiny-pro 仓库的 docs 目录,图片在 docs/public/images。
* 这里只在渲染时改链接、图片路径和 HTML 标题,不复制源文件。
*/

Expand All @@ -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
Expand All @@ -37,9 +37,7 @@ const mapOutsideFences = (src: string, transform: (part: string) => string) => {

const inlineHeading = (inner: string) =>
inner
.replace(/<a\s+[^>]*href\s*=\s*['"]([^'"]+)['"][^>]*>([\s\S]*?)<\/a>/gi, '[$2]($1)')
.replace(/<code>([\s\S]*?)<\/code>/gi, '`$1`')
.replace(/<br\s*\/?>/gi, ' ')
.replace(/<[^>]+>/g, '')
.replace(/\s+/g, ' ')
.trim()
Expand All @@ -54,29 +52,55 @@ 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<string, unknown>) => unknown }) {
const parse = md.parse.bind(md)
md.parse = (src: string, env: Record<string, unknown>) => {
// 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
}
}
1 change: 0 additions & 1 deletion opentiny.design
Submodule opentiny.design deleted from 96a54b
1 change: 1 addition & 0 deletions tiny-pro
Submodule tiny-pro added at 442562
Loading