Skip to content

Commit ddd3d9c

Browse files
authored
Merge pull request #28 from djyde/dev
docisify doc
2 parents e0eeed1 + 161e29b commit ddd3d9c

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

public/doc/_sidebar.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- **Self-host Guide**
55
- [Docker](/self-host/docker.md)
66
- [Vercel](/self-host/vercel.md)
7+
- **Integration**
8+
- [Docsify](/integration/docsify.md)
79
- **Advanced**
810
- [JS SDK Reference](/advanced/sdk.md)
911
- [**Contributing**](/contributing.md)

public/doc/integration/docsify.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
# Integrate with Docsify
1+
# Integrate with Docsify
2+
3+
[Docsify](https://docsify.js.org) is a powerful document site generator, which also powers this Cusdis document. Cusdis has a built-in Docsify plugin.
4+
5+
## Usage
6+
7+
```html
8+
<script>
9+
window.$docsify = {
10+
cusdis: {
11+
host: 'https://cusdis.com', // change the host if you are using self-hosted Cusdis
12+
appId: 'xxxx',
13+
},
14+
}
15+
</script>
16+
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
17+
<script src="https://cusdis.com/js/cusdis.docsify.js"></script> <!-- change the host if you are using self-hosted Cusdis -->
18+
19+
```
20+
21+

public/js/cusdis.docsify.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
function CusdisPlugin(hook, vm) {
2-
window.cusdisTag = 'cusdis_thread'
1+
window.CUSDIS_PREVENT_INITIAL_RENDER = true
32

3+
function CusdisPlugin(hook, vm) {
44
const config = vm.config.cusdis
55

6-
const { appId, host } = config;
6+
const { appId, host } = config
77

88
const dom = Docsify.dom
99

10-
hook.init(_ => {
11-
const script = dom.create("script");
12-
script.async = true;
10+
hook.init((_) => {
11+
const script = dom.create('script')
12+
script.async = true
1313
// script.src = `http://localhost:3000/js/cusdis.es.js`;
14-
script.src = `${host}/js/cusdis.es.js`;
15-
script.setAttribute("data-timestamp", Number(new Date()));
16-
dom.appendTo(dom.body, script);
14+
script.src = `${host}/js/cusdis.es.js`
15+
script.setAttribute('data-timestamp', Number(new Date()))
16+
dom.appendTo(dom.body, script)
1717
})
1818

1919
function createCusdis() {
@@ -29,8 +29,9 @@ function CusdisPlugin(hook, vm) {
2929
hook.doneEach(() => {
3030
const cusdis = createCusdis()
3131
dom.find('#main').append(cusdis)
32-
window.renderCusdis(cusdis);
32+
// TODO: waiting for script loaded
33+
window.renderCusdis(cusdis)
3334
})
3435
}
3536

36-
window.$docsify.plugins = (window.$docsify.plugins || []).concat(CusdisPlugin);
37+
window.$docsify.plugins = (window.$docsify.plugins || []).concat(CusdisPlugin)

widget/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ if (window.cusdisElementId) {
2525
target = document.querySelector("#cusdis");
2626
}
2727

28-
if (target) {
29-
render(target);
30-
}
28+
if (window.CUSDIS_PREVENT_INITIAL_RENDER === true) {
29+
30+
} else {
31+
if (target) {
32+
render(target)
33+
}
34+
}

0 commit comments

Comments
 (0)