This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-website.git
The following commit(s) were added to refs/heads/master by this push:
new fa08073 fix: lastmod time (#237)
fa08073 is described below
commit fa08073944e216e77e5960612555af000d1773b3
Author: Juntao Zhang <[email protected]>
AuthorDate: Wed Mar 3 23:19:34 2021 +0800
fix: lastmod time (#237)
---
config.toml | 2 +-
docs.js | 23 +++++++++++++----------
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/config.toml b/config.toml
index 4f0f0cc..2ab9841 100644
--- a/config.toml
+++ b/config.toml
@@ -10,7 +10,7 @@ theme = ["docsy"]
enableGitInfo = true
[frontmatter]
-lastmod = [":git", ":fileModTime", "lastmod", ":default"]
+lastmod = [":git", "date", "lastmod", ":default"]
# Language settings
contentDir = "content"
defaultContentLanguage = "en"
diff --git a/docs.js b/docs.js
index 9b83755..ff898fb 100644
--- a/docs.js
+++ b/docs.js
@@ -11,13 +11,13 @@ const layoutTemplateFile =
'/themes/docsy/layouts/projectDoc/baseof.html';
init();
async function init() {
- try{
+ try {
const targetPath = path.join(__dirname, layoutTemplateFile)
const result = await loadYaml(docConfig)
const {tpl, docsInfo} = await traverseDocsList(result)
await generateLayoutTemplate(targetPath, tpl)
handleDocsFiles(docsInfo)
- }catch (err){
+ } catch (err) {
console.log(err);
process.exit(1)
}
@@ -55,7 +55,7 @@ function readFile(filePath, docInfo, replaceMarkdownText) {
function replaceMarkdownText(codeTxt, docInfo, filePath) {
if (!/^([\s]*)(---[\s\S]*---)/.test(codeTxt)) {
- const {repoUrl, commitId} = docInfo;
+ const {repoUrl, commitId, date} = docInfo;
const prefix = repoUrl.replace('.git', '/tree') + `/${commitId}`;
const depth = filePath.split('/docs')[1].match(/\//g).length - 2;
@@ -66,6 +66,7 @@ function replaceMarkdownText(codeTxt, docInfo, filePath) {
codeTxt =
`---
title: ${title}
+date: ${date}
type: projectDoc
layout: baseof
---\n` + codeTxt;
@@ -117,19 +118,21 @@ async function traverseDocsList(result) {
for (const doc of item.docs) {
const {repo, repoUrl} = item;
let {version, commitId} = doc;
+ let date;
if (version === 'latest') {
- try {
- const res = await
axios.get(`https://api.github.com/repos/apache/${repo}/commits?page=1&per_page=1`)
- commitId = res.data[0].sha;
- } catch (err) {
- throw err
- }
+ const res = await
axios.get(`https://api.github.com/repos/apache/${repo}/commits?page=1&per_page=1`)
+ commitId = res.data[0].sha;
+ date = res.data[0].commit.author.date;
}
if (commitId) {
+ if (!date) {
+ const res = await
axios.get(`https://api.github.com/repos/apache/${repo}/commits/${commitId}`)
+ date = res.data.commit.author.date;
+ }
const docName = repo === 'skywalking' ? 'main' : repo;
const localPath = `/content/docs/${docName}/${version}`;
const menuFileName = `${docName}${version}`.replace(/\-|v|\./g, '_');
- docsInfo.push({localPath, repoUrl, commitId})
+ docsInfo.push({localPath, repoUrl, commitId, date})
tpl += `{{ if in .File.Path "${localPath.split('/content/')[1]}" }}
<h5>Documentation:
{{.Site.Data.docSidebar.${menuFileName}.version}}</h5>