Skip to content

Commit 79877d4

Browse files
committed
Allow custom stylesheets to be defined.
1 parent 1bfcae5 commit 79877d4

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

packages/webdoc-cli/src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type ConfigSchema = {
3333
},
3434
template: {
3535
applicationName: string,
36+
stylesheets: Array<string>,
3637
siteDomain?: string,
3738
siteRoot: string,
3839
mainPage?: {
@@ -79,6 +80,7 @@ const defaultConfig: ConfigSchema = {
7980
template: {
8081
applicationName: "{ <i>webdoc</i> }",
8182
siteRoot: "",
83+
stylesheets: [],
8284
mainPage: {
8385
title: "Main Page",
8486
},

packages/webdoc-default-template/publish.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ exports.publish = async function publish(options /*: PublishOptions */) {
122122
idToDoc.set(doc.id, doc);
123123
});
124124

125-
outStaticFiles(outDir);
125+
await outStaticFiles(outDir, config);
126126
outExplorerData(outDir, crawlData);
127127
outMainPage(path.join(outDir, indexRelative), pipeline, options.config);
128128
outIndexes(outDir, pipeline, options.config, crawlData.index);
@@ -133,11 +133,13 @@ exports.publish = async function publish(options /*: PublishOptions */) {
133133
};
134134

135135
// Copy the contents of ./static to the output directory
136-
function outStaticFiles(outDir /*: string */) /*: Promise<void> */ {
136+
async function outStaticFiles(outDir /*: string */, config /*: ConfigSchema */) /*: Promise<void> */ {
137137
const staticDir = path.join(__dirname, "./static");
138138

139-
return fse.copy(staticDir, outDir)
140-
.then(() => {
139+
await fse.copy(staticDir, outDir)
140+
141+
await Promise.all([
142+
(async () => {
141143
// Copy the prettify script to outDir
142144
PRETTIFIER_SCRIPT_FILES.forEach((fileName) => {
143145
const toPath = path.join(outDir, "scripts", path.basename(fileName));
@@ -146,8 +148,29 @@ function outStaticFiles(outDir /*: string */) /*: Promise<void> */ {
146148
path.join(require.resolve("code-prettify"), "..", fileName),
147149
toPath,
148150
);
149-
});
150-
});
151+
})
152+
})(),
153+
(() => {
154+
// Copy the stylesheets
155+
const stylesheets = config.template.stylesheets;
156+
let copyPromises = [];
157+
let resolved = [];
158+
159+
for (const file of stylesheets) {
160+
const out = path.join(outDir, file);
161+
162+
resolved.push(path.relative(outDir, out));
163+
copyPromises.push(fse.copy(
164+
path.join(process.cwd(), file),
165+
out,
166+
));
167+
}
168+
169+
config.template.stylesheets = resolved;
170+
171+
return Promise.all(copyPromises);
172+
})(),
173+
]);
151174
}
152175

153176
// Write the explorer JSON data in the output directory

packages/webdoc-default-template/src/styles/header.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
}
6666

6767
&__link__current {
68-
color: #0066cd;
68+
color: $colorPrimary;
6969
text-decoration: none;
7070
}
7171

packages/webdoc-default-template/static/styles/index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/webdoc-default-template/tmpl/layout.tmpl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const siteRoot = this.getPlugin("linker").siteRoot;
1010
const sitePrefix = siteRoot ? siteRoot + "/" : siteRoot;
1111
const integrations = JSON.stringify(config.integrations);
1212
?>
13+
<!-- Generated by webdoc on <?js= new Date().toLocaleString() + " " + Intl.DateTimeFormat().resolvedOptions().timeZone ?> -->
1314
<!DOCTYPE html>
1415
<html lang="en">
1516
<head>
@@ -25,6 +26,10 @@ const integrations = JSON.stringify(config.integrations);
2526
<meta property="<?js= key ?>" content="<?js= config.meta[key].replace("{{url}}", `${config.siteDomain}`) ?>" />
2627
<?js }); ?>
2728

29+
<?js config.stylesheets.forEach((file) => { ?>
30+
<link rel="stylesheet" type="text/css" href="<?js= "/" + sitePrefix + file ?>" />
31+
<?js }); ?>
32+
2833
<script>
2934
window.appData = {
3035
applicationName: "<?js= config.applicationName ?>",
@@ -43,7 +48,7 @@ const integrations = JSON.stringify(config.integrations);
4348
<script src="/<?js= sitePrefix ?>scripts/default-template.js"></script>
4449
</head>
4550
<body class="root">
46-
<div class="docs">
51+
<div class="docs <?js= document && document.type === "TutorialDoc" ? "tutorials" : "api-docs" ?>">
4752
<article class="page">
4853
<div class="page-explorer" id="explorer-mount-point"></div>
4954
<div class="header-content-container">

0 commit comments

Comments
 (0)