Skip to content

Commit a6d3046

Browse files
committed
chore: split English and Chinese
1 parent 03f759f commit a6d3046

3 files changed

Lines changed: 106 additions & 0 deletions

File tree

book.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ title = "Postgres Weekly, A Hacker’s Digest"
88
[output.html]
99
no-section-label = true
1010
git-repository-url = "https://github.com/pgweekly/pgweekly.github.io"
11+
additional-js = ["extra.js"]
12+
additional-css = ["extra.css"]
1113

1214
[output.html.fold]
1315
enable = true # whether or not to enable section folding

extra.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Align all right-side actions on one vertical center line */
2+
#menu-bar .right-buttons {
3+
display: inline-flex;
4+
align-items: center;
5+
align-self: center;
6+
}
7+
8+
/* Language switch in mdBook menu bar */
9+
#menu-bar .right-buttons a.pgw-menu-lang {
10+
display: inline-flex;
11+
align-items: center;
12+
gap: 0.35em;
13+
box-sizing: border-box;
14+
height: var(--menu-bar-height);
15+
padding: 0 10px 0 6px;
16+
margin-right: 4px;
17+
font-size: 1.4rem;
18+
font-weight: 500;
19+
line-height: 1;
20+
color: var(--icons);
21+
text-decoration: none;
22+
}
23+
24+
#menu-bar .right-buttons a.pgw-menu-lang:hover {
25+
color: var(--icons-hover);
26+
}
27+
28+
/* Icon: optically nudged down to match print/github glyphs */
29+
#menu-bar .right-buttons a.pgw-menu-lang > .fa-language {
30+
padding: 0;
31+
font-size: 1.45rem;
32+
line-height: 1;
33+
position: relative;
34+
top: 0px;
35+
}
36+
37+
#menu-bar .right-buttons a.pgw-menu-lang .pgw-menu-lang-label {
38+
line-height: 1;
39+
position: relative;
40+
top: -1px;
41+
}

extra.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* One language in the sidebar; language switch link in the menu bar. */
2+
(function () {
3+
var path = window.location.pathname || '';
4+
var isCn = path.indexOf('/cn/') !== -1;
5+
6+
var sidebar = document.querySelector('#sidebar .sidebar-scrollbox ol.chapter');
7+
if (sidebar) {
8+
var titles = sidebar.querySelectorAll(':scope > li.part-title');
9+
if (titles.length >= 2) {
10+
var cnPartTitle = titles[1];
11+
var el = sidebar.firstElementChild;
12+
var next;
13+
if (isCn) {
14+
while (el && el !== cnPartTitle) {
15+
next = el.nextElementSibling;
16+
el.style.display = 'none';
17+
el = next;
18+
}
19+
} else {
20+
el = cnPartTitle;
21+
while (el) {
22+
next = el.nextElementSibling;
23+
el.style.display = 'none';
24+
el = next;
25+
}
26+
}
27+
}
28+
}
29+
30+
function otherLangPath(p) {
31+
if (p.indexOf('/cn/') !== -1) return p.replace('/cn/', '/en/');
32+
if (p.indexOf('/en/') !== -1) return p.replace('/en/', '/cn/');
33+
return new URL('cn/2026/index.html', window.location.href).pathname;
34+
}
35+
36+
var target = otherLangPath(path);
37+
if (target === path) return;
38+
if (path.indexOf('print.html') !== -1) return;
39+
40+
var right = document.querySelector('#menu-bar .right-buttons');
41+
if (!right) return;
42+
43+
var a = document.createElement('a');
44+
a.className = 'pgw-menu-lang';
45+
a.href = target;
46+
var icon = document.createElement('i');
47+
icon.className = 'fa fa-language';
48+
icon.setAttribute('aria-hidden', 'true');
49+
var label = document.createElement('span');
50+
label.className = 'pgw-menu-lang-label';
51+
if (target.indexOf('/cn/') !== -1) {
52+
label.textContent = '中文';
53+
a.title = '切换到中文版';
54+
a.setAttribute('aria-label', '切换到中文版');
55+
} else {
56+
label.textContent = 'English';
57+
a.title = 'English version';
58+
a.setAttribute('aria-label', 'English version');
59+
}
60+
a.appendChild(icon);
61+
a.appendChild(label);
62+
right.insertBefore(a, right.firstChild);
63+
})();

0 commit comments

Comments
 (0)