From a4999575d07e2cee802ffca60ffcb1e39ec6299f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 1 Aug 2016 14:17:25 -0700 Subject: [PATCH] Cleanup npm link creation. --- lib/main/build-doc.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/main/build-doc.js b/lib/main/build-doc.js index f52b87bb2..94003448b 100644 --- a/lib/main/build-doc.js +++ b/lib/main/build-doc.js @@ -23,28 +23,40 @@ var config = { }, 'github': { 'style': 'github', - 'sublinks': [ - '<% if (name == "templateSettings" || !/^(?:methods|properties|seq)$/i.test(category)) {' + - 'print("[Ⓝ](https://www.npmjs.com/package/lodash." + name.toLowerCase() + " \\"See the npm package\\")")' + - '} %>' - ] + 'sublinks': [npmLink('Ⓝ', 'See the npm package')] }, 'site': { 'entryLink': '', 'sourceLink': '[source](${sourceHref})', 'tocHref': '', 'tocLink': '', - 'sublinks': [ - '<% if (name == "templateSettings" || !/^(?:methods|properties|seq)$/i.test(category)) {' + - 'print("[npm package](https://www.npmjs.com/package/lodash." + name.toLowerCase() + ")")' + - '} %>' - ] + 'sublinks': [npmLink('npm package')] } }; +/** + * Composes a npm link from `text` and optional `title`. + * + * @private + * @param {string} text The link text. + * @param {string} [title] The link title. + * @returns {string} Returns the composed npm link. + */ +function npmLink(text, title) { + return ( + '<% if (name == "templateSettings" || !/^(?:methods|properties|seq)$/i.test(category)) {' + + 'print(' + + '"[' + text + '](https://www.npmjs.com/package/lodash." + name.toLowerCase() + ' + + '"' + (title == null ? '' : ' \\"' + title + '\\"') + ')"' + + ');' + + '} %>' + ); +} + /** * Post-process `markdown` to make adjustments. * + * @private * @param {string} markdown The markdown to process. * @returns {string} Returns the processed markdown. */ @@ -58,6 +70,7 @@ function postprocess(markdown) { /** * Creates the documentation markdown formatted for 'github' or 'site'. * + * @private * @param {string} type The format type. */ function build(type) {