Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 5 additions & 42 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ const shelljs = require('shelljs'),
elasticlunr = require('elasticlunr'),
jsonata = require('jsonata'),
mkdirp = require('mkdirp'),
toc = require('markdown-toc'),
jsonfile = require('jsonfile'),
matter = require('gray-matter'),
matter = require('@11ty/gray-matter'),
parseArgs = require('minimist');
const documentation = import('documentation');

Expand Down Expand Up @@ -318,43 +317,6 @@ function postValidate (strict, ignoreExternal) {
});
}

function parseTableOfContents (frontMatter, body) {
let maxdepth = 2;
const tocConfig = frontMatter.match(/^toc: ?(\d+)$/m);
if (tocConfig) {
maxdepth = Number.parseInt(tocConfig[1]);
}

const table = toc(body, {maxdepth});
if (table.json.length < 3) {
return '';
}

return `
<nav role="navigation" class="page-toc">

${table.content}

</nav>
`;
}

function prependTableOfContents (contents) {
let table = '';
let frontMatter = '';
let body = contents;

if (contents.startsWith('---')) {
const endOfFrontMatter = contents.indexOf('---', 4) + 3;
frontMatter = contents.substring(0, endOfFrontMatter);
body = contents.substring(endOfFrontMatter);

table = parseTableOfContents(frontMatter, body);
}

return `${frontMatter}${table}\n${body}`;
}

/**
* Loads the docs config (if it exists) or creates a default config object based on best guess.
* The config object contains information that specifies how other docs information is loaded. It is
Expand Down Expand Up @@ -403,7 +365,7 @@ function copyStaticDocs ({source, outputTo: outputBase, icon}) {
const sourceWin32 = source.replace('/', '\\');
const findCmdDir = `dir ${sourceWin32}\\*docs /S /B /AD`;
const docDirs = shelljs.exec(findCmdDir, {silent: true});
const dirs = docDirs.stdout.trim().split('\r\n');
const dirs = docDirs.stdout.trim().split('\r\n').filter(d => d.length > 0);

for (let dir of dirs) {
const findCmdFiles = `dir ${dir} /S /B /A-D`;
Expand Down Expand Up @@ -439,7 +401,7 @@ function copyStaticDocs ({source, outputTo: outputBase, icon}) {
const base = pathModule.basename(relativeFile);
// Cheating, discard 'raw' and get directory name -- this will work with 'enact/packages'
const packageName = source.replace(/raw\/([^/]*)\/?(.*)?/, '$1/blob/develop/$2');
let githubUrl = `github: https://github.com/enactjs/${packageName}${relativeFile}\n`;
let githubUrl = `button:\n label: Edit on GitHub\n href: https://github.com/enactjs/${packageName}${relativeFile}\n`;

if (base === 'config.json') return;

Expand All @@ -465,7 +427,8 @@ function copyStaticDocs ({source, outputTo: outputBase, icon}) {
if (file.indexOf('index.md') === -1) {
contents = contents.replace(/\]\(\.\//g, '](../'); // same level .md files are now relative to root
}
contents = prependTableOfContents(contents);

contents = contents.replace(/]\((?!https?:\/\/)([^)]+)\)/g, (_, url) => `](${url.toLowerCase()})`);
fs.writeFileSync(pathModule.join(outputPath, base), contents, {encoding: 'utf8'});
} else {
shelljs.cp(file, outputPath);
Expand Down
Loading
Loading