Skip to content

Commit

Permalink
♻️gitalk automatically switch languages
Browse files Browse the repository at this point in the history
  • Loading branch information
宋慧武 committed Dec 23, 2018
1 parent ea694a9 commit f7d6d09
Showing 1 changed file with 42 additions and 29 deletions.
71 changes: 42 additions & 29 deletions libs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,77 @@
* Docsify config
*/
gitalkConfig = {
clientID: '8b7cffeb4ae285e0e3e4',
clientSecret: '58d06f5220e953d6dac7d6723daf225177cc7bb3',
repo: 'You-need-to-know-css',
owner: 'l-hammer',
admin: ['l-hammer'],
clientID: "8b7cffeb4ae285e0e3e4",
clientSecret: "58d06f5220e953d6dac7d6723daf225177cc7bb3",
repo: "You-need-to-know-css",
owner: "l-hammer",
admin: ["l-hammer"],
perPage: 20,
labels: ['💬Gitalk'],
pagerDirection: 'last',
language: "en",
labels: ["💬Gitalk"],
pagerDirection: "last",
distractionFreeMode: false
},
};
window.$docsify = {
name: 'You-need-to-know-css',
repo: 'https://github.com/l-hammer/You-need-to-know-css',
name: "You-need-to-know-css",
repo: "https://github.com/l-hammer/You-need-to-know-css",
auto2top: true,
loadNavbar: true,
loadSidebar: true,
mergeNavbar: true,
subMaxLevel: 2,
homepage: 'README.md',
ga: 'UA-122081516-1',
homepage: "README.md",
ga: "UA-122081516-1",
search: {
noData: {
'/zh-cn/': '找不到结果!',
'/': 'No results!',
"/zh-cn/": "找不到结果!",
"/": "No results!"
},
paths: 'auto',
paths: "auto",
placeholder: {
'/zh-cn/': '搜索',
'/': 'Search',
"/zh-cn/": "搜索",
"/": "Search"
}
},
plugins: [
function(hook, vm) {
hook.beforeEach(function (html) {
var url = 'https://github.com/l-hammer/You-need-to-know-css/blob/master/' + vm.route.file;
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n';

hook.beforeEach(function(html) {
var url =
"https://github.com/l-hammer/You-need-to-know-css/blob/master/" +
vm.route.file;
var editHtml = "[📝 EDIT DOCUMENT](" + url + ")\n";

return editHtml + html;
})
});

hook.doneEach(function(){
hook.doneEach(function() {
var label, domObj, main, divEle, gitalk;
label = vm.route.path.split('/').pop();
label = vm.route.path.split("/").pop();
domObj = Docsify.dom;
main = domObj.getNode("#main");

/**
* render gittalk
*/
Array.apply(null,document.querySelectorAll("div.gitalk-container")).forEach(function(ele){ele.remove()});
if (vm.route.path.includes("zh-cn")) {
gitalkConfig.language = "zh-CN";
}
Array.apply(
null,
document.querySelectorAll("div.gitalk-container")
).forEach(function(ele) {
ele.remove();
});
divEle = domObj.create("div");
divEle.id = "gitalk-container-" + label;
divEle.className = "gitalk-container";
divEle.style = "width: " + main.clientWidth + "px; margin: 0 auto 20px;";
domObj.appendTo(domObj.find(".content"), divEle);
gitalk = new Gitalk(Object.assign(gitalkConfig, {id: !label ? "home" : label}))
gitalk.render('gitalk-container-' + label)
})
gitalk = new Gitalk(
Object.assign(gitalkConfig, { id: !label ? "home" : label })
);
gitalk.render("gitalk-container-" + label);
});
}
]
}
};

0 comments on commit f7d6d09

Please sign in to comment.