Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf9d7bd

Browse files
committed
Dedupe html & fix doc site previews
- Create template for generating multiple `index.html` files (root and `/docs/`) - Add nunjucks dependency - Append β€œ(Preview)” to document title for easier identification of local preview tabs/windows (preview only) - Add custom plugin to fix preview paths to `/docs` resources in markdown (preview only) - Add front-matter plugin to `/docs/index.html` (missing in previous file, required for front-matter demo in docs) - Add β€œbuild:html” npm script - Fix preview paths to `/docs` resources in `index.html` files (preview only) - Remove β€œPowered by docsify” from footer - Remove β€œVercel has given us a Pro account” from footer (acknowledgement provided via the β€œSpecial Thanks” section in README) - Move β€œEdit Document” link from top-left to bottom-right of page - Refactor package.json script (reorder) - Refactor `.eslintignore` file (reorder and remove duplicate entries)
1 parent 43a73bb commit bf9d7bd

File tree

8 files changed

+595
-334
lines changed

8 files changed

+595
-334
lines changed

β€Ž.eslintignore

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
.git
2-
packages/docsify-server-renderer/build.js
3-
node_modules
2+
**/*.md
43
build
5-
server.js
4+
docs
65
lib
6+
node_modules
7+
packages/docsify-server-renderer/build.js
8+
server.js
79
themes
8-
build
9-
docs/
10-
**/*.md

β€Žbuild/html.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const fs = require('fs');
2+
const nunjucks = require('nunjucks');
3+
const path = require('path');
4+
const prettier = require('prettier');
5+
6+
const renderJobs = [
7+
// Preview index.html
8+
{
9+
isProduction: false,
10+
inputPath: path.resolve(__dirname, '../src/html/index.njk'),
11+
outputPath: path.resolve(__dirname, '../index.html'),
12+
},
13+
// Production index.html
14+
{
15+
isProduction: true,
16+
inputPath: path.resolve(__dirname, '../src/html/index.njk'),
17+
outputPath: path.resolve(__dirname, '../docs/index.html'),
18+
},
19+
];
20+
21+
for (const job of renderJobs) {
22+
console.log(`[Build HTML] ${job.outputPath}`);
23+
24+
const template = fs.readFileSync(job.inputPath, 'utf8').toString();
25+
const html = nunjucks.renderString(template, job);
26+
const htmlFormatted = prettier.format(html, { parser: 'html' });
27+
28+
fs.writeFileSync(job.outputPath, htmlFormatted);
29+
}

β€Ždocs/helpers.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,29 @@ Only when you both set the `routerMode: 'history'` and `externalLinkTarget: '_se
9696
### Resizing
9797

9898
```md
99-
![logo](https://docsify.js.org/_media/icon.svg ':size=WIDTHxHEIGHT')
100-
![logo](https://docsify.js.org/_media/icon.svg ':size=50x100')
101-
![logo](https://docsify.js.org/_media/icon.svg ':size=100')
99+
![logo](_media/icon.svg ':size=WIDTHxHEIGHT')
100+
![logo](_media/icon.svg ':size=50x100')
101+
![logo](_media/icon.svg ':size=100')
102102

103103
<!-- Support percentage -->
104104

105-
![logo](https://docsify.js.org/_media/icon.svg ':size=10%')
105+
![logo](_media/icon.svg ':size=10%')
106106
```
107107

108-
![logo](https://docsify.js.org/_media/icon.svg ':size=50x100')
109-
![logo](https://docsify.js.org/_media/icon.svg ':size=100')
110-
![logo](https://docsify.js.org/_media/icon.svg ':size=10%')
108+
![logo](_media/icon.svg ':size=50x100')
109+
![logo](_media/icon.svg ':size=100')
110+
![logo](_media/icon.svg ':size=10%')
111111

112112
### Customise class
113113

114114
```md
115-
![logo](https://docsify.js.org/_media/icon.svg ':class=someCssClass')
115+
![logo](_media/icon.svg ':class=someCssClass')
116116
```
117117

118118
### Customise ID
119119

120120
```md
121-
![logo](https://docsify.js.org/_media/icon.svg ':id=someCssId')
121+
![logo](_media/icon.svg ':id=someCssId')
122122
```
123123

124124
## Customise ID for headings

β€Ždocs/index.html

Lines changed: 93 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -45,87 +45,70 @@
4545
nav.app-nav li ul {
4646
min-width: 100px;
4747
}
48-
48+
</style>
49+
<style>
4950
#carbonads {
5051
box-shadow: none !important;
5152
width: auto !important;
5253
}
5354
</style>
5455
</head>
55-
5656
<body>
5757
<div id="app">Loading ...</div>
5858
<script>
5959
window.$docsify = {
60-
alias: {
61-
'.*?/awesome':
62-
'https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md',
63-
'.*?/changelog':
64-
'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG.md',
65-
'/.*/_navbar.md': '/_navbar.md',
66-
'/zh-cn/(.*)':
67-
'https://raw.githubusercontent.com/docsifyjs/docs-zh/master/$1',
68-
'/de-de/(.*)':
69-
'https://raw.githubusercontent.com/docsifyjs/docs-de/master/$1',
70-
'/ru-ru/(.*)':
71-
'https://raw.githubusercontent.com/docsifyjs/docs-ru/master/$1',
72-
'/es/(.*)':
73-
'https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1',
74-
'/write-a-plugin':
75-
'https://raw.githubusercontent.com/docsifyjs/docsify/master/docs/write-a-plugin.md',
76-
},
60+
name: "docsify",
61+
// repo: 'docsifyjs/docsify',
7762
auto2top: true,
7863
coverpage: true,
7964
executeScript: true,
80-
loadSidebar: true,
65+
// Navigation
66+
alias: {
67+
".*?/awesome":
68+
"https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md",
69+
".*?/changelog":
70+
"https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG.md",
71+
"/.*/_navbar.md": "/_navbar.md",
72+
"/zh-cn/(.*)":
73+
"https://raw.githubusercontent.com/docsifyjs/docs-zh/master/$1",
74+
"/de-de/(.*)":
75+
"https://raw.githubusercontent.com/docsifyjs/docs-de/master/$1",
76+
"/ru-ru/(.*)":
77+
"https://raw.githubusercontent.com/docsifyjs/docs-ru/master/$1",
78+
"/es/(.*)":
79+
"https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1",
80+
"/write-a-plugin":
81+
"https://raw.githubusercontent.com/docsifyjs/docsify/master/docs/write-a-plugin.md"
82+
},
8183
loadNavbar: true,
82-
mergeNavbar: true,
84+
loadSidebar: true,
8385
maxLevel: 4,
86+
mergeNavbar: true,
8487
subMaxLevel: 2,
85-
ga: 'UA-106147152-1',
86-
matomo: {
87-
host: '//matomo.thunderwave.de',
88-
id: 6,
89-
},
90-
name: 'docsify',
91-
search: {
92-
noData: {
93-
'/de-de/': 'Keine Ergebnisse!',
94-
'/zh-cn/': 'ζ²‘ζœ‰η»“ζžœ!',
95-
'/': 'No results!',
96-
},
97-
paths: 'auto',
98-
placeholder: {
99-
'/de-de/': 'Suche',
100-
'/zh-cn/': '搜紒',
101-
'/': 'Search',
102-
},
103-
},
88+
// Vue
89+
10490
vueComponents: {
105-
'button-counter': {
106-
template: `
107-
<button @click="count += 1">
108-
You clicked me {{ count }} times
109-
</button>
110-
`,
91+
"button-counter": {
92+
template:
93+
'<button @click="count += 1">You clicked me {{ count }} times</button>',
11194
data() {
11295
return {
113-
count: 0,
96+
count: 0
11497
};
115-
},
116-
},
98+
}
99+
}
117100
},
118101
vueGlobalOptions: {
119102
data() {
120103
return {
121104
count: 0,
122-
message: 'Hello, World!',
105+
message: "Hello, World!",
123106
// Fake API response
124107
images: [
125-
{ title: 'Image 1', url: 'https://picsum.photos/150?random=1' },
126-
{ title: 'Image 2', url: 'https://picsum.photos/150?random=2' },
127-
{ title: 'Image 3', url: 'https://picsum.photos/150?random=3' },
128-
],
108+
{ title: "Image 1", url: "https://picsum.photos/150?random=1" },
109+
{ title: "Image 2", url: "https://picsum.photos/150?random=2" },
110+
{ title: "Image 3", url: "https://picsum.photos/150?random=3" }
111+
]
129112
};
130113
},
131114
computed: {
@@ -134,91 +117,95 @@
134117
const hours = date.getHours();
135118

136119
if (hours < 12) {
137-
return 'morning';
120+
return "morning";
138121
} else if (hours < 18) {
139-
return 'afternoon';
122+
return "afternoon";
140123
} else {
141-
return 'evening';
124+
return "evening";
142125
}
143-
},
126+
}
144127
},
145128
methods: {
146129
hello: function() {
147130
alert(this.message);
148-
},
149-
},
131+
}
132+
}
150133
},
151134
vueMounts: {
152-
'#counter': {
135+
"#counter": {
153136
data() {
154137
return {
155-
count: 0,
138+
count: 0
156139
};
157-
},
140+
}
141+
}
142+
},
143+
144+
// Plugins (docsify)
145+
ga: "UA-106147152-1",
146+
matomo: {
147+
host: "//matomo.thunderwave.de",
148+
id: 6
149+
},
150+
search: {
151+
noData: {
152+
"/de-de/": "Keine Ergebnisse!",
153+
"/zh-cn/": "ζ²‘ζœ‰η»“ζžœ!",
154+
"/": "No results!"
158155
},
156+
paths: "auto",
157+
placeholder: {
158+
"/de-de/": "Suche",
159+
"/zh-cn/": "搜紒",
160+
"/": "Search"
161+
}
159162
},
163+
// Plugins (custom)
160164
plugins: [
165+
// Edit Document
161166
function(hook, vm) {
162167
hook.beforeEach(function(html) {
168+
var url =
169+
"https://github.com/docsifyjs/docsify/blob/master/docs/" +
170+
vm.route.file;
171+
163172
if (/githubusercontent\.com/.test(vm.route.file)) {
164173
url = vm.route.file
165-
.replace('raw.githubusercontent.com', 'github.com')
166-
.replace(/\/master/, '/blob/master');
174+
.replace("raw.githubusercontent.com", "github.com")
175+
.replace(/\/master/, "/blob/master");
167176
} else if (/jsdelivr\.net/.test(vm.route.file)) {
168177
url = vm.route.file
169-
.replace('cdn.jsdelivr.net/gh', 'github.com')
170-
.replace('@master', '/blob/master');
171-
} else {
172-
url =
173-
'https://github.com/docsifyjs/docsify/blob/master/docs/' +
174-
vm.route.file;
178+
.replace("cdn.jsdelivr.net/gh", "github.com")
179+
.replace("@master", "/blob/master");
175180
}
176-
var editHtml = '[:memo: Edit Document](' + url + ')\n';
177-
return (
178-
editHtml +
179-
html +
180-
'\n\n----\n\n' +
181-
'<a href="https://docsify.js.org" target="_blank" style="color: inherit; font-weight: normal; text-decoration: none;">Powered by docsify</a>'
182-
);
183-
}),
184-
hook.afterEach(function(html) {
185-
if (vm.route.path === '/') {
186-
return html;
187-
}
188-
return `${html}<br/> <i>Vercel</i> has given us a Pro account <br/> <a href="https://vercel.com/?utm_source=docsifyjsdocs" target="_blank"><img src="_media/vercel_logo.svg" alt="Vercel" width="100" height="64"></a>`;
189-
});
190-
},
191-
],
181+
182+
return [
183+
html,
184+
'<div style="text-align: right;">',
185+
"[:memo: Edit Document](" + url + ")",
186+
"</div>"
187+
].join("\n\n");
188+
});
189+
}
190+
]
192191
};
193192
</script>
194193
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/docsify.min.js"></script>
195194
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/search.min.js"></script>
195+
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/front-matter.js"></script>
196196
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
197197
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-markdown.min.js"></script>
198198
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-nginx.min.js"></script>
199199
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-php.min.js"></script>
200+
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/ga.min.js"></script>
201+
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/matomo.min.js"></script>
200202
<script src="//cdn.jsdelivr.net/npm/docsify-plugin-carbon@1/index.min.js"></script>
201203
<script>
202-
(function() {
203-
function loadJS(src, attrs) {
204-
document.write(
205-
'<script src="' + src + '" ' + (attrs || '') + '><\/script>'
206-
);
207-
}
208-
209-
// Public site only
210-
if (/docsify/.test(location.host)) {
211-
((window.gitter = {}).chat = {}).options = {
212-
room: 'docsifyjs/Lobby',
213-
};
214-
215-
loadJS('//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/ga.min.js');
216-
loadJS('//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/matomo.min.js');
217-
loadJS('//sidecar.gitter.im/dist/sidecar.v1.js', 'async defer');
218-
}
219-
})();
204+
((window.gitter = {}).chat = {}).options = {
205+
room: "docsifyjs/Lobby"
206+
};
220207
</script>
208+
<script src="//sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>
221209
<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script>
222-
<!-- <script src="//cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script> -->
223210
</body>
224211
</html>

0 commit comments

Comments
Β (0)