Skip to content

Commit 3ba2340

Browse files
committed
refactor(docs): move page config to dedicated files
1 parent e3ce047 commit 3ba2340

7 files changed

Lines changed: 117 additions & 103 deletions

File tree

docs/.vuepress/config.js

Lines changed: 14 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
1-
const anchorPlugin = require('markdown-it-anchor')
21
const { viteBundler } = require('@vuepress/bundler-vite');
3-
const { shikiPlugin } = require('@vuepress/plugin-shiki')
4-
const { sitemapPlugin } = require('vuepress-plugin-sitemap2')
52

63
const defaultTheme = require('./theme')
7-
const { path } = require('@vuepress/utils')
8-
const { version } = require('../../package.json')
94

10-
// eslint-disable-next-line no-control-regex
11-
const rControl = /[\u0000-\u001f]/g
12-
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g
13-
const rCombining = /[\u0300-\u036F]/g
14-
15-
const slugify = (str) => {
16-
return str
17-
.normalize('NFKD')
18-
// Remove accents
19-
.replace(rCombining, '')
20-
// Remove control characters
21-
.replace(rControl, '')
22-
// Replace special characters
23-
.replace(rSpecial, '-')
24-
// Remove continuos separators
25-
.replace(/-{2,}/g, '-')
26-
// Remove prefixing and trailing separators
27-
.replace(/^-+|-+$/g, '')
28-
// ensure it doesn't start with a number (#121)
29-
.replace(/^(\d)/, '_$1')
30-
// lowercase
31-
.toLowerCase()
32-
}
5+
const clientAppEnhanceFiles = require('./configs/client-app-enhance-files')
6+
const head = require('./configs/head')
7+
const extendsMarkdown = require('./configs/extends-markdown')
8+
const markdown = require('./configs/markdown')
9+
const navbar = require('./configs/navbar')
10+
const sidebar = require('./configs/sidebar')
11+
const plugins = require('./configs/plugins')
3312

3413
module.exports = {
35-
// site config
3614
lang: 'en-US',
3715
title: 'discue',
3816
description: 'Developer documentation for the secure and reliable messaging and queueing service.',
@@ -48,80 +26,13 @@ module.exports = {
4826
repo: 'discue/discue-io-docs',
4927
repoLabel: 'GitHub',
5028
sidebarDepth: 4,
51-
navbar: [{
52-
text: 'Getting Started',
53-
link: '/getting-started/',
54-
}, {
55-
text: 'API Overview',
56-
link: '/api-overview/',
57-
}, {
58-
text: 'API Reference',
59-
link: '/api-reference/',
60-
{
61-
text: `v${version}`,
62-
children: [
63-
{
64-
text: 'Changelog',
65-
link: 'https://github.com/discue/ui-components/blob/main/CHANGELOG.md',
66-
},
67-
],
68-
}],
69-
sidebar: [{
70-
text: 'Introduction',
71-
link: '/introduction/',
72-
}, {
73-
text: 'Getting Started',
74-
link: '/getting-started/',
75-
}, {
76-
text: 'API Overview',
77-
link: '/api-overview/',
78-
}, {
79-
text: 'API Best Practices',
80-
link: '/api-best-practices/',
81-
}, {
82-
text: 'API Reference',
83-
link: '/api-reference/',
84-
}],
29+
navbar,
30+
sidebar
8531
},
8632
),
87-
plugins: [
88-
["@vuepress/plugin-prismjs", false],
89-
sitemapPlugin({
90-
hostname: 'https://docs.discue.io',
91-
excludeUrls: [
92-
'https://docs.discue.io/api-reference/'
93-
]
94-
}),
95-
shikiPlugin({ theme: 'dark-plus' })
96-
],
97-
clientAppEnhanceFiles: path.resolve(
98-
__dirname,
99-
'./enhance/clientAppEnhance.js'
100-
),
101-
extendsMarkdown: (md) => {
102-
md.use(require('markdown-it-attrs'), {
103-
allowedAttributes: ['id'],
104-
leftDelimiter: '[',
105-
rightDelimiter: ']',
106-
})
107-
md.use(anchorPlugin, {
108-
level: [1, 2, 3, 4, 5, 6],
109-
slugify,
110-
permalink: anchorPlugin.permalink.ariaHidden({
111-
class: 'header-anchor',
112-
symbol: '#',
113-
space: true,
114-
placement: 'before',
115-
}),
116-
})
117-
},
118-
markdown: {
119-
extractHeaders: { level: [2, 3, 4, 5, 6] },
120-
anchor: false
121-
},
122-
head: [
123-
['link', { rel: 'icon', type: "image/png", sizes: "16x16", href: "/icons-fire-all-black/web/favicon.ico" }],
124-
['link', { rel: 'icon', type: "image/png", sizes: "32x32", href: "/icons-fire-all-black/web/favicon.ico" }],
125-
['link', { rel: "apple-touch-icon", sizes: "152x152", href: "/icons-fire-all-black/web/apple-touch-icon-152x152.png" }]
126-
],
33+
plugins,
34+
clientAppEnhanceFiles,
35+
extendsMarkdown,
36+
markdown,
37+
head,
12738
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { path } = require('@vuepress/utils')
2+
3+
module.exports = path.resolve(
4+
__dirname,
5+
'../enhance/clientAppEnhance.js'
6+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const anchorPlugin = require('markdown-it-anchor')
2+
3+
// eslint-disable-next-line no-control-regex
4+
const rControl = /[\u0000-\u001f]/g
5+
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g
6+
const rCombining = /[\u0300-\u036F]/g
7+
8+
const slugify = (str) => {
9+
return str
10+
.normalize('NFKD')
11+
// Remove accents
12+
.replace(rCombining, '')
13+
// Remove control characters
14+
.replace(rControl, '')
15+
// Replace special characters
16+
.replace(rSpecial, '-')
17+
// Remove continuos separators
18+
.replace(/-{2,}/g, '-')
19+
// Remove prefixing and trailing separators
20+
.replace(/^-+|-+$/g, '')
21+
// ensure it doesn't start with a number (#121)
22+
.replace(/^(\d)/, '_$1')
23+
// lowercase
24+
.toLowerCase()
25+
}
26+
27+
module.exports = (md) => {
28+
md.use(require('markdown-it-attrs'), {
29+
allowedAttributes: ['id'],
30+
leftDelimiter: '[',
31+
rightDelimiter: ']',
32+
})
33+
md.use(anchorPlugin, {
34+
level: [1, 2, 3, 4, 5, 6],
35+
slugify,
36+
permalink: anchorPlugin.permalink.ariaHidden({
37+
class: 'header-anchor',
38+
symbol: '#',
39+
space: true,
40+
placement: 'before',
41+
}),
42+
})
43+
}

docs/.vuepress/configs/head.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = [
2+
['link', { rel: 'icon', type: "image/png", sizes: "16x16", href: "/icons-fire-all-black/web/favicon.ico" }],
3+
['link', { rel: 'icon', type: "image/png", sizes: "32x32", href: "/icons-fire-all-black/web/favicon.ico" }],
4+
['link', { rel: "apple-touch-icon", sizes: "152x152", href: "/icons-fire-all-black/web/apple-touch-icon-152x152.png" }]
5+
]

docs/.vuepress/configs/markdown.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
extractHeaders: { level: [2, 3, 4, 5, 6] },
3+
anchor: false
4+
}

docs/.vuepress/configs/navbar.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const { version } = require('../../../package.json')
2+
3+
module.exports = [{
4+
text: 'Getting Started',
5+
link: '/getting-started/',
6+
}, {
7+
text: 'API',
8+
children: [
9+
{
10+
text: 'Overview',
11+
link: '/api-overview/',
12+
},
13+
{
14+
text: 'API Best Practices',
15+
link: '/api-best-practices/',
16+
},
17+
{
18+
text: 'API Reference',
19+
link: '/api-reference/',
20+
}
21+
]
22+
},
23+
{
24+
text: `v${version}`,
25+
children: [
26+
{
27+
text: 'Changelog',
28+
link: 'https://github.com/discue/ui-components/blob/main/CHANGELOG.md',
29+
},
30+
],
31+
}]

docs/.vuepress/configs/plugins.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { shikiPlugin } = require('@vuepress/plugin-shiki')
2+
const { sitemapPlugin } = require('vuepress-plugin-sitemap2')
3+
const { 'default': prismPlugin } = require('@vuepress/plugin-prismjs')
4+
5+
module.exports = [
6+
prismPlugin(false),
7+
sitemapPlugin({
8+
hostname: 'https://docs.discue.io',
9+
excludeUrls: [
10+
'https://docs.discue.io/api-reference/'
11+
]
12+
}),
13+
shikiPlugin({ theme: 'dark-plus' })
14+
]

0 commit comments

Comments
 (0)