mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-26 01:33:02 +00:00
user css gets concatenated to main.css, fixed scripts
This commit is contained in:
parent
f75bd4fc99
commit
e46f97b151
|
|
@ -177,7 +177,6 @@ function execute() {
|
|||
cssContent = cssContent.replace(new RegExp('{secondaryColor}', 'g'), siteConfig.colors.secondaryColor);
|
||||
cssContent = cssContent.replace(new RegExp('{prismColor}', 'g'), siteConfig.colors.prismColor);
|
||||
|
||||
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.writeFileSync(targetFile, cssContent);
|
||||
}
|
||||
|
|
@ -211,18 +210,15 @@ function execute() {
|
|||
|
||||
fs.removeSync(tempFile);
|
||||
}
|
||||
/* for css files, concatenate it to the end of the main.css provided by docusaurus */
|
||||
else if (file.match(/\.css$/)) {
|
||||
console.log(file);
|
||||
let parts = file.split('src');
|
||||
|
||||
const mainCss = __dirname + '/../../build' + siteConfig.baseUrl + 'css/main.css';
|
||||
let cssContent = fs.readFileSync(file);
|
||||
cssContent = cssContent.toString().replace(new RegExp('{primaryColor}', 'g'), siteConfig.colors.primaryColor);
|
||||
cssContent = cssContent.replace(new RegExp('{secondaryColor}', 'g'), siteConfig.colors.secondaryColor);
|
||||
cssContent = cssContent.replace(new RegExp('{prismColor}', 'g'), siteConfig.colors.prismColor);
|
||||
cssContent = fs.readFileSync(mainCss) + '\n' + cssContent;
|
||||
|
||||
|
||||
let targetFile = __dirname + '/../../build' + siteConfig.baseUrl + parts[1];
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.writeFileSync(targetFile, cssContent);
|
||||
fs.writeFileSync(mainCss, cssContent);
|
||||
}
|
||||
else if (!fs.lstatSync(file).isDirectory()) {
|
||||
let parts = file.split('src');
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ function execute () {
|
|||
const readMetadata = require('./readMetadata.js');
|
||||
const toSlug = require('../core/toSlug.js');
|
||||
const mkdirp = require('mkdirp');
|
||||
const glob = require('glob');
|
||||
let siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
/**
|
||||
|
|
@ -282,20 +283,17 @@ function execute () {
|
|||
res.redirect('/index.html');
|
||||
});
|
||||
|
||||
/* generate the css file with the specified colors from siteConfig */
|
||||
app.get('*.css', (req, res) => {
|
||||
let filePath = req.path.toString().replace(siteConfig.baseUrl, '/');
|
||||
let cssContent;
|
||||
if (fs.existsSync(CWD + '/src' + filePath)) {
|
||||
cssContent = fs.readFileSync(CWD + '/src' + filePath);
|
||||
}
|
||||
else if (fs.existsSync(__dirname + '/../src' + filePath)) {
|
||||
cssContent = fs.readFileSync(__dirname + '/../src' + filePath);
|
||||
}
|
||||
else {
|
||||
res.send('No File Found');
|
||||
return;
|
||||
}
|
||||
/* generate the main.css file by concatenating user provided css to the end */
|
||||
app.get(/main\.css$/, (req,res) => {
|
||||
const mainCssPath = __dirname +'/../src/' + req.path.toString().replace(siteConfig.baseUrl, '/');
|
||||
let cssContent = fs.readFileSync(mainCssPath);
|
||||
|
||||
let files = glob.sync(CWD + '/src/**/*.css')
|
||||
|
||||
files.forEach(file => {
|
||||
cssContent = cssContent + '\n' + fs.readFileSync(file);
|
||||
});
|
||||
|
||||
cssContent = cssContent.toString().replace(new RegExp('{primaryColor}', 'g'), siteConfig.colors.primaryColor);
|
||||
cssContent = cssContent.replace(new RegExp('{secondaryColor}', 'g'), siteConfig.colors.secondaryColor);
|
||||
cssContent = cssContent.replace(new RegExp('{prismColor}', 'g'), siteConfig.colors.prismColor);
|
||||
|
|
@ -303,6 +301,27 @@ function execute () {
|
|||
res.send(cssContent);
|
||||
});
|
||||
|
||||
/* generate the css file with the specified colors from siteConfig */
|
||||
// app.get('*.css', (req, res) => {
|
||||
// let filePath = req.path.toString().replace(siteConfig.baseUrl, '/');
|
||||
// let cssContent;
|
||||
// if (fs.existsSync(CWD + '/src' + filePath)) {
|
||||
// cssContent = fs.readFileSync(CWD + '/src' + filePath);
|
||||
// }
|
||||
// else if (fs.existsSync(__dirname + '/../src' + filePath)) {
|
||||
// cssContent = fs.readFileSync(__dirname + '/../src' + filePath);
|
||||
// }
|
||||
// else {
|
||||
// res.send('No File Found');
|
||||
// return;
|
||||
// }
|
||||
// cssContent = cssContent.toString().replace(new RegExp('{primaryColor}', 'g'), siteConfig.colors.primaryColor);
|
||||
// cssContent = cssContent.replace(new RegExp('{secondaryColor}', 'g'), siteConfig.colors.secondaryColor);
|
||||
// cssContent = cssContent.replace(new RegExp('{prismColor}', 'g'), siteConfig.colors.prismColor);
|
||||
|
||||
// res.send(cssContent);
|
||||
// });
|
||||
|
||||
/* serve static content first from user folder then from docusaurus */
|
||||
app.use(siteConfig.baseUrl, express.static(CWD + '/src'));
|
||||
app.use(siteConfig.baseUrl, express.static(__dirname + '/../src'));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"scripts": {
|
||||
"start": "./lib/start-server.js",
|
||||
"build": "./lib/build-files.js",
|
||||
"publish": "./lib/publish-gh-pages.js",
|
||||
"publish-gh-pages": "./lib/publish-gh-pages.js",
|
||||
"examples": "./lib/copy-examples.js"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
"babel-preset-react": "^6.24.1"
|
||||
},
|
||||
"name": "docusaurus",
|
||||
"version": "0.0.8-t",
|
||||
"version": "0.0.8-y",
|
||||
"bin": {
|
||||
"docusaurus-start": "./lib/start-server.js",
|
||||
"docusaurus-build": "./lib/build-files.js",
|
||||
|
|
|
|||
Loading…
Reference in New Issue