Skip to content

Commit a241a46

Browse files
cowlingjJoelMarcey
authored andcommittedJan 22, 2018
Make font-family as configurable parameter(#220) (#294)
We look for fonts object within siteConfig.js
1 parent e0704d0 commit a241a46

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed
 

‎docs/api-site-config.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ headerLinks: [
6262

6363
### Optional Fields
6464

65+
`fonts` - Font-family css configuration for the site. If a font family specified as `$myFont`, then adding a `myFont` key to an array in `fonts` will allow you to configure the font. Items appearing earlier in the array will take priority of later elements, so these should be more specific.
6566
`customDocsPath` - By default, Docusaurus expects your documentation to be in a directory called `docs`. This directory is at the same level as the `website` directory (i.e., not inside the `website` directory). You can specify a custom path to your documentation with this field. **Note that all of your documentation *.md files must still reside in a flat hierarchy. You cannot have your documents in nested directories**.
6667

6768
```js

‎lib/server/generate.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,18 @@ function execute() {
346346
codeColor
347347
);
348348

349+
if (siteConfig.fonts) {
350+
Object.keys(siteConfig.fonts).forEach(key => {
351+
const fontString = siteConfig.fonts[key]
352+
.map(font => '"' + font + '"')
353+
.join(', ');
354+
cssContent = cssContent.replace(
355+
new RegExp('\\$' + key, 'g'),
356+
fontString
357+
);
358+
});
359+
}
360+
349361
mkdirp.sync(path.dirname(targetFile));
350362
fs.writeFileSync(targetFile, cssContent);
351363
} else if (!fs.lstatSync(file).isDirectory()) {
@@ -357,7 +369,7 @@ function execute() {
357369
// copy all static files from user
358370
files = glob.sync(join(CWD, 'static', '**'), {dot: true});
359371
files.forEach(file => {
360-
// parse css files to replace colors according to siteConfig
372+
// parse css files to replace colors and fonts according to siteConfig
361373
if (file.match(/\.css$/) && !isSeparateCss(file)) {
362374
const mainCss = join(buildDir, 'css', 'main.css');
363375
let cssContent = fs.readFileSync(file, 'utf8');
@@ -368,6 +380,18 @@ function execute() {
368380
cssContent = cssContent.replace(new RegExp('\\$' + key, 'g'), color);
369381
});
370382

383+
if (siteConfig.fonts) {
384+
Object.keys(siteConfig.fonts).forEach(key => {
385+
const fontString = siteConfig.fonts[key]
386+
.map(font => '"' + font + '"')
387+
.join(', ');
388+
cssContent = cssContent.replace(
389+
new RegExp('\\$' + key, 'g'),
390+
fontString
391+
);
392+
});
393+
}
394+
371395
fs.writeFileSync(mainCss, cssContent);
372396
} else if (!fs.lstatSync(file).isDirectory()) {
373397
let parts = file.split('/static/');

‎lib/server/server.js

+12
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,18 @@ function execute(port) {
487487
.string();
488488
cssContent = cssContent.replace(new RegExp('\\$codeColor', 'g'), codeColor);
489489

490+
if (siteConfig.fonts) {
491+
Object.keys(siteConfig.fonts).forEach(key => {
492+
const fontString = siteConfig.fonts[key]
493+
.map(font => '"' + font + '"')
494+
.join(', ');
495+
cssContent = cssContent.replace(
496+
new RegExp('\\$' + key, 'g'),
497+
fontString
498+
);
499+
});
500+
}
501+
490502
res.send(cssContent);
491503
});
492504

0 commit comments

Comments
 (0)
Please sign in to comment.