update dubbo allInOne template
This commit is contained in:
parent
952bec1b05
commit
f0fabb840a
src/main
java/com/power/doc
resources/template/dubbo
|
@ -21,6 +21,7 @@ import static com.power.doc.constants.DocGlobalConstants.FILE_SEPARATOR;
|
|||
public class RpcDocBuilderTemplate extends BaseDocBuilderTemplate {
|
||||
|
||||
private static long now = System.currentTimeMillis();
|
||||
|
||||
/**
|
||||
* Generate api documentation for all controllers.
|
||||
*
|
||||
|
@ -36,10 +37,10 @@ public class RpcDocBuilderTemplate extends BaseDocBuilderTemplate {
|
|||
mapper.binding(TemplateVariable.DESC.getVariable(), rpcDoc.getDesc());
|
||||
mapper.binding(TemplateVariable.NAME.getVariable(), rpcDoc.getName());
|
||||
mapper.binding(TemplateVariable.LIST.getVariable(), rpcDoc.getList());
|
||||
mapper.binding(TemplateVariable.PROTOCOL.getVariable(),rpcDoc.getProtocol());
|
||||
mapper.binding(TemplateVariable.AUTHOR.getVariable(),rpcDoc.getAuthor());
|
||||
mapper.binding(TemplateVariable.VERSION.getVariable(),rpcDoc.getVersion());
|
||||
mapper.binding(TemplateVariable.URI.getVariable(),rpcDoc.getUri());
|
||||
mapper.binding(TemplateVariable.PROTOCOL.getVariable(), rpcDoc.getProtocol());
|
||||
mapper.binding(TemplateVariable.AUTHOR.getVariable(), rpcDoc.getAuthor());
|
||||
mapper.binding(TemplateVariable.VERSION.getVariable(), rpcDoc.getVersion());
|
||||
mapper.binding(TemplateVariable.URI.getVariable(), rpcDoc.getUri());
|
||||
FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + rpcDoc.getShortName() + fileExtension);
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +63,7 @@ public class RpcDocBuilderTemplate extends BaseDocBuilderTemplate {
|
|||
tpl.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList);
|
||||
tpl.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(), errorCodeList);
|
||||
tpl.binding(TemplateVariable.VERSION_LIST.getVariable(), config.getRevisionLogs());
|
||||
tpl.binding(TemplateVariable.DEPENDENCY_LIST.getVariable(),config.getRpcApiDependencies());
|
||||
tpl.binding(TemplateVariable.DEPENDENCY_LIST.getVariable(), config.getRpcApiDependencies());
|
||||
tpl.binding(TemplateVariable.VERSION.getVariable(), now);
|
||||
tpl.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime);
|
||||
tpl.binding(TemplateVariable.PROJECT_NAME.getVariable(), config.getProjectName());
|
||||
|
|
|
@ -80,7 +80,7 @@ public class RpcHtmlBuilder {
|
|||
*/
|
||||
private static void buildIndex(List<RpcApiDoc> apiDocList, ApiConfig config) {
|
||||
FileUtil.mkdirs(config.getOutPath());
|
||||
Template indexTemplate = BeetlTemplateUtil.getByName(INDEX_TPL);
|
||||
Template indexTemplate = BeetlTemplateUtil.getByName(RPC_INDEX_TPL);
|
||||
if (CollectionUtil.isEmpty(apiDocList)) {
|
||||
return;
|
||||
}
|
||||
|
@ -92,9 +92,9 @@ public class RpcHtmlBuilder {
|
|||
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() + 1);
|
||||
} else {
|
||||
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())) {
|
||||
|
@ -105,7 +105,7 @@ public class RpcHtmlBuilder {
|
|||
} else {
|
||||
indexTemplate.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), ERROR_CODE_LIST_CN_TITLE);
|
||||
}
|
||||
FileUtil.nioWriteFile(indexTemplate.render(), config.getOutPath() + FILE_SEPARATOR + "api.html");
|
||||
FileUtil.nioWriteFile(indexTemplate.render(), config.getOutPath() + FILE_SEPARATOR + "rpc-api.html");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,7 +119,7 @@ public class RpcHtmlBuilder {
|
|||
Template htmlApiDoc;
|
||||
String strTime = DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND);
|
||||
for (RpcApiDoc rpcDoc : apiDocList) {
|
||||
Template apiTemplate = BeetlTemplateUtil.getByName(API_DOC_MD_TPL);
|
||||
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());
|
||||
|
@ -174,7 +174,7 @@ public class RpcHtmlBuilder {
|
|||
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(), outPath + FILE_SEPARATOR + "dict.html");
|
||||
FileUtil.nioWriteFile(dictTpl.render(), outPath + FILE_SEPARATOR + "dependency.html");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public interface DocGlobalConstants {
|
|||
|
||||
String RPC_ALL_IN_ONE_ADOC_TPL = "dubbo/DubboAllInOne.adoc";
|
||||
|
||||
String RPC_ALL_IN_ONE_HTML_TPL = "AllInOne.html";
|
||||
String RPC_ALL_IN_ONE_HTML_TPL = "dubbo/DubboAllInOne.html";
|
||||
|
||||
String ALL_IN_ONE_HTML_TPL = "AllInOne.html";
|
||||
|
||||
|
@ -47,7 +47,7 @@ public interface DocGlobalConstants {
|
|||
|
||||
String DICT_LIST_MD_TPL = "Dictionary.btl";
|
||||
|
||||
String RPC_DEPENDENCY_MD_TPL = "dubbo/DubboApiDependency.html";
|
||||
String RPC_DEPENDENCY_MD_TPL = "dubbo/DubboApiDependency.md";
|
||||
|
||||
String DICT_LIST_ADOC = "Dictionary.adoc";
|
||||
|
||||
|
@ -55,6 +55,8 @@ public interface DocGlobalConstants {
|
|||
|
||||
String INDEX_TPL = "Index.btl";
|
||||
|
||||
String RPC_INDEX_TPL = "dubbo/DubboIndex.btl";
|
||||
|
||||
String INDEX_CSS_TPL = "index.css";
|
||||
|
||||
String MARKDOWN_CSS_TPL = "markdown.css";
|
||||
|
|
|
@ -14,22 +14,25 @@
|
|||
<div id="header"><%if(isNotEmpty(projectName)){%><h1>${projectName}</h1><%}%>
|
||||
<div id="toc" class="toc2">
|
||||
<div id="toctitle"><span>API Reference</span></div>
|
||||
<ul id="accordion" class="sectlevel1"><%for(api in apiDocList){%><%if(apiLP.first){%>
|
||||
<li class="open"><a class="dd" href="#_${api.desc}">${api.order}. ${api.desc}</a>
|
||||
<ul id="accordion" class="sectlevel1">
|
||||
<li><a href="#_add_dependency">1. Add dependency</a></li>
|
||||
<%for(api in apiDocList){%>
|
||||
<%if(apiLP.first){%>
|
||||
<li class="open"><a class="dd" href="#_${api.desc}">${api.order+1}. ${api.desc}</a>
|
||||
<ul class="sectlevel2" style="display: block"><%for(doc in api.list){%>
|
||||
<li><%if(doc.deprecated){%><a href="#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}. <span
|
||||
<li><%if(doc.deprecated){%><a href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}. <span
|
||||
class="line-through">${doc.desc}</span></a><%}else{%><a
|
||||
href="#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}. ${doc.desc}</a><%}%>
|
||||
href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}. ${doc.desc}</a><%}%>
|
||||
</li>
|
||||
<%}%>
|
||||
</ul>
|
||||
</li>
|
||||
<%}else{%>
|
||||
<li><a class="dd" href="#_${api.desc}">${api.order}. ${api.desc}</a>
|
||||
<li><a class="dd" href="#_${api.desc}">${api.order+1}. ${api.desc}</a>
|
||||
<ul class="sectlevel2"><%for(doc in api.list){%>
|
||||
<li><%if(doc.deprecated){%><a href="#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}. <span
|
||||
<li><%if(doc.deprecated){%><a href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}. <span
|
||||
class="line-through">${doc.desc}</span></a><%}else{%><a
|
||||
href="#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}. ${doc.desc}</a><%}%>
|
||||
href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}. ${doc.desc}</a><%}%>
|
||||
</li>
|
||||
<%}%>
|
||||
</ul>
|
||||
|
@ -83,56 +86,58 @@
|
|||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<%}%><%for(api in apiDocList){%>
|
||||
<%}%>
|
||||
<%if(isNotEmpty(dependencyList)){%>
|
||||
<div class="sect1">
|
||||
<h2 id="_add_dependency"><a class="anchor" href="#_add_dependency"></a><a class="link" href="#_add_dependency">1.
|
||||
Add dependency</a></h2>
|
||||
<div class="sectionbody">
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><%for(dp in dependencyList){%><dependency>
|
||||
<groupId>${dp.groupId}</groupId>
|
||||
<artifactId>${dp.artifactId}</artifactId>
|
||||
<version>${dp.version}</version>
|
||||
</dependency>
|
||||
<%}%>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%}%>
|
||||
|
||||
<%for(api in apiDocList){%>
|
||||
<div class="sect1"><h2 id="_${api.desc}"><a class="anchor" href="#_${api.desc}"></a><a class="link"
|
||||
href="#_${api.desc}">${api.order}. ${api.desc}</a>
|
||||
href="#_${api.desc}">${api.order+1}. ${api.desc}</a>
|
||||
</h2>
|
||||
<div class="sectionbody"><%for(doc in api.list){%>
|
||||
<div class="sect2"><h3 id="_${api.order}_${doc.order}_${doc.desc}"><a class="anchor"
|
||||
href="#_${api.order}_${doc.order}_${doc.desc}"></a><%if(doc.deprecated){%><a
|
||||
class="link" href="#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}. <span
|
||||
<div class="sectionbody">
|
||||
<div class="paragraph">
|
||||
<p><strong>URI:</strong> ${api.uri}</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><strong>Service:</strong> ${api.name}</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><strong>Protocol:</strong> ${api.protocol}</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><strong>Author:</strong> ${api.author}</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><strong>Version:</strong> ${api.version}</p>
|
||||
</div>
|
||||
<%for(doc in api.list){%>
|
||||
<div class="sect2"><h3 id="_${api.order+1}_${doc.order}_${doc.desc}"><a class="anchor"
|
||||
href="#_${api.order+1}_${doc.order}_${doc.desc}"></a><%if(doc.deprecated){%><a
|
||||
class="link" href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}. <span
|
||||
class="line-through">${doc.desc}</span></a><%}else{%><a class="link"
|
||||
href="#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}. ${doc.desc}</a><%}%>
|
||||
href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}. ${doc.desc}</a><%}%>
|
||||
</h3>
|
||||
<div class="paragraph"><p><strong>URL:</strong><a href="${doc.url}" class="bare"> ${doc.url}</a>
|
||||
<div class="paragraph"><p><strong>Definition:</strong><a href="${doc.methodDefinition}" class="bare"> ${doc.methodDefinition}</a>
|
||||
</p></div>
|
||||
<div class="paragraph"><p><strong>Type:</strong> ${doc.type}</p></div>
|
||||
<%if(isNotEmpty(doc.author)){%>
|
||||
<div class="paragraph"><p><strong>Author:</strong> ${doc.author}</p></div>
|
||||
<%}%>
|
||||
<div class="paragraph"><p><strong>Content-Type:</strong> ${doc.contentType}</p></div>
|
||||
<div class="paragraph"><p><strong>Description:</strong> ${doc.detail}</p></div>
|
||||
<%if(isNotEmpty(doc.requestHeaders)){%>
|
||||
<div class="paragraph"><p><strong>Request-headers:</strong></p></div>
|
||||
<table class="tableblock frame-all grid-all spread">
|
||||
<colgroup>
|
||||
<col style="width: 20%;">
|
||||
<col style="width: 20%;">
|
||||
<col style="width: 20%;">
|
||||
<col style="width: 20%;">
|
||||
<col style="width: 20%;">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="tableblock halign-left valign-top">Header</th>
|
||||
<th class="tableblock halign-left valign-top">Type</th>
|
||||
<th class="tableblock halign-left valign-top">Description</th>
|
||||
<th class="tableblock halign-left valign-top">Required</th>
|
||||
<th class="tableblock halign-left valign-top">Since</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><%for(header in doc.requestHeaders){%>
|
||||
<tr>
|
||||
<td class="tableblock halign-left valign-top"><p class="tableblock">${header.name}</p></td>
|
||||
<td class="tableblock halign-left valign-top"><p class="tableblock">${header.type}</p></td>
|
||||
<td class="tableblock halign-left valign-top"><p class="tableblock">${header.desc}</p></td>
|
||||
<td class="tableblock halign-left valign-top"><p class="tableblock">${header.required}</p></td>
|
||||
<td class="tableblock halign-left valign-top"><p class="tableblock">${header.since}</p></td>
|
||||
</tr>
|
||||
<%}%>
|
||||
</tbody>
|
||||
</table>
|
||||
<%}%><%if(isNotEmpty(doc.requestParams)){%>
|
||||
<%if(isNotEmpty(doc.requestParams)){%>
|
||||
<div class="paragraph"><p><strong>Request-parameters:</strong></p></div>
|
||||
<table class="tableblock frame-all grid-all spread">
|
||||
<colgroup>
|
||||
|
@ -162,14 +167,8 @@
|
|||
<%}%>
|
||||
</tbody>
|
||||
</table>
|
||||
<%}%><%if(isNotEmpty(doc.requestUsage)){%>
|
||||
<div class="paragraph"><p><strong>Request-example:</strong></p></div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre>${doc.requestUsage}</pre>
|
||||
</div>
|
||||
</div>
|
||||
<%}%><%if(isNotEmpty(doc.responseParams)){%>
|
||||
<%}%>
|
||||
<%if(isNotEmpty(doc.responseParams)){%>
|
||||
<div class="paragraph"><p><strong>Response-fields:</strong></p></div>
|
||||
<table class="tableblock frame-all grid-all spread">
|
||||
<colgroup>
|
||||
|
@ -197,21 +196,14 @@
|
|||
</tbody>
|
||||
</table>
|
||||
<%}%>
|
||||
<%if(isNotEmpty(doc.responseUsage)){%>
|
||||
<div class="paragraph"><p><strong>Response-example:</strong></p></div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre>${doc.responseUsage}</pre>
|
||||
</div>
|
||||
</div>
|
||||
<%}%>
|
||||
</div>
|
||||
<%}%>
|
||||
</div>
|
||||
</div>
|
||||
<%}%><%if(isNotEmpty(errorCodeList)){%>
|
||||
<%}%>
|
||||
<%if(isNotEmpty(errorCodeList)){%>
|
||||
<div class="sect1"><h2 id="_error_code_list"><a class="anchor" href="#_error_code_list"></a><a class="link"
|
||||
href="#_error_code_list">${apiDocList.~size+1}. ${errorListTitle}</a>
|
||||
href="#_error_code_list">${apiDocList.~size+2}. ${errorListTitle}</a>
|
||||
</h2>
|
||||
<div class="sectionbody">
|
||||
<table class="tableblock frame-all grid-all spread">
|
||||
|
@ -236,20 +228,6 @@
|
|||
</div>
|
||||
</div>
|
||||
<%}%>
|
||||
<%}%>
|
||||
<%if(isNotEmpty(dependencyList)){%>
|
||||
<div class="sect1"><h2 id="_dependencies"><a class="anchor" href="#_dependencies"></a><a class="link"
|
||||
href="#_dependencies">${apiDocList.~size+1}. ${errorListTitle}</a>
|
||||
</h2>
|
||||
<div class="sectionbody">
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre>添加依赖</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%}%>
|
||||
<footer class="page-footer"><span class="copyright">Generated by smart-doc at ${createTime}</span><span
|
||||
class="footer-modification">Suggestions,contact,support and error reporting on<a
|
||||
href="https://gitee.com/sunyurepository/smart-doc" target="_blank"> Gitee</a> or<a
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# Add dependency
|
||||
|
||||
```
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.qdox</groupId>
|
||||
<artifactId>qdox</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
```
|
|
@ -0,0 +1,210 @@
|
|||
<!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.alias}" data-path="${api.alias}.html">
|
||||
<a href="javascript:void(0)" onclick="go('${api.alias}', '${api.desc}');">${api.order+1} ${api.desc}</a>
|
||||
<ul class="articles">
|
||||
<%
|
||||
for(doc in api.list){
|
||||
%>
|
||||
<li class="chapter " data-level="${api.alias}" data-path="${api.alias}.html">
|
||||
<%if(doc.deprecated){%>
|
||||
<a href="javascript:void(0)" onclick="go('${api.alias}', '${doc.desc}');">${api.order+1}.${doc.order} <span class="line-through">${doc.desc}</span></a></li>
|
||||
<%}else{%>
|
||||
<a href="javascript:void(0)" onclick="go('${api.alias}', '${doc.desc}');">${api.order+1}.${doc.order} ${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>
|
Loading…
Reference in New Issue