diff --git a/.eslintignore b/.eslintignore index a015d587..2fcdda91 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,7 @@ -dist/ -lib/ -node_modules/ -public/ -config/ -docs/ -repo +/dist/ +/lib/ +/node_modules/ +/public/ +/config/ +/docs/ +/repo/ diff --git a/script/docs/jsdoc-local.js b/script/docs/jsdoc-local.js index 6f3303ee..c2c72b85 100644 --- a/script/docs/jsdoc-local.js +++ b/script/docs/jsdoc-local.js @@ -1,5 +1,5 @@ -const { JsDocHandler } = require('../../lib/index') +const { JsDocHandler } = require('../../lib/index'); JsDocHandler.init({ - author: 'novlan1' -}) + author: 'novlan1', +}); diff --git a/script/docs/jsdoc.js b/script/docs/jsdoc.js index fb4a1d9d..7094852e 100644 --- a/script/docs/jsdoc.js +++ b/script/docs/jsdoc.js @@ -15,14 +15,6 @@ function hiddenSeparatorWhenSearch() { }); } -function hiddenFooter() { - const footer = document.querySelector('footer'); - - if (footer) { - footer.style.display = 'none'; - } -} - document.addEventListener('DOMContentLoaded', () => { hiddenSeparatorWhenSearch(); diff --git a/src/jsdoc/jsdoc.ts b/src/jsdoc/jsdoc.ts index 282c1392..9112dd8e 100644 --- a/src/jsdoc/jsdoc.ts +++ b/src/jsdoc/jsdoc.ts @@ -20,6 +20,17 @@ function getSeparatorStr(content) { return `${fill} ${content} ${fill}`; } +/** + * 默认处理source的方法,默认仅去掉的文件名 + * @private + * @param source 文件路径 + * @returns 处理后的数据 + */ +function defaultNavHandler(source) { + const list = source.split('/'); + return list.slice(0, list.length - 1).join('/'); +} + class JsDocHandler { /** @@ -29,11 +40,17 @@ class JsDocHandler { * @param {string} [options.docsPath] 文档所在目录位置,默认为`./docs` * @param {string} [options.author] 作者,默认为空 * @param {string} [options.extraCss] 额外插入的css,默认为`.nav-separator`的一些样式 + * @param {string} [options.navHandler] 处理API所在文件的方法 * @returns {object} JsDocHandler实例 * @example * * JsDocHandler.init({ - * author: 'novlan1' + * author: 'novlan1', + * docsPath: './docs', + * extraCss: '.some-class{}', + * navHandler(nav) { + * + * } * }) * */ @@ -46,6 +63,7 @@ class JsDocHandler { extraCss: string; author: string; docsPath: string; + navHandler: Function; fs; path; @@ -59,20 +77,24 @@ class JsDocHandler { * @param {string} [options.docsPath] 文档所在目录位置,默认为`./docs` * @param {string} [options.author] 作者,默认为空 * @param {string} [options.extraCss] 额外插入的css,默认为`.nav-separator`的一些样式 + * @param {string} [options.navHandler] 处理API所在文件的方法 */ constructor(options: { docsPath?: string author?: string extraCss?: string + navHandler?: Function } = {}) { const { docsPath = './docs', author = '', extraCss = DEFAULT_EXTRA_CSS, + navHandler = defaultNavHandler, } = options; this.docsPath = docsPath; this.author = author; this.extraCss = extraCss; + this.navHandler = navHandler; this.fs = this.getFs(); this.path = this.getPath(); } @@ -130,8 +152,7 @@ class JsDocHandler { .html() .trim(); - const list = source.split('/'); - source = list.slice(0, list.length - 1).join('/'); + source = this.navHandler(source); sourceMap[`${file}#${id}`] = source; });