Add theme and js files

This commit is contained in:
Aaran Xu 2021-05-09 15:16:11 +08:00
parent 6404d64eb8
commit b29615dba3
5 changed files with 104 additions and 2 deletions

9
book.toml Normal file
View File

@ -0,0 +1,9 @@
[book]
title = "Rust 程序设计语言"
author = "Steve Klabnik and Carol Nichols, with Contributions from the Rust Community"
translator = "Rust 中文翻译项目组Rust 中文社区"
[output.html]
additional-css = ["ferris.css", "theme/2018-edition.css"]
additional-js = ["ferris.js"]
git-repository-url = "https://github.com/rust-lang-cn/book-cn"

33
ferris.css Normal file
View File

@ -0,0 +1,33 @@
body.light .does_not_compile,
body.light .panics,
body.light .not_desired_behavior,
body.rust .does_not_compile,
body.rust .panics,
body.rust .not_desired_behavior {
background: #fff1f1;
}
body.coal .does_not_compile,
body.coal .panics,
body.coal .not_desired_behavior,
body.navy .does_not_compile,
body.navy .panics,
body.navy .not_desired_behavior,
body.ayu .does_not_compile,
body.ayu .panics,
body.ayu .not_desired_behavior {
background: #501f21;
}
.ferris {
position: absolute;
z-index: 99;
right: 5px;
top: 30px;
width: 10%;
height: auto;
}
.ferris-explain {
width: 100px;
}

51
ferris.js Normal file
View File

@ -0,0 +1,51 @@
var ferrisTypes = [
{
attr: 'does_not_compile',
title: 'This code does not compile!'
},
{
attr: 'panics',
title: 'This code panics!'
},
{
attr: 'unsafe',
title: 'This code block contains unsafe code.'
},
{
attr: 'not_desired_behavior',
title: 'This code does not produce the desired behavior.'
}
]
document.addEventListener('DOMContentLoaded', () => {
for (var ferrisType of ferrisTypes) {
attachFerrises(ferrisType)
}
})
function attachFerrises (type) {
var elements = document.getElementsByClassName(type.attr)
for (var codeBlock of elements) {
var lines = codeBlock.textContent.split(/\r|\r\n|\n/).length - 1;
if (lines >= 4) {
attachFerris(codeBlock, type)
}
}
}
function attachFerris (element, type) {
var a = document.createElement('a')
a.setAttribute('href', 'ch00-00-introduction.html#ferris')
a.setAttribute('target', '_blank')
var img = document.createElement('img')
img.setAttribute('src', 'img/ferris/' + type.attr + '.svg')
img.setAttribute('title', type.title)
img.className = 'ferris'
a.appendChild(img)
element.parentElement.insertBefore(a, element)
}

View File

@ -1,7 +1,7 @@
# Rust 程序设计语言 # Rust 程序设计语言
[The Rust Programming Language](title-page.md) [Rust 程序设计语言](title-page.md)
[Foreword](foreword.md) [前言](foreword.md)
[简介](ch00-00-introduction.md) [简介](ch00-00-introduction.md)
## 开始 ## 开始

9
theme/2018-edition.css Normal file
View File

@ -0,0 +1,9 @@
span.caption {
font-size: .8em;
font-weight: 600;
}
span.caption code {
font-size: 0.875em;
font-weight: 400;
}