add tags to example docs

#10022
This commit is contained in:
roemhildtg
2019-10-23 22:06:46 -05:00
parent 599835e818
commit 9908433cfd
2 changed files with 21 additions and 2 deletions

View File

@@ -138,9 +138,13 @@ ExampleBuilder.prototype.apply = function(compiler) {
.filter(chunk => chunk.names[0] !== this.common);
const exampleData = [];
const uniqueTags = new Set();
const promises = chunks.map(async chunk => {
const [assets, data] = await this.render(compiler.context, chunk);
// collect tags for main page... TODO: implement index tag links
data.tags.forEach(tag => uniqueTags.add(tag));
exampleData.push({
link: data.filename,
example: data.filename,
@@ -158,7 +162,8 @@ ExampleBuilder.prototype.apply = function(compiler) {
const info = {
examples: exampleData,
index: createWordIndex(exampleData)
index: createWordIndex(exampleData),
tags: Array.from(uniqueTags)
};
const indexSource = `var info = ${JSON.stringify(info)}`;
@@ -182,6 +187,13 @@ ExampleBuilder.prototype.render = async function(dir, chunk) {
data.olVersion = pkg.version;
data.filename = htmlName;
// process tags
if (data.tags) {
data.tags = data.tags.replace(/[\s"]+/g, '').split(',');
} else {
data.tags = [];
}
// add in script tag
const jsName = `${name}.js`;
let jsSource = getJsSource(chunk, path.join('.', jsName));