From 6b0069f10f322c1a5cfeccbd127d59b509c5bd29 Mon Sep 17 00:00:00 2001 From: Zack Hall Date: Fri, 1 Jul 2016 10:45:19 -0700 Subject: [PATCH] Add doc-site build script (#2461) --- .gitignore | 1 + lib/main/build-site.js | 43 ++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 3 files changed, 46 insertions(+) create mode 100644 lib/main/build-site.js diff --git a/.gitignore b/.gitignore index 63ec000f7..56cc3a36d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.log coverage node_modules +doc/*.html \ No newline at end of file diff --git a/lib/main/build-site.js b/lib/main/build-site.js new file mode 100644 index 000000000..6baba581b --- /dev/null +++ b/lib/main/build-site.js @@ -0,0 +1,43 @@ +'use strict'; + +const fs = require('fs'), + marky = require('marky-markdown'), + path = require('path'), + _ = require('lodash'); + +const basePath = path.join(__dirname, '..', '..'), + docPath = path.join(basePath, 'doc'), + readmePath = path.join(docPath, 'README.md'); + +function onComplete(error) { + if (error) { + throw error; + } +} + +function build(type) { + let html = + marky(fs.readFileSync(readmePath, 'utf8'), { sanitize: false }); + const header = html('h1').first(); + const version = _.trim(header.find('span').first().text()); + + header.remove(); + html = html.html(); + html = html.replace(//g, '>'); + + html = [ + '---', + 'id: docs', + 'layout: docs', + 'title: lodash Documentation', + `version: ${version ? version : null}`, + '---', + html, + ].join('\n'); + + // File output + fs.writeFile(path.join(docPath, `${version}.html`), html, onComplete); +} + +build(); \ No newline at end of file diff --git a/package.json b/package.json index de6142eac..b06abb778 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "doc": "node lib/main/build-doc github && npm run test:doc", "doc:fp": "node lib/fp/build-doc", "doc:site": "node lib/main/build-doc site", + "doc:sitehtml": "npm run doc:site && node lib/main/build-site", "prepublish": "npm run build", "pretest": "npm run build", "style": "npm run style:main && npm run style:fp && npm run style:perf && npm run style:test", @@ -43,6 +44,7 @@ "jscs": "^3.0.5", "lodash": "4.11.2", "markdown-doctest": "^0.8.1", + "marky-markdown": "^7.0.1", "platform": "^1.3.1", "qunit-extras": "^2.0.1", "qunitjs": "^1.23.1",