diff --git a/compile.js b/compile.js index 2c60e88..14b27a1 100644 --- a/compile.js +++ b/compile.js @@ -38,8 +38,28 @@ if(Process.argv.length < 4 && require.main === module) { } function markup(input, options) { + var usedSlugs = {}; let tableOfContents = new Remarkable().use(TOCGenerator.plugin(options)).render(input); - let output = new Remarkable().use(RemarkableHeaderIDs()).render("# Table of contents:\n"+tableOfContents.content+"\n\n"+input); + let output = new Remarkable().use( + RemarkableHeaderIDs({ + levels: [1,2,3,4,5,6], + anchorClassName: "header-anchor", + anchorText: "#", + headerId: function(slug) { + if(usedSlugs[slug] > 0) { + const out_ = `${slug}-${usedSlugs[slug]}`; + usedSlugs[slug] = usedSlugs[slug] + 1; + return out_; + } else { + if(!usedSlugs.hasOwnProperty(slug)) { + usedSlugs[slug] = 0; + } + usedSlugs[slug] = usedSlugs[slug] + 1; + return slug; + } + } + }) + ).render("# Table of contents:\n"+tableOfContents.content+"\n\n"+input); return output; } @@ -67,7 +87,7 @@ function format(data, name) { "$1$2" ) .replace( /* multitag suffix fix for special characters. */ - /(<\/(?:a|code)>)\n\t*([.)\];:,?!+-])/g, + /(<\/(?:a|code)>)\n\t*([.)\];:,?!+\-'])/g, "$1$2" ) .replace( /* fix tag attached to word and not whitespace */ diff --git a/sitemap-gen.js b/sitemap-gen.js index d121dbc..598b9f1 100644 --- a/sitemap-gen.js +++ b/sitemap-gen.js @@ -45,9 +45,10 @@ ${outputTemp} } function makeSitemapChunk(file, outputDir) { + var file = file.replace(".md", ".html"); outputTemp = outputTemp.concat( /* eslint-disable indent */ ` - https://${targetDomain}${rootPrefix}${file.replace(outputDir, "")} + https://${targetDomain}${rootPrefix}${file.replace(outputDir, "").replace(".md", ".html")} ${Filesystem.statSync(file).mtime.toISOString().substring(0, 10)} ` diff --git a/ymake.js b/ymake.js index 047d99b..1e93376 100644 --- a/ymake.js +++ b/ymake.js @@ -73,9 +73,11 @@ Filesystem.globSync(`${SRC_DIRS}/**/*.css`).forEach(function(file) { Filesystem.writeFileSync(Path.normalize(BUILD_DIR+"/sitemap.xml"), require("./sitemap-gen.js")( MARKDOWN_L.map(function(filename){ - return Path.dirname(filename).replace(/\\/g, "/") + "/" + Path.basename(filename); + return Path.dirname(filename) + .replace(Path.normalize(SRC_DIRS), Path.normalize(BUILD_DIR)) + .replace(/\\/g, "/") + "/" + Path.basename(filename, ".md") + ".html"; }), - Path.normalize(SRC_DIRS) + Path.normalize(BUILD_DIR) ) ); console.log(`SMAP: ${Path.normalize(BUILD_DIR+"/sitemap.xml")}`);