docs: Fix docco output.
docco 0.8 and onward changed the paths of the output files.  This fixes
them.
Resolves
MODIFY
examples/build-utils.js
examples/build-utils.js
@@ -98,7 +98,36 @@ function writeYamlList(dir, filename, records) {
);
}
+/**
+ * Fix paths of docco files and remove unnecessary extra files.
+ *
+ * @param {string} sourceFile The path of the javascript file being processed.
+ * @param {string} outputPath The output directory.
+ * @returns {function} A function to call from docco to fix the results.
+ */
+function fixupDocco(sourceFile, outputPath) {
+ return function () {
+ // docco places the file many directories deep
+ const destname = path.basename(sourceFile, path.extname(sourceFile)) + '.html';
+ const src = path.join(outputPath, 'docs', path.dirname(sourceFile), destname);
+ // read the file and adjust the css link
+ const doc = fs.readFileSync(src, {encoding: 'utf8'}).replace(/href=".*docco\.css/, 'href="docco.css');
+ // write it back in the correct spot
+ fs.writeFileSync(path.join(outputPath, 'docs', destname), doc, {encoding: 'utf8'});
+ // remove it
+ fs.removeSync(src);
+ // if the directory is empty, prune it
+ if (!fs.readdirSync(path.dirname(src)).length) {
+ fs.removeSync(path.join(outputPath, 'docs', path.dirname(sourceFile).substr(0, path.dirname(sourceFile).indexOf('/', 1))));
+ // simplify the docco output to reduce the output size by removing the
+ // unnecessary public/ directory
+ fs.removeSync(path.resolve(outputPath, 'docs', 'public'));
+ }
+ };
+}
+
module.exports = {
getList: getList,
+ fixupDocco: fixupDocco,
writeYamlList: writeYamlList
};

MODIFY
examples/build-website.js
examples/build-website.js
@@ -14,30 +14,22 @@ examples.forEach(function (json) {
if (json.main) {
const options = {
args: [json.main],
+ opts: () => ({
output: path.resolve(json.output, 'docs'),
layout: 'classic'
+ })
};
- // docco 0.8.1 requires this weirdness
- options.opts = () => options;
- docco(options, function () {
- // simplify the docco output to reduce the output size by
- // removing the unnecessary public/ directory
- fs.removeSync(path.resolve(json.output, 'docs', 'public'));
- });
+ docco(options, buildUtils.fixupDocco(options.args[0], json.output));
}
(json.docJs || []).forEach(function (name) {
const options = {
args: [path.resolve(json.dir, name)],
+ opts: () => ({
output: path.resolve(json.output, 'docs'),
layout: 'classic'
+ })
};
- // docco 0.8.1 requires this weirdness
- options.opts = () => options;
- docco(options, function () {
- // simplify the docco output to reduce the output size by
- // removing the unnecessary public/ directory
- fs.removeSync(path.resolve(json.output, 'docs', 'public'));
- });
+ docco(options, buildUtils.fixupDocco(options.args[0], json.output));
});
json.docHTML = 'docs/' + path.basename(json.main).replace(/js$/, 'html');

MODIFY
examples/build.js
examples/build.js
@@ -15,30 +15,22 @@ examples.forEach(function (json) {
if (json.exampleJs.length) {
const options = {
args: [json.main],
+ opts: () => ({
output: path.resolve(json.output, 'docs'),
layout: 'classic'
+ })
};
- // docco 0.8.1 requires this weirdness
- options.opts = () => options;
- docco(options, function () {
- // simplify the docco output to reduce the output size by
- // removing the unnecessary public/ directory
- fs.removeSync(path.resolve(json.output, 'docs', 'public'));
- });
+ docco(options, buildUtils.fixupDocco(options.args[0], json.output));
}
(json.docJs || []).forEach(function (name) {
const options = {
args: [path.resolve(json.dir, name)],
+ opts: () => ({
output: path.resolve(json.output, 'docs'),
layout: 'classic'
+ })
};
- // docco 0.8.1 requires this weirdness
- options.opts = () => options;
- docco(options, function () {
- // simplify the docco output to reduce the output size by
- // removing the unnecessary public/ directory
- fs.removeSync(path.resolve(json.output, 'docs', 'public'));
- });
+ docco(options, buildUtils.fixupDocco(options.args[0], json.output));
});
json.docHTML = 'docs/' + path.basename(json.main).replace(/js$/, 'html');

MODIFY
website/package.json
website/package.json
"version": "0.0.0",
"private": true,
"hexo": {
- "version": "5.4.0"
+ "version": "5.4.1"
},
"dependencies": {
"hexo": "^5.4.0",

docs: Fix docco output.

docco 0.8 and onward changed the paths of the output files.  This fixes
them.

Resolves #1168.