From 7d01d1679c9ae8edd569e40673720436efdc8814 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 25 Feb 2021 01:31:26 -0600 Subject: [PATCH] docs: simplify docs --- .gitignore | 2 +- docs/branding/footer.html.in | 7 --- docs/branding/media/js/script.js | 47 -------------- docs/branding/{ => public}/CNAME | 0 .../branding/{ => public}/media/css/style.css | 61 +------------------ docs/branding/{ => public}/media/img/logo.svg | 0 .../{header.html.in => template.html} | 5 ++ docs/index.md | 4 +- scripts/build-docs.js | 54 ++++++++-------- 9 files changed, 37 insertions(+), 143 deletions(-) delete mode 100644 docs/branding/footer.html.in delete mode 100644 docs/branding/media/js/script.js rename docs/branding/{ => public}/CNAME (100%) rename docs/branding/{ => public}/media/css/style.css (81%) rename docs/branding/{ => public}/media/img/logo.svg (100%) rename docs/branding/{header.html.in => template.html} (94%) diff --git a/.gitignore b/.gitignore index e70d427..7637174 100644 --- a/.gitignore +++ b/.gitignore @@ -77,4 +77,4 @@ xcuserdata *.env # built docs -public +/public diff --git a/docs/branding/footer.html.in b/docs/branding/footer.html.in deleted file mode 100644 index 17cf313..0000000 --- a/docs/branding/footer.html.in +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/docs/branding/media/js/script.js b/docs/branding/media/js/script.js deleted file mode 100644 index 496dd56..0000000 --- a/docs/branding/media/js/script.js +++ /dev/null @@ -1,47 +0,0 @@ - -/* eslint-disable */ - -$(function() { - var headerHeight = $("#header").height(); - var offsets = []; - var current = -1; - - function endpoint(scrollDistance) { - if (scrollDistance < offsets[0]) { - return -1; - } else { - for (var id = offsets.length; id > 0; id--) { - if (scrollDistance > offsets[id - 1]) { - return id - 1; - break; - } - } - } - } - - $("h2").each(function(i) { - offsets.push($(this).offset().top - headerHeight) - }); - - $("#content").append(''); - var fixed_h2 = $("h2.fixed"); - var fixed_span = $("h2.fixed span"); - - $("#content").scroll(function() { - var scrollDistance = $("#content").attr('scrollTop'); - var now = endpoint(scrollDistance); - - if (now !== current) { - $("#sidebar li").removeClass("current"); - current = now; - if (current < 0) { - fixed_h2.hide(); - } else if (current >= 0) { - var heading = $($("h2 span")[current]).text(); - $("#sidebar a[href|=#" + heading.replace(' ', '-') + "]").parent().addClass("current"); - fixed_span.text(heading); - fixed_h2.show(); - } - } - }); -}); diff --git a/docs/branding/CNAME b/docs/branding/public/CNAME similarity index 100% rename from docs/branding/CNAME rename to docs/branding/public/CNAME diff --git a/docs/branding/media/css/style.css b/docs/branding/public/media/css/style.css similarity index 81% rename from docs/branding/media/css/style.css rename to docs/branding/public/media/css/style.css index c5477d6..adaae73 100644 --- a/docs/branding/media/css/style.css +++ b/docs/branding/public/media/css/style.css @@ -7,7 +7,7 @@ body { color: #4a3f2d; } -:focus { +:focus:not(:focus-visible) { outline: 0; } @@ -83,22 +83,6 @@ h4 { display: inline; } - - -/* ---- custom classes */ - -pre.shell, -pre.shell code { - background:#444; - color:#fff; - border-width:0px; -} -pre.shell code::before { - content: '$ '; - display: inline; -} - - /* ---- header and sidebar */ #header { @@ -150,15 +134,6 @@ pre.shell code::before { z-index:0; } -#sidebar .vertical_divider { - background-color:#FFFFFF; - bottom:0px; - position:absolute; - top:0px; - right:0px; - width:1px; -} - #sidebar h1 { font-size:1.2em; padding:0px; @@ -187,25 +162,6 @@ pre.shell code::before { padding:1px 0px 1px 2px; } -#sidebar li span.verb { - color:#aaa; - padding:2px 3px 0px; - width:30px; - display:block; - float:left; - font-size:9px; - font-family:verdana; - -moz-border-radius:3px; - -webkit-border-radius:3px; - margin-left:0px; - margin-right:5px; -} - -#sidebar li.current { - background-repeat: no-repeat; - background-position:right; -} - /* ---- intro */ @@ -219,13 +175,6 @@ pre.shell code::before { border-radius: 5px; margin-bottom:40px; } -.intro pre.base { - background:#444; - color:#29231A; - color:#fff; - border-color:#fff; - font-size:1.5em; -} .intro h1 { color: #1C313C; } @@ -259,14 +208,6 @@ h1 + h2 { margin-top: 0px; } -h2.fixed { - position:fixed; - margin-top: 0; - border-top:none; - right:45px; - top:66px; -} - h2 span { background: #979592; float:right; diff --git a/docs/branding/media/img/logo.svg b/docs/branding/public/media/img/logo.svg similarity index 100% rename from docs/branding/media/img/logo.svg rename to docs/branding/public/media/img/logo.svg diff --git a/docs/branding/header.html.in b/docs/branding/template.html similarity index 94% rename from docs/branding/header.html.in rename to docs/branding/template.html index 0af4160..01183cc 100644 --- a/docs/branding/header.html.in +++ b/docs/branding/template.html @@ -32,3 +32,8 @@
+%(content)s +
+ + + diff --git a/docs/index.md b/docs/index.md index af59dd1..c6a26c3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -79,9 +79,7 @@ API documentation is: # More information - License:[MIT](http://opensource.org/licenses/mit-license.php) -- Code: [mcavage/node-ldapjs](https://github.com/mcavage/node-ldapjs) -- node.js version: >=0.8 -- Twitter: [@pfmooney](http://twitter.com/pfmooney) +- Code: [ldapjs/node-ldapjs](https://github.com/ldapjs/node-ldapjs) # What's not in the box? diff --git a/scripts/build-docs.js b/scripts/build-docs.js index dcadd97..fb0ecb5 100644 --- a/scripts/build-docs.js +++ b/scripts/build-docs.js @@ -66,56 +66,60 @@ function markdownTOC (markdown) { } } -function createHTML (header, footer, text) { +function createHTML (template, text) { const { attributes, body } = fm(text) - for (const prop in attributes) { - header = header.replace(new RegExp(`%\\(${prop}\\)s`, 'ig'), attributes[prop]) - footer = footer.replace(new RegExp(`%\\(${prop}\\)s`, 'ig'), attributes[prop]) - } const { toc, html } = markdownTOC(body) + attributes.toc_html = toc + attributes.content = html - header = header.replace(/%\(toc_html\)s/ig, toc) + for (const prop in attributes) { + template = template.replace(new RegExp(`%\\(${prop}\\)s`, 'ig'), attributes[prop]) + } - return header + html + footer + return template +} + +async function copyRecursive (src, dest) { + const stats = await fs.stat(src) + const isDirectory = stats.isDirectory() + if (isDirectory) { + await fs.mkdir(dest) + const files = await fs.readdir(src) + for (const file of files) { + await copyRecursive(path.join(src, file), path.join(dest, file)) + } + } else { + await fs.copyFile(src, dest) + } } async function createDocs () { const docs = path.resolve(__dirname, '..', 'docs') const dist = path.resolve(__dirname, '..', 'public') const branding = path.join(docs, 'branding') + const src = path.join(branding, 'public') await fs.rmdir(dist, { recursive: true }) - await fs.mkdir(dist) + await copyRecursive(src, dist) - const header = await fs.readFile(path.join(branding, 'header.html.in'), { encoding: 'utf8' }) - const footer = await fs.readFile(path.join(branding, 'footer.html.in'), { encoding: 'utf8' }) + const highlightjsStyles = path.resolve(__dirname, '..', 'node_modules', 'highlight.js', 'styles') + await fs.copyFile(path.join(highlightjsStyles, 'default.css'), path.join(dist, 'media', 'css', 'highlight.css')) + + const template = await fs.readFile(path.join(branding, 'template.html'), { encoding: 'utf8' }) const files = await fs.readdir(docs) for (const file of files) { if (!file.endsWith('.md')) { continue } const text = await fs.readFile(path.join(docs, file), { encoding: 'utf8' }) - const html = createHTML(header, footer, text) + const html = createHTML(template, text) await fs.writeFile(path.join(dist, file.replace(/md$/, 'html')), html) } - - const dest = path.join(dist, 'media') - const src = path.join(branding, 'media') - const highlightjsStyles = path.resolve(__dirname, '..', 'node_modules', 'highlight.js', 'styles') - await fs.mkdir(dest) - await fs.mkdir(path.join(dest, 'css')) - await fs.mkdir(path.join(dest, 'js')) - await fs.mkdir(path.join(dest, 'img')) - await fs.copyFile(path.join(src, 'css', 'style.css'), path.join(dest, 'css', 'style.css')) - await fs.copyFile(path.join(highlightjsStyles, 'default.css'), path.join(dest, 'css', 'highlight.css')) - await fs.copyFile(path.join(src, 'js', 'script.js'), path.join(dest, 'js', 'script.js')) - await fs.copyFile(path.join(src, 'img', 'logo.svg'), path.join(dest, 'img', 'logo.svg')) - await fs.copyFile(path.join(branding, 'CNAME'), path.join(dist, 'CNAME')) } createDocs().catch(ex => { console.error(ex) - process.exit(1) + process.exitCode = 1 })