Skip to content

Commit

Permalink
refactor(docs): move page config to dedicated files
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed May 15, 2022
1 parent e3ce047 commit 3ba2340
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 103 deletions.
117 changes: 14 additions & 103 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
const anchorPlugin = require('markdown-it-anchor')
const { viteBundler } = require('@vuepress/bundler-vite');
const { shikiPlugin } = require('@vuepress/plugin-shiki')
const { sitemapPlugin } = require('vuepress-plugin-sitemap2')

const defaultTheme = require('./theme')
const { path } = require('@vuepress/utils')
const { version } = require('../../package.json')

// eslint-disable-next-line no-control-regex
const rControl = /[\u0000-\u001f]/g
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g
const rCombining = /[\u0300-\u036F]/g

const slugify = (str) => {
return str
.normalize('NFKD')
// Remove accents
.replace(rCombining, '')
// Remove control characters
.replace(rControl, '')
// Replace special characters
.replace(rSpecial, '-')
// Remove continuos separators
.replace(/-{2,}/g, '-')
// Remove prefixing and trailing separators
.replace(/^-+|-+$/g, '')
// ensure it doesn't start with a number (#121)
.replace(/^(\d)/, '_$1')
// lowercase
.toLowerCase()
}
const clientAppEnhanceFiles = require('./configs/client-app-enhance-files')
const head = require('./configs/head')
const extendsMarkdown = require('./configs/extends-markdown')
const markdown = require('./configs/markdown')
const navbar = require('./configs/navbar')
const sidebar = require('./configs/sidebar')
const plugins = require('./configs/plugins')

module.exports = {
// site config
lang: 'en-US',
title: 'discue',
description: 'Developer documentation for the secure and reliable messaging and queueing service.',
Expand All @@ -48,80 +26,13 @@ module.exports = {
repo: 'discue/discue-io-docs',
repoLabel: 'GitHub',
sidebarDepth: 4,
navbar: [{
text: 'Getting Started',
link: '/getting-started/',
}, {
text: 'API Overview',
link: '/api-overview/',
}, {
text: 'API Reference',
link: '/api-reference/',
{
text: `v${version}`,
children: [
{
text: 'Changelog',
link: 'https://github.com/discue/ui-components/blob/main/CHANGELOG.md',
},
],
}],
sidebar: [{
text: 'Introduction',
link: '/introduction/',
}, {
text: 'Getting Started',
link: '/getting-started/',
}, {
text: 'API Overview',
link: '/api-overview/',
}, {
text: 'API Best Practices',
link: '/api-best-practices/',
}, {
text: 'API Reference',
link: '/api-reference/',
}],
navbar,
sidebar
},
),
plugins: [
["@vuepress/plugin-prismjs", false],
sitemapPlugin({
hostname: 'https://docs.discue.io',
excludeUrls: [
'https://docs.discue.io/api-reference/'
]
}),
shikiPlugin({ theme: 'dark-plus' })
],
clientAppEnhanceFiles: path.resolve(
__dirname,
'./enhance/clientAppEnhance.js'
),
extendsMarkdown: (md) => {
md.use(require('markdown-it-attrs'), {
allowedAttributes: ['id'],
leftDelimiter: '[',
rightDelimiter: ']',
})
md.use(anchorPlugin, {
level: [1, 2, 3, 4, 5, 6],
slugify,
permalink: anchorPlugin.permalink.ariaHidden({
class: 'header-anchor',
symbol: '#',
space: true,
placement: 'before',
}),
})
},
markdown: {
extractHeaders: { level: [2, 3, 4, 5, 6] },
anchor: false
},
head: [
['link', { rel: 'icon', type: "image/png", sizes: "16x16", href: "/icons-fire-all-black/web/favicon.ico" }],
['link', { rel: 'icon', type: "image/png", sizes: "32x32", href: "/icons-fire-all-black/web/favicon.ico" }],
['link', { rel: "apple-touch-icon", sizes: "152x152", href: "/icons-fire-all-black/web/apple-touch-icon-152x152.png" }]
],
plugins,
clientAppEnhanceFiles,
extendsMarkdown,
markdown,
head,
}
6 changes: 6 additions & 0 deletions docs/.vuepress/configs/client-app-enhance-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { path } = require('@vuepress/utils')

module.exports = path.resolve(
__dirname,
'../enhance/clientAppEnhance.js'
)
43 changes: 43 additions & 0 deletions docs/.vuepress/configs/extends-markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const anchorPlugin = require('markdown-it-anchor')

// eslint-disable-next-line no-control-regex
const rControl = /[\u0000-\u001f]/g
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g
const rCombining = /[\u0300-\u036F]/g

const slugify = (str) => {
return str
.normalize('NFKD')
// Remove accents
.replace(rCombining, '')
// Remove control characters
.replace(rControl, '')
// Replace special characters
.replace(rSpecial, '-')
// Remove continuos separators
.replace(/-{2,}/g, '-')
// Remove prefixing and trailing separators
.replace(/^-+|-+$/g, '')
// ensure it doesn't start with a number (#121)
.replace(/^(\d)/, '_$1')
// lowercase
.toLowerCase()
}

module.exports = (md) => {
md.use(require('markdown-it-attrs'), {
allowedAttributes: ['id'],
leftDelimiter: '[',
rightDelimiter: ']',
})
md.use(anchorPlugin, {
level: [1, 2, 3, 4, 5, 6],
slugify,
permalink: anchorPlugin.permalink.ariaHidden({
class: 'header-anchor',
symbol: '#',
space: true,
placement: 'before',
}),
})
}
5 changes: 5 additions & 0 deletions docs/.vuepress/configs/head.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = [
['link', { rel: 'icon', type: "image/png", sizes: "16x16", href: "/icons-fire-all-black/web/favicon.ico" }],
['link', { rel: 'icon', type: "image/png", sizes: "32x32", href: "/icons-fire-all-black/web/favicon.ico" }],
['link', { rel: "apple-touch-icon", sizes: "152x152", href: "/icons-fire-all-black/web/apple-touch-icon-152x152.png" }]
]
4 changes: 4 additions & 0 deletions docs/.vuepress/configs/markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extractHeaders: { level: [2, 3, 4, 5, 6] },
anchor: false
}
31 changes: 31 additions & 0 deletions docs/.vuepress/configs/navbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { version } = require('../../../package.json')

module.exports = [{
text: 'Getting Started',
link: '/getting-started/',
}, {
text: 'API',
children: [
{
text: 'Overview',
link: '/api-overview/',
},
{
text: 'API Best Practices',
link: '/api-best-practices/',
},
{
text: 'API Reference',
link: '/api-reference/',
}
]
},
{
text: `v${version}`,
children: [
{
text: 'Changelog',
link: 'https://github.com/discue/ui-components/blob/main/CHANGELOG.md',
},
],
}]
14 changes: 14 additions & 0 deletions docs/.vuepress/configs/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { shikiPlugin } = require('@vuepress/plugin-shiki')
const { sitemapPlugin } = require('vuepress-plugin-sitemap2')
const { 'default': prismPlugin } = require('@vuepress/plugin-prismjs')

module.exports = [
prismPlugin(false),
sitemapPlugin({
hostname: 'https://docs.discue.io',
excludeUrls: [
'https://docs.discue.io/api-reference/'
]
}),
shikiPlugin({ theme: 'dark-plus' })
]

0 comments on commit 3ba2340

Please sign in to comment.