fix: #1114 static files in blog/assets is not working (#1143)

* fix: #1114 static files in `blog/assets` is not working

* lint fix
This commit is contained in:
tsmrachel 2018-12-07 23:58:20 +08:00 committed by Endilie Yacop Sucipto
parent db6017903b
commit a1e7af7e0e
6 changed files with 114 additions and 23 deletions

View file

@ -4,12 +4,12 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const postcss = require('postcss');
const path = require('path');
const escapeStringRegexp = require('escape-string-regexp');
const siteConfig = require('../../website/siteConfig.js');
function getSubDir(file, refDir) {
const subDir = path.dirname(path.relative(refDir, file)).replace(/\\/g, '/');
@ -66,10 +66,27 @@ function autoPrefixCss(cssContent) {
.then(result => result.css);
}
function replaceAssetsLink(oldContent, location) {
let fencedBlock = false;
const lines = oldContent.split('\n').map(line => {
if (line.trim().startsWith('```')) {
fencedBlock = !fencedBlock;
}
return fencedBlock
? line
: line.replace(
/\]\(assets\//g,
`](${siteConfig.baseUrl}${location}/assets/`,
);
});
return lines.join('\n');
}
module.exports = {
getSubDir,
getLanguage,
isSeparateCss,
minifyCss,
autoPrefixCss,
replaceAssetsLink,
};