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/04/17 11:38:15 UTC
[skywalking-website] branch master updated: Feat: Document version
selector (#256)
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 e2d434b Feat: Document version selector (#256)
e2d434b is described below
commit e2d434b979556ae07eadfcc11cdbbc142abde11e
Author: Juntao Zhang <jt...@163.com>
AuthorDate: Sat Apr 17 19:38:08 2021 +0800
Feat: Document version selector (#256)
---
README.md | 2 ++
docs.js | 24 +++++++++----
themes/docsy/assets/scss/_custom_project_doc.scss | 11 +++++-
themes/docsy/assets/scss/_sidebar-toc.scss | 2 +-
themes/docsy/layouts/projectDoc/baseof.html | 41 +++++++++++++++++++----
5 files changed, 65 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
index 18ccc06..0098c05 100755
--- a/README.md
+++ b/README.md
@@ -25,6 +25,8 @@ Located at `content/_index.html`。
The data of documentation link is located in `data/docs.yml` and formated as `YAML`.
+Update the [config file](https://github.com/algolia/docsearch-configs/blob/master/configs/skywalking.json) everytime in order that a new documentation version will be available searched by [algolia](https://www.algolia.com/).
+
### Event
Located at `content/blog`. If you don't want to create a new blog, you need to create a new subdirectory under this directory. Here is a sample blog below.
diff --git a/docs.js b/docs.js
index 47c22fe..2aefc9a 100644
--- a/docs.js
+++ b/docs.js
@@ -145,7 +145,7 @@ async function traverseDocsList(result) {
continue;
}
for (const doc of item.docs) {
- const {repo, repoUrl} = item;
+ const {repo, repoUrl, docs} = item;
let {version, commitId} = doc;
let date;
if (version === 'latest') {
@@ -164,15 +164,26 @@ async function traverseDocsList(result) {
docsInfo.push({localPath, repoUrl, commitId, date, docName, version})
tpl += `{{ if in .File.Path "${localPath.split('/content/')[1]}" }}
- <h5>Documentation: {{.Site.Data.docSidebar.${menuFileName}.version}}</h5>
+ {{ $currentVersion := .Site.Data.docSidebar.${menuFileName}.version }}
+ <h5>Documentation:
+ <select class="version-select">
+ {{range .Site.Data.docSidebar.${menuFileName}.repoDocs}}
+ {{$version := .version}}
+ <option {{ cond (eq $currentVersion $version) "selected" "" }} value="{{$version}}">{{$version}}</option>
+ {{end}}
+ </select>
+ </h5>
+
{{ partial "sidebar-menu.html" .Site.Data.docSidebar.${menuFileName} }}
<div class="commit-id">Commit Id: {{.Site.Data.docSidebar.${menuFileName}.commitId}}</div>
- {{ end }}\n`
+ {{ end }}\n`;
+
execSync(`"./doc.sh" ${repo} ${repoUrl} ${commitId} ${localPath} ${menuFileName}`);
await handleMenuFiles(`./data/docSidebar/${menuFileName}.yml`, {
version,
- commitId
+ commitId,
+ docs,
}, `/docs/${docName}/${version}`)
}
}
@@ -185,7 +196,7 @@ async function traverseDocsList(result) {
async function generateLayoutTemplate(targetPath, tpl) {
let codeTxt = await promises.readFile(targetPath, 'utf8');
codeTxt = codeTxt.toString()
- codeTxt = codeTxt.replace(/(td-sidebar">)([\s\S]*)(<\/div>[\s\S]*<div id="toc")/, function (match, p1, p2, p3) {
+ codeTxt = codeTxt.replace(/(td-sidebar">)([\s\S]*)(<\/div>[\s\S]*<main)/, function (match, p1, p2, p3) {
return `${p1}\n${tpl}\n${p3}`
})
await promises.writeFile(targetPath, codeTxt, 'utf8');
@@ -202,9 +213,10 @@ function handleDocsFiles(docsInfo) {
async function handleMenuFiles(menuFilePath, docInfo, localPath) {
const nativeObject = await loadYaml(menuFilePath);
- const {version, commitId} = docInfo
+ const {version, commitId, docs} = docInfo
nativeObject.version = version;
nativeObject.commitId = commitId.slice(0, 7);
+ nativeObject.repoDocs = docs;
handleMenuPath(nativeObject.catalog, localPath)
const yamlString = YAML.stringify(nativeObject, 2);
diff --git a/themes/docsy/assets/scss/_custom_project_doc.scss b/themes/docsy/assets/scss/_custom_project_doc.scss
index e735085..1d4e8e8 100644
--- a/themes/docsy/assets/scss/_custom_project_doc.scss
+++ b/themes/docsy/assets/scss/_custom_project_doc.scss
@@ -6,6 +6,14 @@
margin-bottom: 1rem;
}
}
+ .version-select{
+ vertical-align: middle;
+ margin-left: 5px;
+ color: #2c3e50;
+ border: 1px solid #dee2e6;
+ border-radius: 2px;
+ outline: none;
+ }
.td-sidebar {
font-weight: 300;
@@ -56,8 +64,9 @@
right: 15px;
bottom: 15px;
border: 1px solid #cccccc;
+ background-color: rgba(216,217,218,0.3);
border-radius: 3px;
- padding:8px;
+ padding: 10px;
color: #999;
z-index: 9999;
display: none;
diff --git a/themes/docsy/assets/scss/_sidebar-toc.scss b/themes/docsy/assets/scss/_sidebar-toc.scss
index 2a954c8..fc687b0 100644
--- a/themes/docsy/assets/scss/_sidebar-toc.scss
+++ b/themes/docsy/assets/scss/_sidebar-toc.scss
@@ -2,7 +2,7 @@
// Right side toc
//
.td-toc {
- border-left: 1px solid $border-color;
+ border-left: 1px solid #eaecef;
@supports (position: sticky) {
position: sticky;
diff --git a/themes/docsy/layouts/projectDoc/baseof.html b/themes/docsy/layouts/projectDoc/baseof.html
index 6d5a93b..ec013be 100644
--- a/themes/docsy/layouts/projectDoc/baseof.html
+++ b/themes/docsy/layouts/projectDoc/baseof.html
@@ -14,14 +14,15 @@
<div class="row flex-xl-nowrap">
<div class="col-12 col-md-3 col-xl-2 d-print-none td-sidebar">
-</div>
+ </div>
+ <main class="col-12 col-md-9 col-xl-8 pl-md-5 pr-md-4" role="main">
+ <i class="fa fa-bars doc-menu-button"></i>
+ {{ block "main" . }}{{ end }}
+ </main>
<div id="toc" class="d-none d-xl-block col-xl-2 td-toc d-print-none">
{{ partial "toc.html" . }}
</div>
- <main class="col-12 col-md-9 col-xl-8 pl-md-5 pr-md-4" role="main">
- <i class="fa fa-bars doc-menu-button"></i>
- {{ block "main" . }}{{ end }}
- </main>
+
</div>
</div>
@@ -32,8 +33,34 @@
{{ partial "scripts.html" . }}
</body>
<script>
- $('.doc-menu-button').on('click',function (){
- $('.td-sidebar').toggleClass('active')
+ $(function (){
+ $('.doc-menu-button').on('click',function (){
+ $('.td-sidebar').toggleClass('active')
+ })
+ $('.version-select').on('change', function (){
+ var selectVersion = $(this).val();
+ var prefix = '';
+ var url = location.href.replace(/(\/docs\/[a-zA-Z\-]+\/)([\w|\.]+)(\/.*)/, function (match, p1, p2, p3){
+ prefix = p1 + selectVersion;
+ return p1 + selectVersion + p3
+ })
+ go2SelectVersion(url, prefix)
+
+ })
+ function go2SelectVersion(url, prefix){
+ $.ajax({
+ url: url,
+ type: "get",
+ success:function(){
+ location.href = url;
+ },
+ statusCode: {
+ 404:function(){
+ location.href = prefix + '/readme/';
+ }
+ }
+ });
+ }
})
</script>
</html>