mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 09:07:29 +02:00
Move Docusaurus 1 files into directory (#966)
* Move Docusaurus 1 into v1 directory * Update Circle CI commands for new v1 dir * Remove OC * Fix tests
This commit is contained in:
parent
9d4a5d5359
commit
f2927a9fc4
291 changed files with 7591 additions and 6532 deletions
75
v1/lib/server/utils.js
Normal file
75
v1/lib/server/utils.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* 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');
|
||||
|
||||
function getSubDir(file, refDir) {
|
||||
const subDir = path.dirname(path.relative(refDir, file)).replace('\\', '/');
|
||||
return subDir !== '.' && !subDir.includes('..') ? subDir : null;
|
||||
}
|
||||
|
||||
function getLanguage(file, refDir) {
|
||||
const separator = escapeStringRegexp(path.sep);
|
||||
const baseDir = escapeStringRegexp(path.basename(refDir));
|
||||
const regexSubFolder = new RegExp(
|
||||
`${baseDir}${separator}(.*?)${separator}.*`,
|
||||
);
|
||||
const match = regexSubFolder.exec(file);
|
||||
|
||||
// Avoid misinterpreting subdirectory as language
|
||||
const env = require('./env.js');
|
||||
if (match && env.translation.enabled) {
|
||||
const enabledLanguages = env.translation
|
||||
.enabledLanguages()
|
||||
.map(language => language.tag);
|
||||
if (enabledLanguages.indexOf(match[1]) !== -1) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isSeparateCss(file, separateDirs) {
|
||||
if (!separateDirs) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < separateDirs.length; i++) {
|
||||
if (file.includes(separateDirs[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function minifyCss(cssContent) {
|
||||
return cssnano
|
||||
.process(cssContent, {
|
||||
preset: 'default',
|
||||
zindex: false,
|
||||
})
|
||||
.then(result => result.css);
|
||||
}
|
||||
|
||||
function autoPrefixCss(cssContent) {
|
||||
return postcss([autoprefixer])
|
||||
.process(cssContent, {
|
||||
from: undefined,
|
||||
})
|
||||
.then(result => result.css);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSubDir,
|
||||
getLanguage,
|
||||
isSeparateCss,
|
||||
minifyCss,
|
||||
autoPrefixCss,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue