You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/02/18 02:24:34 UTC

[skywalking-website] branch master updated: Add latest doc (#217)

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 7bd2d9e  Add latest doc (#217)
7bd2d9e is described below

commit 7bd2d9e7225b709b1504693ac2fbcd4e0a6f0bbd
Author: Juntao Zhang <jt...@163.com>
AuthorDate: Thu Feb 18 10:24:27 2021 +0800

    Add latest doc (#217)
---
 data/docs.yml                               |  3 +-
 docs.js                                     | 50 ++++++++++++++++++++---------
 package.json                                |  8 +++--
 themes/docsy/layouts/projectDoc/baseof.html |  1 -
 4 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/data/docs.yml b/data/docs.yml
index 04a0e50..f6a6abe 100644
--- a/data/docs.yml
+++ b/data/docs.yml
@@ -8,6 +8,8 @@
       repo: skywalking
       repoUrl: https://github.com/apache/skywalking.git
       docs:
+        - version: latest
+          link: /docs/main/latest/readme/
         - version: v8.4.0
           link: /docs/main/v8.4.0/readme/
           commitId: ca978d0f8c6de4673009c5f100955035ddae9ecf
@@ -30,7 +32,6 @@
       user: apache
       repo: skywalking-website
 
-
 - type: Agent
   description:
   list:
diff --git a/docs.js b/docs.js
index c3dd84a..6841fc1 100644
--- a/docs.js
+++ b/docs.js
@@ -1,13 +1,21 @@
 const fs = require("fs");
 const path = require("path");
 const YAML = require('yamljs');
+const axios = require('axios');
 const {execSync} = require("child_process");
 const {promises} = fs;
 const docConfig = './data/docs.yml';
 const layoutTemplateFile = '/themes/docsy/layouts/projectDoc/baseof.html';
 
+init();
 
-traverseDocsConfig()
+async function init() {
+  const targetPath = path.join(__dirname, layoutTemplateFile)
+  const result = await loadYaml(docConfig)
+  const {tpl, docsInfo} = await traverseDocsList(result)
+  await generateLayoutTemplate(targetPath, tpl)
+  handleDocsFiles(docsInfo)
+}
 
 function readDirSync(path, docInfo, replaceMarkdownText) {
   const pa = fs.readdirSync(path);
@@ -91,16 +99,26 @@ function writeFile(filePath, codeTxt) {
 }
 
 
-async function traverseDocsConfig() {
+async function traverseDocsList(result) {
   let tpl = '';
   const docsInfo = []
-  const targetPath = path.join(__dirname, layoutTemplateFile)
-  const result = await loadYaml(docConfig)
-  result.forEach(data => {
-    data.list.forEach(item => {
-      item.docs && item.docs.forEach(({version, commitId}) => {
+  for (const data of result) {
+    for (const item of data.list) {
+      if (!item.docs) {
+        continue;
+      }
+      for (const doc of item.docs) {
+        const {repo, repoUrl} = item;
+        let {version, commitId} = doc;
+        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) {
+            console.log(err);
+          }
+        }
         if (commitId) {
-          const {repo, repoUrl} = item;
           const docName = repo === 'skywalking' ? 'main' : repo;
           const localPath = `/content/docs/${docName}/${version}`;
           const menuFileName = `${docName}${version}`.replace(/v|\./g, '_');
@@ -111,18 +129,18 @@ async function traverseDocsConfig() {
                     {{ partial "sidebar-recurse.html" .Site.Data.docSidebar.${menuFileName} }}
                     <div class="commit-id">Commit Id: {{.Site.Data.docSidebar.${menuFileName}.commitId}}</div>
                     {{ end }}\n`
-
           execSync(`"./doc.sh" ${repo} ${repoUrl} ${commitId} ${localPath} ${menuFileName}`);
 
-          handleMenuFiles(`./data/docSidebar/${menuFileName}.yml`, {version, commitId}, `/docs/${docName}/${version}`)
+          await handleMenuFiles(`./data/docSidebar/${menuFileName}.yml`, {
+            version,
+            commitId
+          }, `/docs/${docName}/${version}`)
         }
-      })
-    })
-
-  })
-  await generateLayoutTemplate(targetPath, tpl)
-  handleDocsFiles(docsInfo)
+      }
 
+    }
+  }
+  return {tpl, docsInfo}
 }
 
 async function generateLayoutTemplate(targetPath, tpl) {
diff --git a/package.json b/package.json
index 76cf163..50c84a2 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,10 @@
     "url": "https://github.com/bep/tech-doc-hugo/issues"
   },
   "homepage": "https://github.com/bep/tech-doc-hugo#readme",
-  "dependencies": {},
+  "dependencies": {
+    "axios": "^0.21.1",
+    "yamljs": "^0.3.0"
+  },
   "devDependencies": {
     "autoprefixer": "^9.8.6",
     "cssnano": "^4.1.10",
@@ -27,7 +30,6 @@
     "postcss": "^8.2.6",
     "postcss-cssnext": "^3.1.0",
     "postcss-import": "^12.0.1",
-    "postcss-loader": "^3.0.0",
-    "yamljs": "^0.3.0"
+    "postcss-loader": "^3.0.0"
   }
 }
diff --git a/themes/docsy/layouts/projectDoc/baseof.html b/themes/docsy/layouts/projectDoc/baseof.html
index 7f3a988..b0571b4 100644
--- a/themes/docsy/layouts/projectDoc/baseof.html
+++ b/themes/docsy/layouts/projectDoc/baseof.html
@@ -35,7 +35,6 @@
     $(function (){
       var path = window.location.pathname;
       $('.td-sidebar a').each(function (e){
-        console.log($(this).attr('href'));
         if($(this).attr('href')+'/'==path){
           $(this).addClass('active')
         }