dubbo document support search.

This commit is contained in:
oppofind 2020-12-19 02:58:58 +08:00
parent c1120f1c81
commit b4b145873c
15 changed files with 410 additions and 365 deletions

View File

@ -33,9 +33,7 @@ import com.power.doc.model.ApiErrorCode;
import com.power.doc.model.ApiErrorCodeDictionary;
import org.beetl.core.Template;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.*;
/**
* @author yu 2020/5/16.
@ -72,19 +70,27 @@ public class BaseDocBuilderTemplate {
}
}
public void setDirectoryLanguageVariable(ApiConfig config, Template mapper) {
if (null != config.getLanguage()) {
public Map<String, String> setDirectoryLanguageVariable(ApiConfig config, Template mapper) {
Map<String, String> titleMap = new HashMap<>();
if (Objects.nonNull(config.getLanguage())) {
if (DocLanguage.CHINESE.code.equals(config.getLanguage().getCode())) {
mapper.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
mapper.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
titleMap.put(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
titleMap.put(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
} else {
mapper.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_EN_TITLE);
mapper.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_EN_TITLE);
titleMap.put(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_EN_TITLE);
titleMap.put(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_EN_TITLE);
}
} else {
mapper.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
mapper.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
titleMap.put(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
titleMap.put(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
}
return titleMap;
}
public List<ApiErrorCode> errorCodeDictToList(ApiConfig config) {

View File

@ -22,6 +22,7 @@
*/
package com.power.doc.builder.rpc;
import com.power.common.util.CollectionUtil;
import com.power.common.util.DateTimeUtil;
import com.power.common.util.FileUtil;
import com.power.doc.builder.BaseDocBuilderTemplate;
@ -38,7 +39,9 @@ import com.power.doc.utils.DocUtil;
import com.thoughtworks.qdox.JavaProjectBuilder;
import org.beetl.core.Template;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static com.power.doc.constants.DocGlobalConstants.FILE_SEPARATOR;
@ -50,6 +53,8 @@ public class RpcDocBuilderTemplate extends BaseDocBuilderTemplate {
private static long now = System.currentTimeMillis();
private static final String DEPENDENCY_TITLE = "Add dependency";
/**
* Generate api documentation for all controllers.
*
@ -101,10 +106,46 @@ public class RpcDocBuilderTemplate extends BaseDocBuilderTemplate {
tpl.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime);
tpl.binding(TemplateVariable.PROJECT_NAME.getVariable(), config.getProjectName());
tpl.binding(TemplateVariable.RPC_CONSUMER_CONFIG.getVariable(), rpcConfigConfigContent);
setDirectoryLanguageVariable(config, tpl);
FileUtil.nioWriteFile(tpl.render(), outPath + FILE_SEPARATOR + outPutFileName);
}
/**
* Build search js
*
* @param apiDocList list data of Api doc
* @param config api config
* @param template template
* @param outPutFileName output file
*/
public void buildSearchJs(List<RpcApiDoc> apiDocList, ApiConfig config, String template, String outPutFileName) {
List<ApiErrorCode> errorCodeList = errorCodeDictToList(config);
Template tpl = BeetlTemplateUtil.getByName(template);
// directory tree
List<RpcApiDoc> apiDocs = new ArrayList<>();
RpcApiDoc apiDoc = new RpcApiDoc();
apiDoc.setAlias(DEPENDENCY_TITLE);
apiDoc.setOrder(1);
apiDoc.setDesc(DEPENDENCY_TITLE);
apiDoc.setList(new ArrayList<>(0));
apiDocs.add(apiDoc);
List<RpcApiDoc> apiDocs1 = apiDocList;
for (RpcApiDoc apiDoc1 : apiDocs1) {
apiDoc1.setOrder(apiDocs.size() + 1);
apiDocs.add(apiDoc1);
}
Map<String, String> titleMap = setDirectoryLanguageVariable(config, tpl);
if (CollectionUtil.isNotEmpty(errorCodeList)) {
RpcApiDoc apiDoc1 = new RpcApiDoc();
apiDoc1.setOrder(apiDocs.size() + 1);
apiDoc1.setDesc(titleMap.get(TemplateVariable.ERROR_LIST_TITLE.getVariable()));
apiDoc1.setList(new ArrayList<>(0));
apiDocs.add(apiDoc1);
}
tpl.binding(TemplateVariable.DIRECTORY_TREE.getVariable(), apiDocs);
FileUtil.nioWriteFile(tpl.render(), config.getOutPath() + FILE_SEPARATOR + outPutFileName);
}
/**
* build error_code adoc
*

View File

@ -22,14 +22,9 @@
*/
package com.power.doc.builder.rpc;
import com.power.common.util.CollectionUtil;
import com.power.common.util.DateTimeUtil;
import com.power.common.util.FileUtil;
import com.power.doc.builder.ProjectDocConfigBuilder;
import com.power.doc.constants.DocLanguage;
import com.power.doc.constants.TemplateVariable;
import com.power.doc.model.ApiConfig;
import com.power.doc.model.ApiErrorCode;
import com.power.doc.model.rpc.RpcApiDoc;
import com.power.doc.template.RpcDocBuildTemplate;
import com.power.doc.utils.BeetlTemplateUtil;
@ -49,6 +44,8 @@ public class RpcHtmlBuilder {
private static String INDEX_HTML = "rpc-index.html";
private static String SEARCH_JS = "search.js";
/**
* build controller api
@ -74,138 +71,9 @@ public class RpcHtmlBuilder {
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder);
RpcDocBuildTemplate docBuildTemplate = new RpcDocBuildTemplate();
List<RpcApiDoc> apiDocList = docBuildTemplate.getApiData(configBuilder);
if (config.isAllInOne()) {
Template indexCssTemplate = BeetlTemplateUtil.getByName(ALL_IN_ONE_CSS);
FileUtil.nioWriteFile(indexCssTemplate.render(), config.getOutPath() + FILE_SEPARATOR + ALL_IN_ONE_CSS);
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, RPC_ALL_IN_ONE_HTML_TPL, INDEX_HTML);
} else {
buildIndex(apiDocList, config);
copyCss(config.getOutPath());
buildDoc(apiDocList, config.getOutPath());
buildErrorCodeDoc(config.getErrorCodes(), config.getOutPath());
buildDependency(config);
}
}
private static void copyCss(String outPath) {
Template indexCssTemplate = BeetlTemplateUtil.getByName(INDEX_CSS_TPL);
Template mdCssTemplate = BeetlTemplateUtil.getByName(MARKDOWN_CSS_TPL);
FileUtil.nioWriteFile(indexCssTemplate.render(), outPath + FILE_SEPARATOR + INDEX_CSS_TPL);
FileUtil.nioWriteFile(mdCssTemplate.render(), outPath + FILE_SEPARATOR + MARKDOWN_CSS_TPL);
}
/**
* build api.html
*
* @param apiDocList list of api doc
* @param config ApiConfig
*/
private static void buildIndex(List<RpcApiDoc> apiDocList, ApiConfig config) {
FileUtil.mkdirs(config.getOutPath());
Template indexTemplate = BeetlTemplateUtil.getByName(RPC_INDEX_TPL);
if (CollectionUtil.isEmpty(apiDocList)) {
return;
}
RpcApiDoc doc = apiDocList.get(0);
String homePage = doc.getAlias();
indexTemplate.binding(TemplateVariable.HOME_PAGE.getVariable(), homePage);
indexTemplate.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList);
indexTemplate.binding(TemplateVariable.VERSION.getVariable(), now);
indexTemplate.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(), config.getErrorCodes());
indexTemplate.binding(TemplateVariable.DICT_LIST.getVariable(), config.getDataDictionaries());
if (CollectionUtil.isEmpty(config.getErrorCodes())) {
indexTemplate.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 2);
} else {
indexTemplate.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 3);
}
if (null != config.getLanguage()) {
if (DocLanguage.CHINESE.code.equals(config.getLanguage().getCode())) {
indexTemplate.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), ERROR_CODE_LIST_CN_TITLE);
} else {
indexTemplate.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), ERROR_CODE_LIST_EN_TITLE);
}
} else {
indexTemplate.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), ERROR_CODE_LIST_CN_TITLE);
}
FileUtil.nioWriteFile(indexTemplate.render(), config.getOutPath() + FILE_SEPARATOR + "rpc-api.html");
}
/**
* build ever controller api
*
* @param apiDocList list of api doc
* @param outPath output path
*/
private static void buildDoc(List<RpcApiDoc> apiDocList, String outPath) {
FileUtil.mkdirs(outPath);
Template htmlApiDoc;
String strTime = DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND);
for (RpcApiDoc rpcDoc : apiDocList) {
Template apiTemplate = BeetlTemplateUtil.getByName(RPC_API_DOC_MD_TPL);
apiTemplate.binding(TemplateVariable.DESC.getVariable(), rpcDoc.getDesc());
apiTemplate.binding(TemplateVariable.NAME.getVariable(), rpcDoc.getName());
apiTemplate.binding(TemplateVariable.LIST.getVariable(), rpcDoc.getList());
apiTemplate.binding(TemplateVariable.PROTOCOL.getVariable(), rpcDoc.getProtocol());
apiTemplate.binding(TemplateVariable.AUTHOR.getVariable(), rpcDoc.getAuthor());
apiTemplate.binding(TemplateVariable.VERSION.getVariable(), rpcDoc.getVersion());
apiTemplate.binding(TemplateVariable.URI.getVariable(), rpcDoc.getUri());
// htmlApiDoc = BeetlTemplateUtil.getByName(HTML_API_DOC_TPL);
// htmlApiDoc.binding(TemplateVariable.HTML.getVariable(), html);
// htmlApiDoc.binding(TemplateVariable.TITLE.getVariable(), rpcDoc.getDesc());
// htmlApiDoc.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime);
// htmlApiDoc.binding(TemplateVariable.VERSION.getVariable(), now);
// FileUtil.nioWriteFile(htmlApiDoc.render(), outPath + FILE_SEPARATOR + rpcDoc.getShortName() + ".html");
}
}
/**
* build error_code html
*
* @param errorCodeList list of error code
* @param outPath
*/
private static void buildErrorCodeDoc(List<ApiErrorCode> errorCodeList, String outPath) {
// if (CollectionUtil.isNotEmpty(errorCodeList)) {
// Template error = BeetlTemplateUtil.getByName(ERROR_CODE_LIST_MD_TPL);
// error.binding(TemplateVariable.LIST.getVariable(), errorCodeList);
// String errorHtml = MarkDownUtil.toHtml(error.render());
// Template errorCodeDoc = BeetlTemplateUtil.getByName(HTML_API_DOC_TPL);
// errorCodeDoc.binding(TemplateVariable.VERSION.getVariable(), now);
// errorCodeDoc.binding(TemplateVariable.HTML.getVariable(), errorHtml);
// errorCodeDoc.binding(TemplateVariable.TITLE.getVariable(), ERROR_CODE_LIST_EN_TITLE);
// errorCodeDoc.binding(TemplateVariable.CREATE_TIME.getVariable(), DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND));
// FileUtil.nioWriteFile(errorCodeDoc.render(), outPath + FILE_SEPARATOR + "error_code.html");
// }
}
/**
* build dictionary
*
* @param apiDocDictList dictionary list
* @param outPath
*/
private static void buildDependency(ApiConfig config) {
// List<RpcApiDependency> apiDependencies = config.getRpcApiDependencies();
// Template template;
// if (CollectionUtil.isNotEmpty(config.getRpcApiDependencies())) {
// String rpcConfig = config.getRpcConsumerConfig();
// String rpcConfigConfigContent = null;
// if (Objects.nonNull(rpcConfig)) {
// rpcConfigConfigContent = FileUtil.getFileContent(rpcConfig);
// }
// template = BeetlTemplateUtil.getByName(RPC_DEPENDENCY_MD_TPL);
// template.binding(TemplateVariable.RPC_CONSUMER_CONFIG.getVariable(), rpcConfigConfigContent);
// template.binding(TemplateVariable.DEPENDENCY_LIST.getVariable(), apiDependencies);
// } else {
// template = BeetlTemplateUtil.getByName(RPC_DEPENDENCY_EMPTY_MD_TPL);
// }
// String dictHtml = MarkDownUtil.toHtml(template.render());
// Template dictTpl = BeetlTemplateUtil.getByName(HTML_API_DOC_TPL);
// dictTpl.binding(TemplateVariable.VERSION.getVariable(), now);
// dictTpl.binding(TemplateVariable.TITLE.getVariable(), DICT_EN_TITLE);
// dictTpl.binding(TemplateVariable.HTML.getVariable(), dictHtml);
// dictTpl.binding(TemplateVariable.CREATE_TIME.getVariable(), DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND));
// FileUtil.nioWriteFile(dictTpl.render(), config.getOutPath() + FILE_SEPARATOR + "dependency.html");
Template indexCssTemplate = BeetlTemplateUtil.getByName(ALL_IN_ONE_CSS);
FileUtil.nioWriteFile(indexCssTemplate.render(), config.getOutPath() + FILE_SEPARATOR + ALL_IN_ONE_CSS);
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, RPC_ALL_IN_ONE_HTML_TPL, INDEX_HTML);
builderTemplate.buildSearchJs(apiDocList, config, RPC_ALL_IN_ONE_SEARCH_TPL, SEARCH_JS);
}
}

View File

@ -72,6 +72,8 @@ public interface DocGlobalConstants {
String RPC_ALL_IN_ONE_HTML_TPL = "dubbo/DubboAllInOne.html";
String RPC_ALL_IN_ONE_SEARCH_TPL = "dubbo/DubboSearch.btl";
String RPC_DEPENDENCY_MD_TPL = "dubbo/DubboApiDependency.md";
String RPC_DEPENDENCY_EMPTY_MD_TPL = "dubbo/DubboApiDependencyEmpty.md";

View File

@ -53,7 +53,8 @@ public enum TemplateVariable {
RESPONSE_EXAMPLE("isResponseExample"),
RESPONSE_LIST("respList"),
ORDER("order"),
INDEX_ALIAS("alias");
INDEX_ALIAS("alias"),
DIRECTORY_TREE("directoryTree");
private String variable;

View File

@ -1,5 +1,6 @@
package com.power.doc.model.rpc;
import com.power.common.util.StringUtil;
import com.power.doc.model.JavaMethodDoc;
import java.util.List;
@ -63,6 +64,11 @@ public class RpcApiDoc implements Comparable<RpcApiDoc> {
*/
private String version;
/**
* link
*/
private String link;
/**
* List of method doc
*/
@ -156,6 +162,14 @@ public class RpcApiDoc implements Comparable<RpcApiDoc> {
this.author = author;
}
public String getLink() {
return desc.replace(" ","_").toLowerCase();
}
public void setLink(String link) {
this.link = link;
}
@Override
public int compareTo(RpcApiDoc o) {
if (Objects.nonNull(o.getDesc())) {

View File

@ -17,7 +17,7 @@
padding: 0em;
}</style>
<script src="https://cdn.bootcdn.net/ajax/libs/highlight.js/10.3.2/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.12.2/jquery.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.5.1/jquery.min.js"></script>
</head>
<body class="book toc2 toc-left">
<div id="header"><%if(isNotEmpty(projectName)){%><h1>${projectName}</h1><%}%>

File diff suppressed because one or more lines are too long

View File

@ -1,210 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width initial-scale=1'>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<link rel="stylesheet" href="index.css?v=${version}"/>
<title>api doc</title>
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1">
<div class="book-summary">
<div id="book-search-input"><input id="search" type="text" placeholder="Type to search"></div>
<nav role="navigation">
<ul class="summary">
<li><ul id="reference">API Reference</ul></li>
<li class="divider"></li>
<div id="doc">
<li class="chapter " data-level="dependency" data-path="dependency.html">
<a href="javascript:void(0)" onclick="go('dependency', 'Add dependency');">1 Add dependency</a>
</li>
<%
for(api in apiDocList){
%>
<li class="chapter " data-level="${api.shortName}" data-path="${api.shortName}.html">
<a href="javascript:void(0)" onclick="go('${api.shortName}', '${api.desc}');">${api.order+1} ${api.desc}</a>
<ul class="articles">
<%
for(doc in api.list){
%>
<li class="chapter " data-level="${api.shortName}" data-path="${api.shortName}.html">
<%if(doc.deprecated){%>
<a href="javascript:void(0)" onclick="go('${api.shortName}', '${doc.desc}');">${api.order+1}.${doc.order}&nbsp;<span class="line-through">${doc.desc}</span></a></li>
<%}else{%>
<a href="javascript:void(0)" onclick="go('${api.shortName}', '${doc.desc}');">${api.order+1}.${doc.order}&nbsp;${doc.desc}</a></li>
<%}%>
<%}%>
</ul>
</li>
<%}%>
</div>
<%if(isNotEmpty(errorCodeList)){%>
<li class="chapter " data-level="error_code" data-path="error_code.html">
<a href="error_code.html?v=${version}" target="book_iframe">${apiDocList.~size+1}. ${errorListTitle}</a>
</li>
<%}%>
<%if(isNotEmpty(dictList)){%>
<li class="chapter " data-level="dict" data-path="dict.html">
<a href="dict.html?v=${version}" target="book_iframe">${dictListOrder}. ${dictListTitle}</a>
<ul class="articles">
<%
for(dict in dictList){
%>
<li class="chapter " data-level="${dict.title}" data-path="dict.html">
<a href="dict.html?v=${version}" target="book_iframe">${dictListOrder}.${dictLP.index} ${dict.title}</a></li>
<%}%>
</ul>
</li>
<%}%>
<li class="divider"></li>
<li class="footer_link"><a href="https://github.com/shalousun/smart-doc" target="_blank" class="gitbook-link">Created by smart-doc</a>
</li>
</ul>
</nav>
</div>
<div id="book-body" class="book-body" height="100%">
<iframe src="${homePage}.html?v=${version}" frameborder="0" id="book_iframe" name="book_iframe" width="100%"></iframe>
</div>
</div>
<script type="text/javascript">
var api = [];
function changeFrameHeight() {
var ifm = document.getElementById("book_iframe");
ifm.height = document.documentElement.clientHeight;
}
function toPage() {
var page = localStorage.getItem('page');
var title = localStorage.getItem('title');
if(page) {
var iframe = document.getElementById("book_iframe");
iframe.src = page + ".html";
var obj = iframe.contentWindow;
obj.onload = function(){
var h2 = obj.document.getElementsByTagName('h2');
for(j = 0; j < h2.length; j++) {
var dom = h2[j];
if(dom.innerText == title){
obj.scroll(0, dom.offsetTop);
break;
}
}
}
}
}
toPage();
function go(alias, desc) {
console.log(alias, desc);
var iframe = document.getElementById("book_iframe");
var page = localStorage.getItem('page');
if(page != alias){
iframe.src = alias + ".html";
}
localStorage.setItem('page', alias);
localStorage.setItem('title', desc);
setTimeout(() => {
var obj = iframe.contentWindow;
var h2 = obj.document.getElementsByTagName('h2');
for(j = 0; j < h2.length; j++) {
var dom = h2[j];
if(dom.innerText == desc){
obj.scroll(0, dom.offsetTop);
break;
}
}
}, 200)
}
changeFrameHeight();
setInterval(function(){changeFrameHeight(); }, 500);
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
var theEvent = e || window.event;
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if (code == 13) {
var search = document.getElementById('search');
var searchArr = [];
<% for(api in apiDocList) { %>
searchArr.push({
alias: '${api.alias}',
order: '${api.order}',
desc: '${api.desc}',
list: []
})
api.push({
alias: '${api.alias}',
order: '${api.order}',
desc: '${api.desc}',
list: []
})
<% for(doc in api.list) { %>
api[${apiLP.dataIndex}].list.push({
order: '${doc.order}',
desc: '${doc.desc}',
});
if('${doc.desc}'.indexOf(search.value) > -1) {
searchArr[${apiLP.dataIndex}].list.push({
order: '${doc.order}',
desc: '${doc.desc}',
});
}
<%}%>
<%}%>
var searchResult = searchArr.filter(obj => obj.list.length > 0);
if(searchResult.length > 0) {
var html = '';
for(j = 0; j < searchResult.length; j++) {
html += '<li class="chapter " data-level="' + searchResult[j].alias + '" data-path="' + searchResult[j].alias + '.html">';
html += ' <a href="javascript:void(0)" onclick="go(\'' + searchResult[j].alias + '\', \'' + searchResult[j].desc + '\');">' + searchResult[j].order + ' ' + searchResult[j].desc + '</a>';
html += ' <ul class="articles">';
var doc = searchResult[j].list;
for(m = 0; m < doc.length; m++) {
html += ' <li class="chapter " data-level="' + searchResult[j].alias + '" data-path="' + searchResult[j].alias + '.html">';
html += ' <a href="javascript:void(0)" onclick="go(\'' + searchResult[j].alias + '\', \'' + doc[m].desc + '\');">' + searchResult[j].order + '.' + doc[m].order + ' ' + doc[m].desc + '</a></li>';
html += ' </li>';
}
html += '</ul>';
}
document.getElementById('doc').innerHTML = html;
} else {
if(search.value == '') {
var html = '';
for(j = 0; j < api.length; j++) {
html += '<li class="chapter " data-level="' + api[j].alias + '" data-path="' + api[j].alias + '.html">';
html += ' <a href="javascript:void(0)" onclick="go(\'' + api[j].alias + '\', \'' + api[j].desc + '\');">' + api[j].order + ' ' +api[j].desc + '</a>';
html += ' <ul class="articles">';
var doc = api[j].list;
for(m = 0; m < doc.length; m++) {
html += ' <li class="chapter " data-level="' + searchResult[j].alias + '" data-path="' + searchResult[j].alias + '.html">';
html += ' <a href="javascript:void(0)" onclick="go(\'' + api[j].alias + '\', \'' + doc[m].desc + '\');">' + searchResult[j].order + '.' + doc[m].order + ' ' + doc[m].desc + '</a></li>';
html += ' </li>';
}
html += '</ul>';
}
document.getElementById('doc').innerHTML = html;
} else {
document.getElementById('doc').innerHTML = '';
}
}
}
}
</script>
</body>
</html>

View File

@ -0,0 +1,102 @@
let api = [];
<%for(api in directoryTree){%>
api.push({
alias: '${api.alias}',
order: '${api.order}',
link: '${api.link}',
desc: '${api.desc}',
list: []
})
<%for(doc in api.list) {%>
api[${apiLP.dataIndex}].list.push({
order: '${doc.order}',
desc: '${doc.desc}',
});
<%}%>
<%}%>
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
const theEvent = e || window.event;
const code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if (code == 13) {
const search = document.getElementById('search');
const searchValue = search.value;
let searchArr = [];
for (let i = 0; i < api.length; i++) {
let apiData = api[i];
const desc = apiData.desc;
if (desc.indexOf(searchValue) > -1) {
searchArr.push({
order: apiData.order,
desc: apiData.desc,
link: apiData.link,
list: apiData.list
});
} else {
let methodList = apiData.list || [];
let methodListTemp = [];
for (let j = 0; j < methodList.length; j++) {
const methodData = methodList[j];
const methodDesc = methodData.desc;
if (methodDesc.indexOf(searchValue) > -1) {
methodListTemp.push(methodData);
break;
}
}
if (methodListTemp.length > 0) {
const data = {
order: apiData.order,
desc: apiData.desc,
link: apiData.link,
list: methodListTemp
};
searchArr.push(data);
}
}
}
let html;
if (searchValue == '') {
html = buildAccordion(api);
console.log(html);
document.getElementById('accordion').innerHTML = html;
} else {
html = buildAccordion(searchArr);
document.getElementById('accordion').innerHTML = html;
}
const Accordion = function (el, multiple) {
this.el = el || {};
this.multiple = multiple || false;
const links = this.el.find('.dd');
links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
};
Accordion.prototype.dropdown = function (e) {
const $el = e.data.el;
$this = $(this), $next = $this.next();
$next.slideToggle();
$this.parent().toggleClass('open');
if (!e.data.multiple) {
$el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
}
};
new Accordion($('#accordion'), false);
}
}
function buildAccordion(apiData) {
let html = "";
let doc;
if (apiData.length > 0) {
for (let j = 0; j < apiData.length; j++) {
html += '<li class="open">';
html += ' <a class="dd" href="#_' + apiData[j].link + '">' + apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
html += ' <ul class="sectlevel2" style="display: block">';
doc = apiData[j].list;
for (let m = 0; m < doc.length; m++) {
html += '<li><a href="#_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + doc[m].desc + '</a> </li>';
}
html += '</ul>';
html += '</li>';
}
}
return html;
}

View File

@ -17,7 +17,7 @@
padding: 0em;
}</style>
<script src="https://cdn.bootcdn.net/ajax/libs/highlight.js/10.3.2/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.12.2/jquery.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.5.1/jquery.min.js"></script>
</head>
<body class="book toc2 toc-left">
<div id="header">

View File

@ -17,7 +17,7 @@
padding: 0em;
}</style>
<script src="https://cdn.bootcdn.net/ajax/libs/highlight.js/10.3.2/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.12.2/jquery.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.5.1/jquery.min.js"></script>
</head>
<body class="book toc2 toc-left">
<div id="header">

View File

@ -18,7 +18,7 @@
}
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/highlight.js/10.3.2/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.12.2/jquery.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.5.1/jquery.min.js"></script>
</head>
<body class="book toc2 toc-left">
<div id="header">

View File

@ -8,7 +8,7 @@
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="AllInOne.css?v=${version}"/>
<script src="https://cdn.bootcss.com/jquery/1.12.2/jquery.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.5.1/jquery.min.js"></script>
</head>
<body class="book toc2 toc-left">
<div id="header">

View File

@ -8,7 +8,7 @@
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="AllInOne.css?v=${version}"/>
<script src="https://cdn.bootcss.com/jquery/1.12.2/jquery.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.5.1/jquery.min.js"></script>
</head>
<body class="book toc2 toc-left">
<div id="header"><%if(isNotEmpty(projectName)){%><h1>${projectName}</h1><%}%>