feat: random color scheme in siteConfig (#1365)

This commit is contained in:
murray-b 2019-04-15 12:04:38 -04:00 committed by Yangshun Tay
parent 57df1f8e32
commit 94a0da33c3
2 changed files with 48 additions and 16 deletions

View file

@ -54,8 +54,8 @@ const siteConfig = {
/* Colors for website */
colors: {
primaryColor: '#2E8555',
secondaryColor: '#205C3B',
primaryColor: '{{primaryColor}}',
secondaryColor: '{{secondaryColor}}',
},
/* Custom fonts for website */

View file

@ -15,6 +15,24 @@ const path = require('path');
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;
commander
@ -197,6 +215,17 @@ if (feature === 'translations') {
return;
}
const filePath = path.resolve(file).split(path.resolve(folder))[1];
if (
path.basename(file) === 'siteConfig.js' &&
!fs.existsSync(CWD + filePath)
) {
const {primaryColor, secondaryColor} = colorScheme();
const siteConfig = fs
.readFileSync(file, 'utf8')
.replace('{{primaryColor}}', primaryColor)
.replace('{{secondaryColor}}', secondaryColor);
fs.writeFileSync(CWD + filePath, siteConfig);
} else {
try {
fs.copySync(file, CWD + filePath, {
overwrite: false,
@ -208,10 +237,13 @@ if (feature === 'translations') {
`- ${chalk.green(
`${path.basename(filePath)}`,
)} already exists in ${chalk.blue(
`${outerFolder}/website${filePath.split(path.basename(filePath))[0]}`,
`${outerFolder}/website${
filePath.split(path.basename(filePath))[0]
}`,
)}.`,
);
}
}
});
if (exampleSiteCreated) {