Skip to content

Commit 2e62d67

Browse files
committed
fix: 🐞 修复 Demo 容器引用的组件没有打包被打包,修复浏览器无法回退上一页问题,主题版权链接更改为 GitHub 地址
1 parent 4f2c9c2 commit 2e62d67

File tree

12 files changed

+27
-33
lines changed

12 files changed

+27
-33
lines changed

docs/01.指南/10.使用/05.Markdown 拓展.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -660,4 +660,8 @@ Demo 容器默认在项目根目录的 `examples` 目录下寻找 `button-demo.v
660660
│ ├─ button-demo.vue
661661
```
662662

663-
如果您需要更改 `examples` 目录,请查看 [插件配置](/reference/plugin-config#demo)
663+
::: tip
664+
暂不支持通过配置项更改 `examples` 为其他目录。
665+
:::
666+
667+
Demo 容器的更多配置请查看 [Demo 容器](/reference/plugin-config#demo)

docs/01.指南/20.相关/15.笔记技巧.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ Demo 容器默认在项目根目录的 `examples` 目录下寻找 `button-demo.v
307307
│ ├─ button-demo.vue
308308
```
309309

310-
如果您需要更改 `examples` 目录,请查看 [插件配置](/reference/plugin-config#demo)。
311-
312310
## 自定义容器
313311

314312
自定义容器可以通过它们的类型、标题和内容来定义。
@@ -407,7 +405,7 @@ Markdown 拓展
407405
::: details 点我查看代码
408406

409407
```js
410-
console.log("Hello, VitePress!");
408+
console.log("Hello, Vitepress!");
411409
```
412410

413411
:::

docs/10.配置/01.主题配置/40.插件配置.md

-7
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ import { defineTeekConfig } from "vitepress-theme-teek/config";
344344
const teekConfig = defineTeekConfig({
345345
markdown: {
346346
demo: {
347-
path: "examples", // Demo 组件路径,基于 .vitepress 目录层级添加
348347
playgroundUrl: "", // Playground 链接
349348
playgroundMainFileName: "App.vue", // Playground 主文件名
350349
githubUrl: "", // Github 链接
@@ -364,12 +363,6 @@ interface Markdown {
364363
* demo 插件配置
365364
*/
366365
demo?: {
367-
/**
368-
* Demo 组件路径,基于 .vitepress 目录层级添加
369-
*
370-
* @default 'examples'
371-
*/
372-
path?: string;
373366
/**
374367
* Playground 链接
375368
*/

docs/examples/button-demo.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts" name="Demo1"></script>
22

33
<template>
4-
<button class="tk-button">primary</button>
4+
<button class="tk-button">primary1234</button>
55
</template>
66

77
<style lang="scss" scoped>

plugins/vitepress-plugin-permalink/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# vitepress-plugin-permalink
22

3+
## 1.0.16
4+
5+
### Patch Changes
6+
7+
- 修复跳转 permalink 后无法回退问题
8+
39
## 1.0.15
410

511
### Patch Changes

plugins/vitepress-plugin-permalink/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vitepress-plugin-permalink",
33
"type": "module",
4-
"version": "1.0.15",
4+
"version": "1.0.16",
55
"description": "扫描 Markdown 文档,生成永久链接",
66
"author": {
77
"name": "teeker",

plugins/vitepress-plugin-permalink/src/usePermalink.ts

-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ export default function usePermalink() {
117117

118118
if (filePath) {
119119
const targetUrl = base + filePath + search + hash;
120-
// router.go 前清除当前历史记录,防止 router.go 后浏览器返回时回到当前历史记录时,又重定向过去,如此反复循环
121-
history.replaceState(history.state || null, "", targetUrl);
122120
router.go(targetUrl);
123121

124122
// 阻止本次路由跳转

vitepress-theme-teek/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"vitepress-plugin-doc-analysis": "^1.0.10",
5252
"vitepress-plugin-file-content-loader": "^1.0.9",
5353
"vitepress-plugin-md-h1": "^1.0.8",
54-
"vitepress-plugin-permalink": "^1.0.15",
54+
"vitepress-plugin-permalink": "^1.0.16",
5555
"vitepress-plugin-sidebar-resolve": "^1.0.8"
5656
},
5757
"devDependencies": {

vitepress-theme-teek/src/components/DemoCode/src/index.vue

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Icon from "../../Icon";
77
import TransitionCollapse from "../../TransitionCollapse";
88
import type { DemoCodeProps } from "./demoCode";
99
import { playgroundIcon, githubIcon, copyIcon, codeIcon, caretTopIcon } from "../../../assets/icons";
10+
import { cs } from "element-plus/es/locale";
1011
1112
defineOptions({ name: "DemoCode" });
1213
@@ -31,13 +32,15 @@ const decodeSource = computed(() => decodeURIComponent(props.source));
3132
const decodeRawSource = computed(() => decodeURIComponent(props.rawSource));
3233
const decodedDescription = computed(() => decodeURIComponent(props.description));
3334
35+
// 预加载 Demo 组件,防止 Vitepress 打包时不包含 Demo 组件
36+
const moduleFiles = (import.meta as any).glob("/examples/**/*.vue", { eager: true });
37+
3438
const DemoComponent = defineAsyncComponent(async () => {
3539
try {
36-
// / 表示从 .vitepress 目录层级开始
37-
return await import(/* @vite-ignore */ withBase(`/${props.path}`));
40+
const key = Object.keys(moduleFiles).find(i => i.endsWith(`/${props.path}`)) as string;
41+
return moduleFiles[key];
3842
} catch (error) {
39-
console.error(`[Teek Error] Failed to load component: '${props.path}'`, error);
40-
return null;
43+
console.error(`[Teek Error] Failed to load component: '/${props.path}'`, error);
4144
}
4245
});
4346

vitepress-theme-teek/src/components/Footer/src/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const footerData = computed(() => {
2525
data.push({
2626
name: "Theme By Teek",
2727
icon: themeIcon,
28-
link: "http://vp.teek.top/",
28+
link: "https://github.com/Kele-Bingtang/vitepress-theme-teek",
2929
// 可覆盖上面的配置项
3030
...theme,
3131
});

vitepress-theme-teek/src/config/types/markdown.ts

-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ export interface Markdown {
2626
}
2727

2828
export interface Demo {
29-
/**
30-
* Demo 组件路径,基于 .vitepress 目录层级添加
31-
*
32-
* @default 'examples'
33-
*/
34-
path?: string;
3529
/**
3630
* Playground 链接
3731
*/

vitepress-theme-teek/src/markdown/plugins/demo.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Renderer, Token } from "markdown-it";
33
import type { SiteConfig } from "vitepress";
44
import container from "markdown-it-container";
55
import { readFileSync } from "fs";
6-
import { join, resolve, normalize } from "path";
6+
import { join, resolve, posix } from "path";
77
import type { Demo } from "../../config";
88

99
interface ContainerOpts {
@@ -13,11 +13,10 @@ interface ContainerOpts {
1313
}
1414

1515
const demoPlugin = (md: MarkdownIt, option: Demo = {}) => {
16-
console.log(option);
1716
const siteConfig: SiteConfig = (globalThis as any).VITEPRESS_CONFIG;
1817
const srcDir = siteConfig.srcDir;
19-
const { path = "examples" } = option;
20-
const demoPath = join(srcDir, path || "");
18+
const path = "examples";
19+
const demoPath = join(srcDir, path);
2120

2221
const options: ContainerOpts = {
2322
validate(params) {
@@ -34,7 +33,6 @@ const demoPlugin = (md: MarkdownIt, option: Demo = {}) => {
3433
const containerContent = sourceFileToken.children?.[0].content ?? "";
3534
// 确保文件路径带 .vue
3635
const sourceFile = containerContent ? `${containerContent.replace(/.vue$/, "")}.vue` : "";
37-
const sourceRelativeFile = normalize(join(path, sourceFile));
3836

3937
if (sourceFile && sourceFileToken.type === "inline") {
4038
source = readFileSync(resolve(demoPath, sourceFile), "utf-8");
@@ -43,7 +41,7 @@ const demoPlugin = (md: MarkdownIt, option: Demo = {}) => {
4341

4442
return `<TkDemoCode source="${encodeURIComponent(
4543
md.render(`\`\`\` vue\n${source}\`\`\``)
46-
)}" path="${sourceRelativeFile}" raw-source="${encodeURIComponent(
44+
)}" path="${posix.join(path, sourceFile)}" raw-source="${encodeURIComponent(
4745
source
4846
)}" description="${encodeURIComponent(md.render(description))}" demo="${encodeURIComponent(JSON.stringify(option))}">`;
4947
} else return "</TkDemoCode>";

0 commit comments

Comments
 (0)