`; // Loop over tags and snippets to create the list of snippets for (let tag of taggedData){ let notEmbedded = true; let localOutput = output .replace(/\$tag/g, util.capitalize(tag)) .replace(new RegExp(`./${tag}#`, 'g'), '#'); if (tag === 'array') localOutput = localOutput.replace(new RegExp('./index#', 'g'), '#'); localOutput += md .render(`## ${util.capitalize(tag, true)}\n`) .replace(/
/g, '');
if (tag === 'array')
localOutput += ``;
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) {
localOutput += generateSnippetCard(snippets, taggedSnippet, true);
if (Object.entries(tagDbData).filter(v => v[1][0] === tag).findIndex(v => v[0] === taggedSnippet[0]) >= Object.entries(tagDbData).filter(v => v[1][0] === tag).length * 0.5 && notEmbedded) {
notEmbedded = !notEmbedded;
localOutput += embedCard(tag);
}
}
// Add the ending static part
localOutput += `\n${endPart + '\n'}`;
// Optimize punctuation nodes
localOutput = util.optimizeNodes(
localOutput,
/([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm,
(match, p1, p2, p3) => `${p1}${p2}${p3}`
);
// Optimize operator nodes
localOutput = util.optimizeNodes(
localOutput,
/([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm,
(match, p1, p2, p3) => `${p1}${p2}${p3}`
);
// Optimize keyword nodes
localOutput = util.optimizeNodes(
localOutput,
/([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm,
(match, p1, p2, p3) => `${p1}${p2}${p3}`
);
pagesOutput.push({ tag, content: localOutput });
}
// Minify output
pagesOutput.forEach(page => {
page.content = minifyHTML(page.content);
fs.writeFileSync(
path.join(docsPath, (page.tag === 'array' ? 'index' : page.tag) + '.html'),
page.content
);
console.log(
`${green('SUCCESS!')} ${page.tag === 'array' ? 'index' : page.tag}.html file generated!`
);
});
} catch (err) {
// Handle errors (hopefully not!)
console.log(`${red('ERROR!')} During category page generation: ${err}`);
process.exit(1);
}
const generateMenuForStaticPage = staticPart => {
let taggedData = util.prepTaggedData(tagDbData);
// Add the start static part
let htmlCode;
for (let tag of taggedData) {
htmlCode +=
'' +
md
.render(`${util.capitalize(tag, true)}\n`)
.replace(/
/g, '')
.replace(/<\/p>/g, '') +
'
';
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) {
htmlCode += md
.render(
`[${taggedSnippet[0]}](./${
tag === 'array' ? 'index' : tag
}#${taggedSnippet[0].toLowerCase()})\n`
)
.replace(//g, '')
.replace(/<\/p>/g, '')
.replace(/\n';
}
return staticPart.replace('$nav-menu-data', htmlCode);
};
const staticPageStartGenerator = (staticPart, heading, description) => {
let taggedData = util.prepTaggedData(tagDbData);
// Add the start static part
let htmlCode = `${staticPart}\n`;
// Loop over tags and snippets to create the table of contents
for (let tag of taggedData) {
htmlCode +=
'' +
md
.render(`${util.capitalize(tag, true)}\n`)
.replace(/
/g, '')
.replace(/<\/p>/g, '') +
'
';
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) {
htmlCode += md
.render(
`[${taggedSnippet[0]}](./${
tag === 'array' ? 'index' : tag
}#${taggedSnippet[0].toLowerCase()})\n`
)
.replace(//g, '')
.replace(/<\/p>/g, '')
.replace(/\n';
}
htmlCode += `Archive
Glossary
Contributing
About
${heading}
${description}
`;
return htmlCode.replace(/\$page_name/g, util.capitalize(heading));
};
// Create the output for the archive.html file
try {
// Add the static part
let heading = 'Snippets Archive';
let description = "These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are.";
let htmlCode = staticPageStartGenerator(staticPageStartPart, heading, description);
archivedOutput += htmlCode;
// Filter README.md from folder
const filteredArchivedSnippets = filterSnippets(archivedSnippets, ['README.md']);
// Generate archived snippets from md files
for (let snippet of Object.entries(filteredArchivedSnippets))
archivedOutput += generateSnippetCard(filteredArchivedSnippets, snippet, false);
// Optimize punctuation nodes
archivedOutput = util.optimizeNodes(
archivedOutput,
/([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm,
(match, p1, p2, p3) => `${p1}${p2}${p3}`
);
// Optimize operator nodes
archivedOutput = util.optimizeNodes(
archivedOutput,
/([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm,
(match, p1, p2, p3) => `${p1}${p2}${p3}`
);
// Optimize keyword nodes
archivedOutput = util.optimizeNodes(
archivedOutput,
/([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm,
(match, p1, p2, p3) => `${p1}${p2}${p3}`
);
archivedOutput += `${staticPageEndPart}`;
// Generate and minify 'archive.html' file
const minifiedArchivedOutput = minifyHTML(archivedOutput);
fs.writeFileSync(path.join(docsPath, 'archive.html'), minifiedArchivedOutput);
console.log(`${green('SUCCESS!')} archive.html file generated!`);
} catch (err) {
console.log(`${red('ERROR!')} During archive.html generation: ${err}`);
process.exit(1);
}
// Create the output for the glossary.html file
try {
// Add the static part
let heading = 'Glossary';
let description = 'Developers use a lot of terminology daily. Every once in a while, you might find a term you do not know. We know how frustrating that can get, so we provide you with a handy glossary of frequently used web development terms.';
let htmlCode = staticPageStartGenerator(staticPageStartPart, heading, description);
glossaryOutput += htmlCode;
// Filter README.md from folder
const filteredGlossarySnippets = filterSnippets(glossarySnippets, ['README.md']);
// Generate glossary snippets from md files
for (let snippet of Object.entries(filteredGlossarySnippets)) {
glossaryOutput +=
'' +
md
.render(`\n${filteredGlossarySnippets[snippet[0]]}`)
.replace(//g, '') +
'
';
}
glossaryOutput += `${staticPageEndPart}`;
// Generate and minify 'glossary.html' file
const minifiedGlossaryOutput = minifyHTML(glossaryOutput);
fs.writeFileSync(path.join(docsPath, 'glossary.html'), minifiedGlossaryOutput);
console.log(`${green('SUCCESS!')} glossary.html file generated!`);
} catch (err) {
console.log(`${red('ERROR!')} During glossary.html generation: ${err}`);
process.exit(1);
}
// Copy static files
staticFiles.forEach(f => {
try {
if(f !== 'array.html') {
let fileData = fs.readFileSync(path.join(staticPartsPath, f), 'utf8');
fs.writeFileSync(path.join(docsPath, f), generateMenuForStaticPage(fileData));
} else
fs.copyFileSync(path.join(staticPartsPath, f), path.join(docsPath, f));
console.log(`${green('SUCCESS!')} ${f} file copied!`);
} catch (err) {
console.log(`${red('ERROR!')} During ${f} copying: ${err}`);
process.exit(1);
}
});
// Log the time taken
console.timeEnd('Webber');
' + md .render(`${util.capitalize(tag, true)}\n`) .replace(/
/g, '') .replace(/<\/p>/g, '') + '
- ';
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) {
htmlCode += md
.render(
`[${taggedSnippet[0]}](./${
tag === 'array' ? 'index' : tag
}#${taggedSnippet[0].toLowerCase()})\n`
)
.replace(/
/g, '')
.replace(/<\/p>/g, '')
.replace(/\n';
}
return staticPart.replace('$nav-menu-data', htmlCode);
};
const staticPageStartGenerator = (staticPart, heading, description) => {
let taggedData = util.prepTaggedData(tagDbData);
// Add the start static part
let htmlCode = `${staticPart}\n`;
// Loop over tags and snippets to create the table of contents
for (let tag of taggedData) {
htmlCode +=
' /g, '')
.replace(/<\/p>/g, '') +
' /g, '')
.replace(/<\/p>/g, '')
.replace(/\n';
}
htmlCode += ` ${description}' +
md
.render(`${util.capitalize(tag, true)}\n`)
.replace(/
';
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) {
htmlCode += md
.render(
`[${taggedSnippet[0]}](./${
tag === 'array' ? 'index' : tag
}#${taggedSnippet[0].toLowerCase()})\n`
)
.replace(/
Archive
Glossary
Contributing
About
${heading}
`;
return htmlCode.replace(/\$page_name/g, util.capitalize(heading));
};
// Create the output for the archive.html file
try {
// Add the static part
let heading = 'Snippets Archive';
let description = "These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are.";
let htmlCode = staticPageStartGenerator(staticPageStartPart, heading, description);
archivedOutput += htmlCode;
// Filter README.md from folder
const filteredArchivedSnippets = filterSnippets(archivedSnippets, ['README.md']);
// Generate archived snippets from md files
for (let snippet of Object.entries(filteredArchivedSnippets))
archivedOutput += generateSnippetCard(filteredArchivedSnippets, snippet, false);
// Optimize punctuation nodes
archivedOutput = util.optimizeNodes(
archivedOutput,
/([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm,
(match, p1, p2, p3) => `${p1}${p2}${p3}`
);
// Optimize operator nodes
archivedOutput = util.optimizeNodes(
archivedOutput,
/([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm,
(match, p1, p2, p3) => `${p1}${p2}${p3}`
);
// Optimize keyword nodes
archivedOutput = util.optimizeNodes(
archivedOutput,
/([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm,
(match, p1, p2, p3) => `${p1}${p2}${p3}`
);
archivedOutput += `${staticPageEndPart}`;
// Generate and minify 'archive.html' file
const minifiedArchivedOutput = minifyHTML(archivedOutput);
fs.writeFileSync(path.join(docsPath, 'archive.html'), minifiedArchivedOutput);
console.log(`${green('SUCCESS!')} archive.html file generated!`);
} catch (err) {
console.log(`${red('ERROR!')} During archive.html generation: ${err}`);
process.exit(1);
}
// Create the output for the glossary.html file
try {
// Add the static part
let heading = 'Glossary';
let description = 'Developers use a lot of terminology daily. Every once in a while, you might find a term you do not know. We know how frustrating that can get, so we provide you with a handy glossary of frequently used web development terms.';
let htmlCode = staticPageStartGenerator(staticPageStartPart, heading, description);
glossaryOutput += htmlCode;
// Filter README.md from folder
const filteredGlossarySnippets = filterSnippets(glossarySnippets, ['README.md']);
// Generate glossary snippets from md files
for (let snippet of Object.entries(filteredGlossarySnippets)) {
glossaryOutput +=
'/g, '') +
'