-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ab901e
commit 41ac6b4
Showing
6 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ permalink: /article/5xbhl125/ | |
|
||
```json | ||
{ | ||
"jsLib": [], | ||
"cssLib": [] | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import type { App } from 'vuepress' | ||
import type { Markdown } from 'vuepress/markdown' | ||
import { demoContainer, demoEmbed } from './demo.js' | ||
import { createDemoRender } from './watcher.js' | ||
|
||
export function demoPlugin(app: App, md: Markdown) { | ||
createDemoRender() | ||
demoEmbed(app, md) | ||
demoContainer(app, md) | ||
} | ||
|
||
export * from './extendPage.js' | ||
export * from './watcher.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* 消除异步编译 demo 代码 与 markdown 同步 render 的时间差问题 | ||
* 确保 在 vuepress onPrepared 阶段完成所有 demo 代码的编译与输出 | ||
*/ | ||
let renderDone: null | ((...args: any[]) => void) = null | ||
let renderCount = 0 | ||
let renderPromise!: Promise<void> | ||
|
||
export function createDemoRender() { | ||
renderPromise = new Promise((resolve) => { | ||
renderDone = resolve | ||
}) | ||
} | ||
|
||
export async function waitDemoRender() { | ||
if (renderCount === 0) { | ||
renderDone?.() | ||
renderDone = null | ||
} | ||
await renderPromise | ||
} | ||
|
||
export function markDemoRender() { | ||
renderCount++ | ||
} | ||
|
||
export function checkDemoRender() { | ||
if (renderCount > 0) { | ||
renderCount-- | ||
} | ||
if (renderCount === 0) { | ||
renderDone?.() | ||
renderDone = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters