fix url path and add cache fresh for html
This commit is contained in:
parent
b06cd38efb
commit
fe7740637c
|
@ -24,6 +24,7 @@ import static com.power.doc.constants.DocGlobalConstants.*;
|
|||
*/
|
||||
public class HtmlApiDocBuilder {
|
||||
|
||||
private static long now = System.currentTimeMillis();
|
||||
/**
|
||||
* @param config 配置
|
||||
*/
|
||||
|
@ -62,6 +63,7 @@ public class HtmlApiDocBuilder {
|
|||
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);
|
||||
if (null != config.getLanguage()) {
|
||||
if (DocLanguage.CHINESE.code.equals(config.getLanguage().getCode())) {
|
||||
indexTemplate.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), "A. 错误码列表");
|
||||
|
@ -84,6 +86,7 @@ public class HtmlApiDocBuilder {
|
|||
private static void buildApiDoc(List<ApiDoc> apiDocList, String outPath) {
|
||||
FileUtil.mkdirs(outPath);
|
||||
Template htmlApiDoc;
|
||||
String strTime = DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND);
|
||||
for (ApiDoc doc : apiDocList) {
|
||||
Template apiTemplate = BeetlTemplateUtil.getByName(API_DOC_TPL);
|
||||
apiTemplate.binding(TemplateVariable.DESC.getVariable(), doc.getDesc());
|
||||
|
@ -93,9 +96,9 @@ public class HtmlApiDocBuilder {
|
|||
String html = MarkDownUtil.toHtml(apiTemplate.render());
|
||||
htmlApiDoc = BeetlTemplateUtil.getByName(HTML_API_DOC_TPL);
|
||||
htmlApiDoc.binding(TemplateVariable.HTML.getVariable(), html);
|
||||
htmlApiDoc.binding(TemplateVariable.TITLE.getVariable(),doc.getDesc());
|
||||
htmlApiDoc.binding(TemplateVariable.CREATE_TIME.getVariable(), DateTimeUtil.long2Str(System.currentTimeMillis()
|
||||
, DateTimeUtil.DATE_FORMAT_SECOND));
|
||||
htmlApiDoc.binding(TemplateVariable.TITLE.getVariable(), doc.getDesc());
|
||||
htmlApiDoc.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime);
|
||||
htmlApiDoc.binding(TemplateVariable.VERSION.getVariable(), now);
|
||||
FileUtil.nioWriteFile(htmlApiDoc.render(), outPath + FILE_SEPARATOR + doc.getAlias() + ".html");
|
||||
}
|
||||
}
|
||||
|
@ -112,10 +115,10 @@ public class HtmlApiDocBuilder {
|
|||
error.binding(TemplateVariable.LIST.getVariable(), errorCodeList);//类名
|
||||
String errorHtml = MarkDownUtil.toHtml(error.render());
|
||||
Template errorCodeDoc = BeetlTemplateUtil.getByName(HTML_API_DOC_TPL);
|
||||
errorCodeDoc.binding(TemplateVariable.TITLE.getVariable(),"error code");
|
||||
errorCodeDoc.binding(TemplateVariable.VERSION.getVariable(), now);
|
||||
errorCodeDoc.binding(TemplateVariable.TITLE.getVariable(), "error code");
|
||||
errorCodeDoc.binding(TemplateVariable.HTML.getVariable(), errorHtml);
|
||||
errorCodeDoc.binding(TemplateVariable.CREATE_TIME.getVariable(), DateTimeUtil.long2Str(System.currentTimeMillis()
|
||||
, DateTimeUtil.DATE_FORMAT_SECOND));
|
||||
errorCodeDoc.binding(TemplateVariable.CREATE_TIME.getVariable(), DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND));
|
||||
FileUtil.nioWriteFile(errorCodeDoc.render(), outPath + FILE_SEPARATOR + "error_code.html");
|
||||
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ package com.power.doc.builder;
|
|||
|
||||
import com.power.common.util.*;
|
||||
import com.power.doc.constants.DocAnnotationConstants;
|
||||
import com.power.doc.constants.DocTags;
|
||||
import com.power.doc.constants.DocGlobalConstants;
|
||||
import com.power.doc.constants.DocTags;
|
||||
import com.power.doc.model.*;
|
||||
import com.power.doc.utils.DocClassUtil;
|
||||
import com.power.doc.utils.DocUtil;
|
||||
import com.power.doc.utils.PathUtil;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
import com.thoughtworks.qdox.model.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
@ -274,13 +274,8 @@ public class SourceBuilder {
|
|||
}
|
||||
url = url.replaceAll("\"", "").trim();
|
||||
apiMethodDoc.setType(methodType);
|
||||
if (StringUtil.isNotEmpty(baseUrl)) {
|
||||
baseUrl = StringUtils.equals("/", baseUrl.subSequence(0, 1)) ? baseUrl : "/" + baseUrl;
|
||||
apiMethodDoc.setUrl(this.appUrl + (baseUrl + "/" + url).replace("//", "/"));
|
||||
} else {
|
||||
url = StringUtils.equals("/", url.subSequence(0, 1)) ? url : "/" + url;
|
||||
apiMethodDoc.setUrl(this.appUrl + (url).replace("//", "/"));
|
||||
}
|
||||
url = this.appUrl + "/" + baseUrl + "/" + url;
|
||||
apiMethodDoc.setUrl(PathUtil.processHttpUrl(url));
|
||||
String comment = getCommentTag(method, "param", cls.getCanonicalName());
|
||||
apiMethodDoc.setRequestParams(comment);
|
||||
String requestJson = buildReqJson(method, apiMethodDoc);
|
||||
|
@ -320,7 +315,7 @@ public class SourceBuilder {
|
|||
}
|
||||
|
||||
private String buildMethodReturn(JavaMethod method, String controllerName) {
|
||||
ApiReturn apiReturn = DocClassUtil.processReturnType( method.getReturnType().getGenericCanonicalName());
|
||||
ApiReturn apiReturn = DocClassUtil.processReturnType(method.getReturnType().getGenericCanonicalName());
|
||||
String returnType = apiReturn.getGenericCanonicalName();
|
||||
String typeName = apiReturn.getSimpleName();
|
||||
if (DocClassUtil.isMvcIgnoreParams(typeName)) {
|
||||
|
|
|
@ -14,7 +14,8 @@ public enum TemplateVariable {
|
|||
HTML("html"),
|
||||
TITLE("title"),
|
||||
ERROR_LIST_TITLE("errorListTitle"),
|
||||
CREATE_TIME("createTime");
|
||||
CREATE_TIME("createTime"),
|
||||
VERSION("version");
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -24,4 +24,16 @@ public class PathUtil {
|
|||
className = className.replaceAll("\\.", "\\" + File.separator);
|
||||
return parentDir + className + ".java";
|
||||
}
|
||||
|
||||
/**
|
||||
* process http url
|
||||
* @param url url
|
||||
* @return String
|
||||
*/
|
||||
public static String processHttpUrl(String url) {
|
||||
int index = url.indexOf("//");
|
||||
String urlHead = url.substring(0, index + 2);
|
||||
String urlTail = url.substring(index + 2, url.length()).replaceAll("/+", "/");
|
||||
return new StringBuilder().append(urlHead).append(urlTail).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<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="markdown.css"/>
|
||||
<link rel="stylesheet" href="markdown.css?v=${version}"/>
|
||||
<title>${title}</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<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"/>
|
||||
<link rel="stylesheet" href="index.css?v=${version}"/>
|
||||
<title>api doc</title>
|
||||
</head>
|
||||
<div class="book without-animation with-summary font-size-2 font-family-1">
|
||||
|
@ -20,19 +20,19 @@
|
|||
for(api in apiDocList){
|
||||
%>
|
||||
<li class="chapter " data-level="${api.alias}" data-path="${api.alias}.html">
|
||||
<a href="${api.alias}.html" target="book_iframe">${api.order}. ${api.desc}</a>
|
||||
<a href="${api.alias}.html?v=${version}" target="book_iframe">${api.order}. ${api.desc}</a>
|
||||
<ul class="articles">
|
||||
<%
|
||||
for(doc in api.list){
|
||||
%>
|
||||
<li class="chapter " data-level="${api.alias}" data-path="${api.alias}.html">
|
||||
<a href="${api.alias}.html" target="book_iframe">${api.order}.${doc.order} ${doc.desc}</a></li>
|
||||
<a href="${api.alias}.html?v=${version}" target="book_iframe">${api.order}.${doc.order} ${doc.desc}</a></li>
|
||||
<%}%>
|
||||
</ul>
|
||||
</li>
|
||||
<%}%>
|
||||
<li class="chapter " data-level="error_code" data-path="error_code.html">
|
||||
<a href="error_code.html" target="book_iframe">${errorListTitle}</a>
|
||||
<a href="error_code.html?v=${version}" target="book_iframe">${errorListTitle}</a>
|
||||
</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>
|
||||
|
@ -41,7 +41,7 @@
|
|||
</nav>
|
||||
</div>
|
||||
<div id="book-body" class="book-body" height="100%">
|
||||
<iframe src="${homePage}.html" frameborder="0" id="book_iframe" name="book_iframe" width="100%"></iframe>
|
||||
<iframe src="${homePage}.html?v=${version}" frameborder="0" id="book_iframe" name="book_iframe" width="100%"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
|
|
Loading…
Reference in New Issue