diff --git a/book.toml b/book.toml new file mode 100644 index 0000000..c46e047 --- /dev/null +++ b/book.toml @@ -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" diff --git a/ferris.css b/ferris.css new file mode 100644 index 0000000..3712079 --- /dev/null +++ b/ferris.css @@ -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; +} diff --git a/ferris.js b/ferris.js new file mode 100644 index 0000000..5e79b3c --- /dev/null +++ b/ferris.js @@ -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) +} diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 4e58585..d26edbe 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -1,7 +1,7 @@ # Rust 程序设计语言 -[The Rust Programming Language](title-page.md) -[Foreword](foreword.md) +[Rust 程序设计语言](title-page.md) +[前言](foreword.md) [简介](ch00-00-introduction.md) ## 开始 diff --git a/theme/2018-edition.css b/theme/2018-edition.css new file mode 100644 index 0000000..b1dcf93 --- /dev/null +++ b/theme/2018-edition.css @@ -0,0 +1,9 @@ +span.caption { + font-size: .8em; + font-weight: 600; +} + +span.caption code { + font-size: 0.875em; + font-weight: 400; +}