Add language switch icon in top-right corner
This commit is contained in:
parent
03d010accc
commit
f501cbc737
|
@ -1,5 +1,13 @@
|
||||||
# ChangeLog
|
# ChangeLog
|
||||||
|
|
||||||
|
### 2022-03-29
|
||||||
|
|
||||||
|
- Add language switch icon in top-right corner
|
||||||
|
|
||||||
|
### 2022-03-28
|
||||||
|
|
||||||
|
- Add [Basic lifetime](https://practice.rs/lifetime/basic.html)
|
||||||
|
|
||||||
### 2022-03-25
|
### 2022-03-25
|
||||||
|
|
||||||
- Replace gitalk with giscus comments system which is based on Github Discussions
|
- Replace gitalk with giscus comments system which is based on Github Discussions
|
||||||
|
|
|
@ -110,6 +110,17 @@ var initAll = function () {
|
||||||
pagePath = "index"
|
pagePath = "index"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add vistors count
|
||||||
|
var ele = document.createElement("div");
|
||||||
|
ele.setAttribute("align","center");
|
||||||
|
var count = document.createElement("img")
|
||||||
|
count.setAttribute("src", "https://visitor-badge.glitch.me/badge?page_id=practice/en/" + path);
|
||||||
|
ele.appendChild(count);
|
||||||
|
var divider =document.createElement("hr")
|
||||||
|
|
||||||
|
document.getElementById("giscus-container").appendChild(ele);
|
||||||
|
document.getElementById("giscus-container").appendChild(divider);
|
||||||
|
|
||||||
// 选取浏览器默认使用的语言
|
// 选取浏览器默认使用的语言
|
||||||
const lang = navigator.language || navigator.userLanguage
|
const lang = navigator.language || navigator.userLanguage
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
(function () {
|
||||||
|
var path = window.location.pathname;
|
||||||
|
var link = "https://practice.rs" + path;
|
||||||
|
var word = "English";
|
||||||
|
var lang = "zh-CN";
|
||||||
|
var changeLang = "切换到英语";
|
||||||
|
|
||||||
|
if (window.location.href.indexOf("zh.") == -1) {
|
||||||
|
link = "https://zh.practice.rs" + path;
|
||||||
|
word = "简体中文";
|
||||||
|
lang = "en";
|
||||||
|
changeLang = "Switch to Chinese"
|
||||||
|
}
|
||||||
|
|
||||||
|
var lang_node = '';
|
||||||
|
if (link != '') {
|
||||||
|
lang_node = '<a href="' + link + '" title="' + changeLang + '" aria-label="' + changeLang + '"><i id="change-language-button" class="fa fa-language"> ' + word + '</i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(lang_node)
|
||||||
|
var insertNode = document.getElementsByClassName('right-buttons');
|
||||||
|
if (insertNode.length > 0) {
|
||||||
|
var html = insertNode[0].innerHTML;
|
||||||
|
insertNode[0].innerHTML = html + lang_node;
|
||||||
|
}
|
||||||
|
})()
|
|
@ -14,7 +14,7 @@ level = 1
|
||||||
|
|
||||||
[output.html]
|
[output.html]
|
||||||
additional-css = ["theme/style1.css"]
|
additional-css = ["theme/style1.css"]
|
||||||
additional-js = ["assets/custom1.js"]
|
additional-js = ["assets/custom3.js","assets/lang.js"]
|
||||||
git-repository-url = "https://github.com/sunface/rust-by-practice"
|
git-repository-url = "https://github.com/sunface/rust-by-practice"
|
||||||
edit-url-template = "https://github.com/sunface/rust-by-practice/edit/master/en/{path}"
|
edit-url-template = "https://github.com/sunface/rust-by-practice/edit/master/en/{path}"
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
mdbook build
|
mdbook build
|
||||||
## copy CNAME info to book dir
|
## copy CNAME info to book dir
|
||||||
cp ./assets/CNAME ./book/
|
cp ./assets/CNAME ./book/
|
||||||
cp ./assets/*.html ./book/
|
|
||||||
cp ./assets/sitemap.xml ./book/
|
|
||||||
|
|
||||||
## init git repo
|
## init git repo
|
||||||
cd book
|
cd book
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
# advance
|
# advance
|
||||||
|
|
||||||
|
aaaa
|
|
@ -110,6 +110,17 @@ var initAll = function () {
|
||||||
pagePath = "index"
|
pagePath = "index"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add vistors count
|
||||||
|
var ele = document.createElement("div");
|
||||||
|
ele.setAttribute("align","center");
|
||||||
|
var count = document.createElement("img")
|
||||||
|
count.setAttribute("src", "https://visitor-badge.glitch.me/badge?page_id=practice/en/" + path);
|
||||||
|
ele.appendChild(count);
|
||||||
|
var divider =document.createElement("hr")
|
||||||
|
|
||||||
|
document.getElementById("giscus-container").appendChild(ele);
|
||||||
|
document.getElementById("giscus-container").appendChild(divider);
|
||||||
|
|
||||||
// 选取浏览器默认使用的语言
|
// 选取浏览器默认使用的语言
|
||||||
const lang = navigator.language || navigator.userLanguage
|
const lang = navigator.language || navigator.userLanguage
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
(function () {
|
||||||
|
var path = window.location.pathname;
|
||||||
|
var link = "https://practice.rs" + path;
|
||||||
|
var word = "English";
|
||||||
|
var lang = "zh-CN";
|
||||||
|
var changeLang = "切换到英语";
|
||||||
|
|
||||||
|
if (window.location.href.indexOf("zh.") == -1) {
|
||||||
|
link = "https://zh.practice.rs" + path;
|
||||||
|
word = "简体中文";
|
||||||
|
lang = "en";
|
||||||
|
changeLang = "Switch to Chinese"
|
||||||
|
}
|
||||||
|
|
||||||
|
var lang_node = '';
|
||||||
|
if (link != '') {
|
||||||
|
lang_node = '<a href="' + link + '" title="' + changeLang + '" aria-label="' + changeLang + '"><i id="change-language-button" class="fa fa-language"> ' + word + '</i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(lang_node)
|
||||||
|
var insertNode = document.getElementsByClassName('right-buttons');
|
||||||
|
if (insertNode.length > 0) {
|
||||||
|
var html = insertNode[0].innerHTML;
|
||||||
|
insertNode[0].innerHTML = html + lang_node;
|
||||||
|
}
|
||||||
|
})()
|
|
@ -14,7 +14,7 @@ level = 1
|
||||||
|
|
||||||
[output.html]
|
[output.html]
|
||||||
additional-css = ["theme/style1.css"]
|
additional-css = ["theme/style1.css"]
|
||||||
additional-js = ["assets/custom1.js"]
|
additional-js = ["assets/custom3.js","assets/lang.js"]
|
||||||
git-repository-url = "https://github.com/sunface/rust-by-practice"
|
git-repository-url = "https://github.com/sunface/rust-by-practice"
|
||||||
edit-url-template = "https://github.com/sunface/rust-by-practice/edit/master/zh-CN/{path}"
|
edit-url-template = "https://github.com/sunface/rust-by-practice/edit/master/zh-CN/{path}"
|
||||||
|
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
# advance
|
# advance
|
||||||
|
|
||||||
|
aaaa
|
Loading…
Reference in New Issue