chore(v2): generic styling improvements

This commit is contained in:
Yangshun Tay 2019-02-23 12:50:31 -08:00
parent c46a894a01
commit b33de00a32
16 changed files with 109 additions and 109 deletions

View file

@ -17,7 +17,7 @@ module.exports = function createClientConfig(props) {
const config = createBaseConfig(props);
config.entry('main').add(path.resolve(__dirname, '../core/clientEntry.js'));
// remove/clean build folders before building bundles
// Remove/clean build folders before building bundles.
const {outDir} = props;
config
.plugin('clean')
@ -33,7 +33,7 @@ module.exports = function createClientConfig(props) {
{filename: path.join(outDir, 'react-loadable.json')},
]);
// show compilation progress bar and build time
// Show compilation progress bar and build time.
const isProd = process.env.NODE_ENV === 'production';
config
.plugin('niceLog')

View file

@ -26,10 +26,10 @@ module.exports = function(fileString) {
sourceToMetadata,
} = options;
/* Extract content of markdown (without frontmatter) */
// Extract content of markdown (without frontmatter).
const {body} = fm(fileString);
/* Determine the source dir. e.g: /docs, /website/versioned_docs/version-1.0.0 */
// Determine the source dir. e.g: /docs, /website/versioned_docs/version-1.0.0
let sourceDir;
const thisSource = this.resourcePath;
if (thisSource.startsWith(translatedDir)) {
@ -48,7 +48,7 @@ module.exports = function(fileString) {
sourceDir = docsDir;
}
/* Replace internal markdown linking (except in fenced blocks) */
// Replace internal markdown linking (except in fenced blocks).
let content = body;
if (sourceDir) {
let fencedBlock = false;
@ -59,14 +59,13 @@ module.exports = function(fileString) {
if (fencedBlock) return line;
let modifiedLine = line;
/* Replace inline-style links or reference-style links e.g:
This is [Document 1](doc1.md) -> we replace this doc1.md with correct link
[doc1]: doc1.md -> we replace this doc1.md with correct link
*/
// Replace inline-style links or reference-style links e.g:
// This is [Document 1](doc1.md) -> we replace this doc1.md with correct link
// [doc1]: doc1.md -> we replace this doc1.md with correct link
const mdRegex = /(?:(?:\]\()|(?:\]:\s?))(?!https)([^'")\]\s>]+\.md)/g;
let mdMatch = mdRegex.exec(modifiedLine);
while (mdMatch !== null) {
/* Replace it to correct html link */
// Replace it to correct html link.
const mdLink = mdMatch[1];
const targetSource = `${sourceDir}/${mdLink}`;
const {permalink} =
@ -86,21 +85,21 @@ module.exports = function(fileString) {
const md = new Remarkable({
langPrefix: 'hljs css language-',
highlight(str, rawLang) {
// Default language fallback
// Default language fallback.
const defaultLang =
siteConfig.highlight && siteConfig.highlight.defaultLang;
// No syntax highlighting
// No syntax highlighting.
if (rawLang === 'text' || (!rawLang && !defaultLang)) {
return escapeHtml(str);
}
// User's own hljs function to register additional languages
// User's own hljs function to register additional languages.
if (siteConfig.highlight && siteConfig.highlight.hljs) {
siteConfig.highlight.hljs(hljs);
}
// Syntax highlighting
// Syntax highlighting.
const lang = rawLang.toLowerCase() || defaultLang;
try {
if (hljs.getLanguage(lang)) {
@ -119,10 +118,10 @@ module.exports = function(fileString) {
linkify: true,
});
// Register anchors plugin
// Register anchors plugin.
md.use(anchors);
// Allow client sites to register their own plugins
// Allow client sites to register their own plugins.
if (siteConfig.markdownPlugins) {
siteConfig.markdownPlugins.forEach(plugin => {
md.use(plugin);
@ -134,7 +133,8 @@ module.exports = function(fileString) {
const html = md
.render(content)
.replace(/<pre><code>/g, '<pre><code class="hljs">');
/* Return a React component */
// Return a React component.
return `
import React from 'react';
import Markdown from '@theme/Markdown';

View file

@ -59,7 +59,7 @@ module.exports = (string, context = {}) => {
}
if (typeof context.slugStats[slug] === 'number') {
// search for an index, that will not clash with an existing headings
// Search for an index, that will not clash with an existing headings
while (
typeof context.slugStats[`${slug}-${++context.slugStats[slug]}`] ===
'number'
@ -67,7 +67,7 @@ module.exports = (string, context = {}) => {
slug += `-${context.slugStats[slug]}`;
}
// we are tracking both original anchors and suffixed to avoid future name
// We are tracking both original anchors and suffixed to avoid future name
// clashing with headings with numbers e.g. `#Foo 1` may clash with the second `#Foo`
context.slugStats[slug] = 0;

View file

@ -23,7 +23,7 @@ module.exports = function createServerConfig(props) {
const {siteConfig, blogMetadatas, docsMetadatas, pagesMetadatas} = props;
// static site generator webpack plugin
// Static site generator webpack plugin.
const docsFlatMetadatas = Object.values(docsMetadatas);
const paths = [...blogMetadatas, ...docsFlatMetadatas, ...pagesMetadatas].map(
data => data.permalink,
@ -38,7 +38,7 @@ module.exports = function createServerConfig(props) {
},
]);
// show compilation progress bar
// Show compilation progress bar.
const isProd = process.env.NODE_ENV === 'production';
config
.plugin('niceLog')
@ -46,7 +46,7 @@ module.exports = function createServerConfig(props) {
{name: 'Server', color: 'yellow', skipBuildTime: isProd},
]);
// user extended webpack-chain config
// User-extended webpack-chain config.
applyChainWebpack(props.siteConfig.chainWebpack, config, true);
return config;

View file

@ -7,7 +7,7 @@
const merge = require('webpack-merge');
// Modify the generated webpack config with normal webpack config
// Modify the generated webpack config with normal webpack config.
function applyConfigureWebpack(userConfig, config, isServer) {
if (typeof userConfig === 'object') {
return merge(config, userConfig);
@ -21,7 +21,7 @@ function applyConfigureWebpack(userConfig, config, isServer) {
return config;
}
// Modify the generated webpack config with webpack-chain API
// Modify the generated webpack config with webpack-chain API.
function applyChainWebpack(userChainWebpack, config, isServer) {
if (userChainWebpack) {
userChainWebpack(config, isServer);