Skip to content

Commit

Permalink
Merge pull request #1172 from OpenGeoscience/fix-docco-output
Browse files Browse the repository at this point in the history
docs: Fix docco output.
  • Loading branch information
manthey authored Feb 1, 2022
2 parents 6670a96 + c8fd0bd commit 7b58b48
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
29 changes: 29 additions & 0 deletions examples/build-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
28 changes: 10 additions & 18 deletions examples/build-website.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,22 @@ examples.forEach(function (json) {
if (json.main) {
const options = {
args: [json.main],
output: path.resolve(json.output, 'docs'),
layout: 'classic'
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)],
output: path.resolve(json.output, 'docs'),
layout: 'classic'
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');

Expand Down
28 changes: 10 additions & 18 deletions examples/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,22 @@ examples.forEach(function (json) {
if (json.exampleJs.length) {
const options = {
args: [json.main],
output: path.resolve(json.output, 'docs'),
layout: 'classic'
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)],
output: path.resolve(json.output, 'docs'),
layout: 'classic'
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');

Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"hexo": {
"version": "5.4.0"
"version": "5.4.1"
},
"dependencies": {
"hexo": "^5.4.0",
Expand Down

0 comments on commit 7b58b48

Please sign in to comment.