Skip to content

Commit 8f8ee53

Browse files
committed
Book style tweaks
1 parent 348d375 commit 8f8ee53

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed

book/book.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ edition = "2018"
88

99
[build]
1010
build-dir = "build"
11+
create-missing = false
1112

1213
[output.html]
1314
additional-css = ["css/cxx.css"]
1415
cname = "cxx.rs"
1516
git-repository-url = "https://github.com/dtolnay/cxx"
17+
playground = { copyable = false }
18+
print = { enable = false }

book/build.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ https://github.com/dtolnay/cxx\
1414
</a>\
1515
</li>`;
1616

17+
const htmljs = `\
18+
var html = document.querySelector('html');
19+
html.classList.remove('no-js');
20+
html.classList.add('js');`;
21+
1722
const dirs = ['build'];
1823
while (dirs.length) {
1924
const dir = dirs.pop();
@@ -32,7 +37,11 @@ while (dirs.length) {
3237
const index = fs.readFileSync(path, 'utf8');
3338
const $ = cheerio.load(index, { decodeEntities: false });
3439

40+
$('script:nth-of-type(3)').text(htmljs);
3541
$('nav#sidebar ol.chapter').append(githublink);
42+
$('head link[href="tomorrow-night.css"]').attr('disabled', true);
43+
$('head link[href="ayu-highlight.css"]').attr('disabled', true);
44+
$('button#theme-toggle').attr('style', 'display:none');
3645
$('pre code').each(function () {
3746
const node = $(this);
3847
const langClass = node.attr('class').split(' ', 2)[0];
@@ -44,21 +53,29 @@ while (dirs.length) {
4453
const boring = lines.map((line) =>
4554
line.includes('<span class="boring">')
4655
);
56+
const ellipsis = lines.map((line) => line.includes('// ...'));
4757
const target = entities.decode(node.text());
4858
const highlighted = hljs.highlight(lang, target).value;
4959
const result = highlighted
5060
.split('\n')
5161
.map(function (line, i) {
5262
if (boring[i]) {
5363
line = '<span class="boring">' + line;
64+
} else if (ellipsis[i]) {
65+
line = '<span class="ellipsis">' + line;
5466
}
55-
if (i > 0 && boring[i - 1]) {
67+
if (i > 0 && (boring[i - 1] || ellipsis[i - 1])) {
5668
line = '</span>' + line;
5769
}
5870
return line;
5971
})
6072
.join('\n');
61-
node.text(result).removeClass(langClass).addClass('hidelines');
73+
node.text(result);
74+
node.removeClass(langClass);
75+
if (!node.hasClass('focuscomment')) {
76+
node.addClass('hidelines');
77+
node.addClass('hide-boring');
78+
}
6279
});
6380
$('code').each(function () {
6481
$(this).addClass('hljs');
@@ -68,3 +85,10 @@ while (dirs.length) {
6885
fs.writeFileSync(path, out);
6986
});
7087
}
88+
89+
fs.copyFileSync('build/highlight.css', 'build/tomorrow-night.css');
90+
fs.copyFileSync('build/highlight.css', 'build/ayu-highlight.css');
91+
92+
var bookjs = fs.readFileSync('build/book.js', 'utf8');
93+
bookjs = bookjs.replace('set_theme(theme, false);', '');
94+
fs.writeFileSync('build/book.js', bookjs);

book/css/cxx.css

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1-
.no-js .boring {
1+
:root {
2+
--sidebar-width: 310px;
3+
}
4+
5+
.badges img {
6+
margin: 0 7px 7px 0;
7+
}
8+
9+
.badges {
10+
margin: 16px 0 120px;
11+
}
12+
13+
.boring {
14+
opacity: 0.5;
15+
}
16+
17+
.no-js code:not(.focuscomment) .boring {
218
display: none;
319
}
420

21+
.js code:not(.hide-boring) .ellipsis {
22+
display: none;
23+
}
24+
25+
.focuscomment .hljs-comment {
26+
font-weight: bold;
27+
color: black;
28+
}
29+
30+
.focuscomment .boring {
31+
opacity: 0.5;
32+
}
33+
534
nav.sidebar li.part-title i.fa-github {
635
font-size: 20px;
736
padding-right: 5px;
837
padding-top: 12px;
938
position: relative;
1039
top: 1px;
1140
}
41+
42+
.sidebar .sidebar-scrollbox {
43+
padding: 10px 0 10px 10px;
44+
}

book/diagram/overview.ascii

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.-----------------------------.
22
| #[cxx::bridge] mod |
3-
| definitions and declarations |
3+
| description of boundary |
44
'--------------+--------------'
55
|
66
|

book/diagram/overview.svg

Lines changed: 3 additions & 3 deletions
Loading

0 commit comments

Comments
 (0)