mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2024-11-09 08:51:18 +08:00
ferris technology
This commit is contained in:
parent
2915a218b8
commit
820474537f
@ -3,7 +3,7 @@ dist: trusty
|
|||||||
language: rust
|
language: rust
|
||||||
cache: cargo
|
cache: cargo
|
||||||
rust:
|
rust:
|
||||||
- nightly
|
- beta # Change this to stable when Rust 1.31.0 is out
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
|
@ -5,3 +5,7 @@ description = "Rust 程序设计语言 简体中文版"
|
|||||||
|
|
||||||
[build-dir]
|
[build-dir]
|
||||||
destination = "mdbook"
|
destination = "mdbook"
|
||||||
|
|
||||||
|
[output.html]
|
||||||
|
additional-css = ["ferris.css"]
|
||||||
|
additional-js = ["ferris.js"]
|
33
ferris.css
Normal file
33
ferris.css
Normal 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
51
ferris.js
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user