mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
feat: random color scheme in siteConfig (#1365)
This commit is contained in:
parent
57df1f8e32
commit
94a0da33c3
2 changed files with 48 additions and 16 deletions
|
@ -54,8 +54,8 @@ const siteConfig = {
|
||||||
|
|
||||||
/* Colors for website */
|
/* Colors for website */
|
||||||
colors: {
|
colors: {
|
||||||
primaryColor: '#2E8555',
|
primaryColor: '{{primaryColor}}',
|
||||||
secondaryColor: '#205C3B',
|
secondaryColor: '{{secondaryColor}}',
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Custom fonts for website */
|
/* Custom fonts for website */
|
||||||
|
|
|
@ -15,6 +15,24 @@ const path = require('path');
|
||||||
|
|
||||||
const CWD = process.cwd();
|
const CWD = process.cwd();
|
||||||
|
|
||||||
|
const toHex = color => {
|
||||||
|
const hex = color.toString(16);
|
||||||
|
return hex.length === 1 ? `0${hex}` : hex;
|
||||||
|
};
|
||||||
|
|
||||||
|
const colorScheme = () => {
|
||||||
|
let primaryColor = '#';
|
||||||
|
let secondaryColor = '#';
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
// 175 is our ceiling to prevent the color from being too bright
|
||||||
|
const color = Math.floor(Math.random() * 176);
|
||||||
|
const darkColor = Math.floor(color * 0.7);
|
||||||
|
primaryColor += toHex(color);
|
||||||
|
secondaryColor += toHex(darkColor);
|
||||||
|
}
|
||||||
|
return {primaryColor, secondaryColor};
|
||||||
|
};
|
||||||
|
|
||||||
let feature;
|
let feature;
|
||||||
|
|
||||||
commander
|
commander
|
||||||
|
@ -197,20 +215,34 @@ if (feature === 'translations') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const filePath = path.resolve(file).split(path.resolve(folder))[1];
|
const filePath = path.resolve(file).split(path.resolve(folder))[1];
|
||||||
try {
|
if (
|
||||||
fs.copySync(file, CWD + filePath, {
|
path.basename(file) === 'siteConfig.js' &&
|
||||||
overwrite: false,
|
!fs.existsSync(CWD + filePath)
|
||||||
errorOnExist: true,
|
) {
|
||||||
});
|
const {primaryColor, secondaryColor} = colorScheme();
|
||||||
exampleSiteCreated = true;
|
const siteConfig = fs
|
||||||
} catch (e) {
|
.readFileSync(file, 'utf8')
|
||||||
console.log(
|
.replace('{{primaryColor}}', primaryColor)
|
||||||
`- ${chalk.green(
|
.replace('{{secondaryColor}}', secondaryColor);
|
||||||
`${path.basename(filePath)}`,
|
fs.writeFileSync(CWD + filePath, siteConfig);
|
||||||
)} already exists in ${chalk.blue(
|
} else {
|
||||||
`${outerFolder}/website${filePath.split(path.basename(filePath))[0]}`,
|
try {
|
||||||
)}.`,
|
fs.copySync(file, CWD + filePath, {
|
||||||
);
|
overwrite: false,
|
||||||
|
errorOnExist: true,
|
||||||
|
});
|
||||||
|
exampleSiteCreated = true;
|
||||||
|
} catch (e) {
|
||||||
|
console.log(
|
||||||
|
`- ${chalk.green(
|
||||||
|
`${path.basename(filePath)}`,
|
||||||
|
)} already exists in ${chalk.blue(
|
||||||
|
`${outerFolder}/website${
|
||||||
|
filePath.split(path.basename(filePath))[0]
|
||||||
|
}`,
|
||||||
|
)}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue