| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -652,7 +652,7 @@ tools/doc/node_modules/js-yaml/package.json: | |||
| 652 | 652 | ||
| 653 | 653 | gen-json = tools/doc/generate.js --format=json $< > $@ | |
| 654 | 654 | gen-html = tools/doc/generate.js --node-version=$(FULLVERSION) --format=html \ | |
| 655 | - --template=doc/template.html --analytics=$(DOCS_ANALYTICS) $< > $@ | ||
| 655 | + --analytics=$(DOCS_ANALYTICS) $< > $@ | ||
| 656 | 656 | ||
| 657 | 657 | out/doc/api/%.json: doc/api/%.md | |
| 658 | 658 | $(call available-node, $(gen-json)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,6 @@ try { | |||
| 10 | 10 | ||
| 11 | 11 | const assert = require('assert'); | |
| 12 | 12 | const fs = require('fs'); | |
| 13 | - const path = require('path'); | ||
| 14 | 13 | const fixtures = require('../common/fixtures'); | |
| 15 | 14 | const processIncludes = require('../../tools/doc/preprocess.js'); | |
| 16 | 15 | const html = require('../../tools/doc/html.js'); | |
@@ -107,7 +106,6 @@ testData.forEach((item) => { | |||
| 107 | 106 | { | |
| 108 | 107 | input: preprocessed, | |
| 109 | 108 | filename: 'foo', | |
| 110 | - template: path.resolve(__dirname, '../../doc/template.html'), | ||
| 111 | 109 | nodeVersion: process.version, | |
| 112 | 110 | analytics: item.analyticsId, | |
| 113 | 111 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,6 @@ const fs = require('fs'); | |||
| 29 | 29 | ||
| 30 | 30 | const args = process.argv.slice(2); | |
| 31 | 31 | let format = 'json'; | |
| 32 | - let template = null; | ||
| 33 | 32 | let filename = null; | |
| 34 | 33 | let nodeVersion = null; | |
| 35 | 34 | let analytics = null; | |
@@ -39,8 +38,6 @@ args.forEach(function(arg) { | |||
| 39 | 38 | filename = arg; | |
| 40 | 39 | } else if (arg.startsWith('--format=')) { | |
| 41 | 40 | format = arg.replace(/^--format=/, ''); | |
| 42 | - } else if (arg.startsWith('--template=')) { | ||
| 43 | - template = arg.replace(/^--template=/, ''); | ||
| 44 | 41 | } else if (arg.startsWith('--node-version=')) { | |
| 45 | 42 | nodeVersion = arg.replace(/^--node-version=/, ''); | |
| 46 | 43 | } else if (arg.startsWith('--analytics=')) { | |
@@ -71,7 +68,7 @@ function next(er, input) { | |||
| 71 | 68 | break; | |
| 72 | 69 | ||
| 73 | 70 | case 'html': | |
| 74 | - require('./html')({ input, filename, template, nodeVersion, analytics }, | ||
| 71 | + require('./html')({ input, filename, nodeVersion, analytics }, | ||
| 75 | 72 | (err, html) => { | |
| 76 | 73 | if (err) throw err; | |
| 77 | 74 | console.log(html); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,6 @@ const common = require('./common.js'); | |||
| 25 | 25 | const fs = require('fs'); | |
| 26 | 26 | const marked = require('marked'); | |
| 27 | 27 | const path = require('path'); | |
| 28 | - const preprocess = require('./preprocess.js'); | ||
| 29 | 28 | const typeParser = require('./type-parser.js'); | |
| 30 | 29 | ||
| 31 | 30 | module.exports = toHTML; | |
@@ -42,76 +41,36 @@ marked.setOptions({ | |||
| 42 | 41 | renderer: renderer | |
| 43 | 42 | }); | |
| 44 | 43 | ||
| 45 | - // TODO(chrisdickinson): never stop vomiting / fix this. | ||
| 46 | - const gtocPath = path.resolve(path.join( | ||
| 47 | - __dirname, | ||
| 48 | - '..', | ||
| 49 | - '..', | ||
| 50 | - 'doc', | ||
| 51 | - 'api', | ||
| 52 | - '_toc.md' | ||
| 53 | - )); | ||
| 54 | - var gtocLoading = null; | ||
| 55 | - var gtocData = null; | ||
| 44 | + const docPath = path.resolve(__dirname, '..', '..', 'doc'); | ||
| 45 | + | ||
| 46 | + const gtocPath = path.join(docPath, 'api', '_toc.md'); | ||
| 47 | + const gtocMD = fs.readFileSync(gtocPath, 'utf8').replace(/^@\/\/.*$/gm, ''); | ||
| 48 | + const gtocHTML = marked(gtocMD).replace( | ||
| 49 | + /<a href="(.*?)"/g, | ||
| 50 | + (all, href) => `<a class="nav-${toID(href)}" href="${href}"` | ||
| 51 | + ); | ||
| 52 | + | ||
| 53 | + const templatePath = path.join(docPath, 'template.html'); | ||
| 54 | + const template = fs.readFileSync(templatePath, 'utf8'); | ||
| 55 | + | ||
| 56 | 56 | var docCreated = null; | |
| 57 | 57 | var nodeVersion = null; | |
| 58 | 58 | ||
| 59 | 59 | /** | |
| 60 | - * opts: input, filename, template, nodeVersion. | ||
| 60 | + * opts: input, filename, nodeVersion. | ||
| 61 | 61 | */ | |
| 62 | 62 | function toHTML(opts, cb) { | |
| 63 | - const template = opts.template; | ||
| 64 | - | ||
| 65 | 63 | nodeVersion = opts.nodeVersion || process.version; | |
| 66 | 64 | docCreated = opts.input.match(DOC_CREATED_REG_EXP); | |
| 67 | 65 | ||
| 68 | - if (gtocData) { | ||
| 69 | - return onGtocLoaded(); | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - if (gtocLoading === null) { | ||
| 73 | - gtocLoading = [onGtocLoaded]; | ||
| 74 | - return loadGtoc(function(err, data) { | ||
| 75 | - if (err) throw err; | ||
| 76 | - gtocData = data; | ||
| 77 | - gtocLoading.forEach(function(xs) { | ||
| 78 | - xs(); | ||
| 79 | - }); | ||
| 80 | - }); | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - if (gtocLoading) { | ||
| 84 | - return gtocLoading.push(onGtocLoaded); | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - function onGtocLoaded() { | ||
| 88 | - const lexed = marked.lexer(opts.input); | ||
| 89 | - fs.readFile(template, 'utf8', function(er, template) { | ||
| 90 | - if (er) return cb(er); | ||
| 91 | - render({ | ||
| 92 | - lexed: lexed, | ||
| 93 | - filename: opts.filename, | ||
| 94 | - template: template, | ||
| 95 | - nodeVersion: nodeVersion, | ||
| 96 | - analytics: opts.analytics, | ||
| 97 | - }, cb); | ||
| 98 | - }); | ||
| 99 | - } | ||
| 100 | - } | ||
| 101 | - | ||
| 102 | - function loadGtoc(cb) { | ||
| 103 | - fs.readFile(gtocPath, 'utf8', function(err, data) { | ||
| 104 | - if (err) return cb(err); | ||
| 105 | - | ||
| 106 | - preprocess(gtocPath, data, function(err, data) { | ||
| 107 | - if (err) return cb(err); | ||
| 108 | - | ||
| 109 | - data = marked(data).replace(/<a href="(.*?)"/gm, function(a, m) { | ||
| 110 | - return `<a class="nav-${toID(m)}" href="${m}"`; | ||
| 111 | - }); | ||
| 112 | - return cb(null, data); | ||
| 113 | - }); | ||
| 114 | - }); | ||
| 66 | + const lexed = marked.lexer(opts.input); | ||
| 67 | + render({ | ||
| 68 | + lexed: lexed, | ||
| 69 | + filename: opts.filename, | ||
| 70 | + template: template, | ||
| 71 | + nodeVersion: nodeVersion, | ||
| 72 | + analytics: opts.analytics, | ||
| 73 | + }, cb); | ||
| 115 | 74 | } | |
| 116 | 75 | ||
| 117 | 76 | function toID(filename) { | |
@@ -150,7 +109,7 @@ function render(opts, cb) { | |||
| 150 | 109 | template = template.replace(/__TOC__/g, toc); | |
| 151 | 110 | template = template.replace( | |
| 152 | 111 | /__GTOC__/g, | |
| 153 | - gtocData.replace(`class="nav-${id}`, `class="nav-${id} active`) | ||
| 112 | + gtocHTML.replace(`class="nav-${id}`, `class="nav-${id} active`) | ||
| 154 | 113 | ); | |
| 155 | 114 | ||
| 156 | 115 | if (opts.analytics) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments