Skip to content

Commit

Permalink
feat: 优化文档
Browse files Browse the repository at this point in the history
  • Loading branch information
novlan1 committed Oct 9, 2022
1 parent 2bc6255 commit eabe476
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
14 changes: 7 additions & 7 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dist/
lib/
node_modules/
public/
config/
docs/
repo
/dist/
/lib/
/node_modules/
/public/
/config/
/docs/
/repo/
6 changes: 3 additions & 3 deletions script/docs/jsdoc-local.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { JsDocHandler } = require('../../lib/index')
const { JsDocHandler } = require('../../lib/index');

JsDocHandler.init({
author: 'novlan1'
})
author: 'novlan1',
});
8 changes: 0 additions & 8 deletions script/docs/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ function hiddenSeparatorWhenSearch() {
});
}

function hiddenFooter() {
const footer = document.querySelector('footer');

if (footer) {
footer.style.display = 'none';
}
}


document.addEventListener('DOMContentLoaded', () => {
hiddenSeparatorWhenSearch();
Expand Down
27 changes: 24 additions & 3 deletions src/jsdoc/jsdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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) {
*
* }
* })
*
*/
Expand All @@ -46,6 +63,7 @@ class JsDocHandler {
extraCss: string;
author: string;
docsPath: string;
navHandler: Function;
fs;
path;

Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
});
Expand Down

0 comments on commit eabe476

Please sign in to comment.