mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 04:29:41 +00:00
Compare commits
43 Commits
20b8f73684
...
e0e88e963a
Author | SHA1 | Date | |
---|---|---|---|
e0e88e963a | |||
f933650123 | |||
21460fad98 | |||
f659004418 | |||
0e2f42a214 | |||
8d25a5067c | |||
716144c1ef | |||
8377d339ce | |||
fa0db45ae3 | |||
67920d9db0 | |||
adfb3ed34d | |||
bc9b3f3ec3 | |||
50d5af5cf0 | |||
6765d55c47 | |||
25842927fc | |||
0302542061 | |||
4e790a35be | |||
2e1d40b55b | |||
c37f77758f | |||
2cddf85611 | |||
94079c49af | |||
609e2d3f8c | |||
a19015f9fa | |||
d89f88f1c3 | |||
73b7dd9694 | |||
3b6474a563 | |||
21188323d3 | |||
4f41faf49c | |||
ef381ba48d | |||
1410670d33 | |||
be61b49f9a | |||
c478b37a0d | |||
68c285d97b | |||
1c83c69d30 | |||
1edb2c3125 | |||
95d89d8f32 | |||
a29f320605 | |||
0600bb3bdc | |||
5453e7a05c | |||
5b9632276f | |||
2f1ed60e25 | |||
ff6c841dd5 | |||
0f9f0367d6 |
@ -69,7 +69,7 @@ We use [mdbook](https://rust-lang.github.io/mdBook/) building our exercises. You
|
||||
|
||||
- Clone the repo
|
||||
```shell
|
||||
$ git clone git@github.com:sunface/rust-by-practice.git
|
||||
$ git clone https://github.com/sunface/rust-by-practice
|
||||
```
|
||||
- Install mdbook using Cargo
|
||||
```shell
|
||||
|
@ -120,7 +120,7 @@ fn main() {
|
||||
```
|
||||
|
||||
### Range
|
||||
9. 🌟🌟 Two goals: 1. Modify `assert!` to make it work 2. Make `println!` output: 97 - 122
|
||||
9. 🌟🌟 Two goals: 1. Modify `assert!` to make it work 2. Make `println!` output list of numbers between 97 and 122
|
||||
|
||||
```rust,editable
|
||||
fn main() {
|
||||
|
@ -63,8 +63,8 @@ fn main() {
|
||||
}
|
||||
|
||||
fn sum(x: i32, y: i32) -> i32 {
|
||||
x + y;
|
||||
x + y
|
||||
}
|
||||
```
|
||||
|
||||
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it
|
||||
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it
|
||||
|
@ -88,7 +88,7 @@ fn main() {
|
||||
fn main() {
|
||||
let names = [String::from("Sunfei"), "Sunface".to_string()];
|
||||
|
||||
// `Get` returns an Option<T>, it's safe to use
|
||||
// `Get` returns an Option<&T>, it's safe to use
|
||||
let name0 = names.get(0).unwrap();
|
||||
|
||||
// But indexing is not safe
|
||||
@ -99,4 +99,4 @@ fn main() {
|
||||
|
||||
```
|
||||
|
||||
> You can find the solutions [here](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/array.md)(under the solutions path), but only use it when you need it
|
||||
> You can find the solutions [here](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/array.md)(under the solutions path), but only use it when you need it
|
||||
|
@ -50,10 +50,10 @@ mod front_of_house {
|
||||
|
||||
pub fn eat_at_restaurant() {
|
||||
// Call add_to_waitlist with **absolute path**:
|
||||
__.add_to_waitlist();
|
||||
__::add_to_waitlist();
|
||||
|
||||
// Call with **relative path**
|
||||
__.add_to_waitlist();
|
||||
__::add_to_waitlist();
|
||||
}
|
||||
```
|
||||
|
||||
@ -67,7 +67,7 @@ mod back_of_house {
|
||||
// FILL in the blank in three ways
|
||||
//1. using keyword `super`
|
||||
//2. using absolute path
|
||||
__.serve_order();
|
||||
__::serve_order();
|
||||
}
|
||||
|
||||
fn cook_order() {}
|
||||
|
@ -223,7 +223,7 @@ Some of these methods call the method `next`to use up the iterator, so they are
|
||||
|
||||
8. 🌟🌟
|
||||
|
||||
```rust,edtiable
|
||||
```rust,editable
|
||||
|
||||
/* Fill in the blank and fix the errors */
|
||||
fn main() {
|
||||
|
@ -1 +1,52 @@
|
||||
# Box
|
||||
|
||||
1. 🌟
|
||||
```rust,editable
|
||||
// Make it work
|
||||
fn main() {
|
||||
// Create a new box `b` that contains the integer 5
|
||||
assert_eq!(*b, 5);
|
||||
|
||||
println!("Success!");
|
||||
}
|
||||
```
|
||||
|
||||
2. 🌟
|
||||
```rust,editable
|
||||
|
||||
// Make it work
|
||||
fn main() {
|
||||
let b = Box::new("Hello");
|
||||
print_boxed_string(b);
|
||||
}
|
||||
|
||||
fn print_boxed_string(b : _) {
|
||||
println!("{}", b);
|
||||
}
|
||||
```
|
||||
|
||||
3. 🌟
|
||||
```rust,editable
|
||||
|
||||
// Make it work
|
||||
fn main() {
|
||||
let b1 = Box::new(5);
|
||||
let b2 = b1;
|
||||
assert_eq!(_, 5);
|
||||
|
||||
println!("Success!");
|
||||
}
|
||||
```
|
||||
|
||||
4. 🌟
|
||||
```rust,editable
|
||||
|
||||
// Make it work
|
||||
fn main() {
|
||||
// Create a box `b` with an array [1, 2, 3, 4, 5]
|
||||
// Print each integer in `b`
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it
|
||||
|
@ -23,7 +23,7 @@ This book was designed for easily diving into and getting skilled with Rust, and
|
||||
|
||||
We use [mdbook](https://rust-lang.github.io/mdBook/) building our exercises. You can run locally with below steps:
|
||||
```shell
|
||||
$ git clone git@github.com:sunface/rust-by-practice.git
|
||||
$ git clone https://github.com/sunface/rust-by-practice
|
||||
$ cargo install mdbook
|
||||
$ cd rust-by-practice && mdbook serve en/
|
||||
```
|
||||
|
@ -16,7 +16,7 @@ mod front_of_house {
|
||||
|
||||
fn take_payment() {}
|
||||
|
||||
fn complain() {}
|
||||
fn complain() {}
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -41,7 +41,7 @@ pub mod front_of_house {
|
||||
|
||||
// Maybe you don't want the guest hearing the your complaining about them
|
||||
// So just make it private
|
||||
fn complain() {}
|
||||
fn complain() {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,8 +83,9 @@ mod back_of_house {
|
||||
```rust
|
||||
// in src/lib.rs
|
||||
|
||||
mod front_of_house;
|
||||
mod back_of_house;
|
||||
pub mod front_of_house;
|
||||
pub mod back_of_house;
|
||||
|
||||
pub fn eat_at_restaurant() -> String {
|
||||
front_of_house::hosting::add_to_waitlist();
|
||||
|
||||
@ -134,16 +135,14 @@ pub fn take_payment() {}
|
||||
|
||||
// Maybe you don't want the guest hearing the your complaining about them
|
||||
// So just make it private
|
||||
fn complain() {}
|
||||
fn complain() {}
|
||||
```
|
||||
|
||||
5.
|
||||
|
||||
```rust
|
||||
mod front_of_house;
|
||||
|
||||
fn main() {
|
||||
assert_eq!(front_of_house::hosting::seat_at_table(), "sit down please");
|
||||
assert_eq!(hello_package::eat_at_restaurant(),"yummy yummy!");
|
||||
assert_eq!(hello_package::front_of_house::hosting::seat_at_table(), "sit down please");
|
||||
assert_eq!(hello_package::eat_at_restaurant(), "yummy yummy!");
|
||||
}
|
||||
```
|
@ -118,7 +118,7 @@ fn main() {
|
||||
```rust
|
||||
fn fn_once<F>(func: F)
|
||||
where
|
||||
F: FnOnce(usize) -> bool + Copy,// 改动在这里
|
||||
F: Copy + FnOnce(usize) -> bool,// 改动在这里
|
||||
{
|
||||
println!("{}", func(3));
|
||||
println!("{}", func(4));
|
||||
@ -293,4 +293,4 @@ fn factory(x:i32) -> Box<dyn Fn(i32) -> i32> {
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
```
|
||||
```
|
||||
|
@ -149,6 +149,6 @@ fn main() {
|
||||
|
||||
// add one line below to make a compiler error: cannot borrow `s` as mutable more than once at a time
|
||||
// you can't use r1 and r2 at the same time
|
||||
r1.push_str("world");
|
||||
println!("{}, {}", r1, r2);
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -31,6 +31,15 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
fn main() {
|
||||
let x = String::from("hello, world");
|
||||
let y = &x;
|
||||
println!("{},{}",x,y);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
2.
|
||||
|
||||
```rust
|
||||
@ -163,7 +172,18 @@ fn main() {
|
||||
let t = (String::from("hello"), String::from("world"));
|
||||
|
||||
// fill the blanks
|
||||
let (s1, s2) = t.clone();
|
||||
let (ref s1, ref s2) = t;
|
||||
|
||||
println!("{:?}, {:?}, {:?}", s1, s2, t); // -> "hello", "world", ("hello", "world")
|
||||
}
|
||||
```
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
let t = (String::from("hello"), String::from("world"));
|
||||
|
||||
// fill the blanks
|
||||
let (ref s1, ref s2) = t;
|
||||
|
||||
println!("{:?}, {:?}, {:?}", s1, s2, t); // -> "hello", "world", ("hello", "world")
|
||||
}
|
||||
|
@ -19,4 +19,4 @@ git-repository-url = "https://github.com/sunface/rust-by-practice"
|
||||
edit-url-template = "https://github.com/sunface/rust-by-practice/edit/master/zh-CN/{path}"
|
||||
|
||||
[rust]
|
||||
edition = "2021"
|
||||
edition = "2018"
|
||||
|
@ -101,7 +101,7 @@ impl<'a> PartialEq<i32> for &'a T {
|
||||
这里只能使用更高级别的约束,因为引用的生命周期比函数上任何可能的生命周期参数都短。
|
||||
|
||||
4. 🌟🌟🌟
|
||||
```rust
|
||||
```rust,editable
|
||||
/* 添加 HRTB 使下面代码正常运行! */
|
||||
fn call_on_ref_zero<'a, F>(f: F) where F: Fn(&'a i32) {
|
||||
let zero = 0;
|
||||
@ -237,7 +237,7 @@ struct Ref<'a, T> {
|
||||
## 艰难的练习
|
||||
|
||||
6. 🌟🌟🌟🌟
|
||||
```rust
|
||||
```rust,editable
|
||||
/* 使下面代码正常运行 */
|
||||
struct Interface<'a> {
|
||||
manager: &'a mut Manager<'a>
|
||||
|
@ -87,7 +87,7 @@ fn show_message(msg: Message) {
|
||||
fn main() {
|
||||
let alphabets = ['a', 'E', 'Z', '0', 'x', '9' , 'Y'];
|
||||
|
||||
// 使用 `matches` 填空
|
||||
// 使用 `matches!` 填空
|
||||
for ab in alphabets {
|
||||
assert!(__)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
我们使用 [mdbook](https://rust-lang.github.io/mdBook/) 构建在线练习题,你也可以下载到本地运行:
|
||||
```shell
|
||||
$ git clone git@github.com:sunface/rust-by-practice.git
|
||||
$ git clone https://github.com/sunface/rust-by-practice
|
||||
$ cargo install mdbook
|
||||
$ cd rust-by-practice && mdbook serve zh-CN/
|
||||
```
|
||||
|
@ -1,59 +1,62 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="{{ language }}" class="{{ default_theme }}" dir="{{ text_direction }}">
|
||||
<head>
|
||||
<!-- Book generated using mdBook -->
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ title }}</title>
|
||||
{{#if is_print }}
|
||||
<meta name="robots" content="noindex">
|
||||
{{/if}}
|
||||
{{#if base_url}}
|
||||
<base href="{{ base_url }}">
|
||||
{{/if}}
|
||||
|
||||
<head>
|
||||
<!-- Book generated using mdBook -->
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ title }}</title>
|
||||
{{#if is_print }}
|
||||
<meta name="robots" content="noindex">
|
||||
{{/if}}
|
||||
{{#if base_url}}
|
||||
<base href="{{ base_url }}">
|
||||
{{/if}}
|
||||
|
||||
|
||||
<!-- Custom HTML head -->
|
||||
{{> head}}
|
||||
<!-- Custom HTML head -->
|
||||
{{> head}}
|
||||
|
||||
<meta name="description" content="{{ description }}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
<meta name="description" content="{{ description }}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
|
||||
{{#if favicon_svg}}
|
||||
<link rel="icon" href="{{ path_to_root }}favicon.svg">
|
||||
{{/if}}
|
||||
{{#if favicon_png}}
|
||||
<link rel="shortcut icon" href="{{ path_to_root }}favicon.png">
|
||||
{{/if}}
|
||||
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
|
||||
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
|
||||
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
|
||||
{{#if print_enable}}
|
||||
<link rel="stylesheet" href="{{ path_to_root }}css/print.css" media="print">
|
||||
{{/if}}
|
||||
{{#if favicon_svg}}
|
||||
<link rel="icon" href="{{ path_to_root }}favicon.svg">
|
||||
{{/if}}
|
||||
{{#if favicon_png}}
|
||||
<link rel="shortcut icon" href="{{ path_to_root }}favicon.png">
|
||||
{{/if}}
|
||||
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
|
||||
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
|
||||
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
|
||||
{{#if print_enable}}
|
||||
<link rel="stylesheet" href="{{ path_to_root }}css/print.css" media="print">
|
||||
{{/if}}
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
|
||||
{{#if copy_fonts}}
|
||||
<link rel="stylesheet" href="{{ path_to_root }}fonts/fonts.css">
|
||||
{{/if}}
|
||||
<!-- Fonts -->
|
||||
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
|
||||
{{#if copy_fonts}}
|
||||
<link rel="stylesheet" href="{{ path_to_root }}fonts/fonts.css">
|
||||
{{/if}}
|
||||
|
||||
<!-- Highlight.js Stylesheets -->
|
||||
<link rel="stylesheet" href="{{ path_to_root }}highlight.css">
|
||||
<link rel="stylesheet" href="{{ path_to_root }}tomorrow-night.css">
|
||||
<link rel="stylesheet" href="{{ path_to_root }}ayu-highlight.css">
|
||||
<!-- Highlight.js Stylesheets -->
|
||||
<link rel="stylesheet" href="{{ path_to_root }}highlight.css">
|
||||
<link rel="stylesheet" href="{{ path_to_root }}tomorrow-night.css">
|
||||
<link rel="stylesheet" href="{{ path_to_root }}ayu-highlight.css">
|
||||
|
||||
<!-- Custom theme stylesheets -->
|
||||
{{#each additional_css}}
|
||||
<link rel="stylesheet" href="{{ ../path_to_root }}{{ this }}">
|
||||
{{/each}}
|
||||
<!-- Custom theme stylesheets -->
|
||||
{{#each additional_css}}
|
||||
<link rel="stylesheet" href="{{ ../path_to_root }}{{ this }}">
|
||||
{{/each}}
|
||||
|
||||
{{#if mathjax_support}}
|
||||
<!-- MathJax -->
|
||||
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||||
{{/if}}
|
||||
</head>
|
||||
<body class="sidebar-visible no-js">
|
||||
{{#if mathjax_support}}
|
||||
<!-- MathJax -->
|
||||
<script async
|
||||
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||||
{{/if}}
|
||||
</head>
|
||||
|
||||
<body class="sidebar-visible no-js">
|
||||
<div id="body-container">
|
||||
<!-- Provide site root to javascript -->
|
||||
<script>
|
||||
@ -80,7 +83,7 @@
|
||||
<!-- Set the theme before any content is loaded, prevents flash -->
|
||||
<script>
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
|
||||
if (theme === null || theme === undefined) { theme = default_theme; }
|
||||
var html = document.querySelector('html');
|
||||
html.classList.remove('{{ default_theme }}')
|
||||
@ -98,7 +101,7 @@
|
||||
var sidebar = null;
|
||||
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
|
||||
if (document.body.clientWidth >= 1080) {
|
||||
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
|
||||
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch (e) { }
|
||||
sidebar = sidebar || 'visible';
|
||||
} else {
|
||||
sidebar = 'hidden';
|
||||
@ -120,7 +123,7 @@
|
||||
<!-- Track and set sidebar scroll position -->
|
||||
<script>
|
||||
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
|
||||
sidebarScrollbox.addEventListener('click', function(e) {
|
||||
sidebarScrollbox.addEventListener('click', function (e) {
|
||||
if (e.target.tagName === 'A') {
|
||||
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
|
||||
}
|
||||
@ -138,7 +141,7 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
||||
<div class="page">
|
||||
@ -146,10 +149,14 @@
|
||||
<div id="menu-bar-hover-placeholder"></div>
|
||||
<div id="menu-bar" class="menu-bar sticky">
|
||||
<div class="left-buttons">
|
||||
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
|
||||
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor"
|
||||
title="Toggle Table of Contents" aria-label="Toggle Table of Contents"
|
||||
aria-controls="sidebar">
|
||||
<i class="fa fa-bars"></i>
|
||||
</label>
|
||||
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
|
||||
<button id="theme-toggle" class="icon-button" type="button" title="Change theme"
|
||||
aria-label="Change theme" aria-haspopup="true" aria-expanded="false"
|
||||
aria-controls="theme-list">
|
||||
<i class="fa fa-paint-brush"></i>
|
||||
</button>
|
||||
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
|
||||
@ -160,7 +167,9 @@
|
||||
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
|
||||
</ul>
|
||||
{{#if search_enabled}}
|
||||
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
|
||||
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)"
|
||||
aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S"
|
||||
aria-controls="searchbar">
|
||||
<i class="fa fa-search"></i>
|
||||
</button>
|
||||
{{/if}}
|
||||
@ -191,7 +200,8 @@
|
||||
{{#if search_enabled}}
|
||||
<div id="search-wrapper" class="hidden">
|
||||
<form id="searchbar-outer" class="searchbar-outer">
|
||||
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
||||
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..."
|
||||
aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
||||
</form>
|
||||
<div id="searchresults-outer" class="searchresults-outer hidden">
|
||||
<div id="searchresults-header" class="searchresults-header"></div>
|
||||
@ -205,14 +215,16 @@
|
||||
<script>
|
||||
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
|
||||
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
|
||||
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
|
||||
Array.from(document.querySelectorAll('#sidebar a')).forEach(function (link) {
|
||||
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="content" class="content">
|
||||
<!-- Page table of contents -->
|
||||
<div class="sidetoc"><nav class="pagetoc"></nav></div>
|
||||
<div class="sidetoc">
|
||||
<nav class="pagetoc"></nav>
|
||||
</div>
|
||||
<main>
|
||||
{{{ content }}}
|
||||
<div id="giscus-container"></div>
|
||||
@ -221,15 +233,17 @@
|
||||
<nav class="nav-wrapper" aria-label="Page navigation">
|
||||
<!-- Mobile navigation buttons -->
|
||||
{{#previous}}
|
||||
<a rel="prev" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
<a rel="prev" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters previous"
|
||||
title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
{{/previous}}
|
||||
|
||||
{{#next}}
|
||||
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters next"
|
||||
title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
{{/next}}
|
||||
|
||||
<div style="clear: both"></div>
|
||||
@ -239,15 +253,17 @@
|
||||
|
||||
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
||||
{{#previous}}
|
||||
<a rel="prev" href="{{ path_to_root }}{{link}}" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
<a rel="prev" href="{{ path_to_root }}{{link}}" class="nav-chapters previous" title="Previous chapter"
|
||||
aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
{{/previous}}
|
||||
|
||||
{{#next}}
|
||||
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="nav-chapters next" title="Next chapter"
|
||||
aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
{{/next}}
|
||||
</nav>
|
||||
|
||||
@ -266,7 +282,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
window.onbeforeunload = function () {
|
||||
socket.close();
|
||||
}
|
||||
</script>
|
||||
@ -280,10 +296,12 @@
|
||||
// make sure we don't activate google analytics if the developer is
|
||||
// inspecting the book locally...
|
||||
if (localAddrs.indexOf(document.location.hostname) === -1) {
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||
(function (i, s, o, g, r, a, m) {
|
||||
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
|
||||
(i[r].q = i[r].q || []).push(arguments)
|
||||
}, i[r].l = 1 * new Date(); a = s.createElement(o),
|
||||
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
|
||||
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
|
||||
|
||||
ga('create', '{{google_analytics}}', 'auto');
|
||||
ga('send', 'pageview');
|
||||
@ -322,7 +340,7 @@
|
||||
<script src="{{ path_to_root }}book.js"></script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
var pagePath = "{{ path }}"
|
||||
var pagePath = "{{ path }}"
|
||||
</script>
|
||||
|
||||
|
||||
@ -334,21 +352,22 @@
|
||||
{{#if is_print}}
|
||||
{{#if mathjax_support}}
|
||||
<script>
|
||||
window.addEventListener('load', function() {
|
||||
MathJax.Hub.Register.StartupHook('End', function() {
|
||||
window.setTimeout(window.print, 100);
|
||||
window.addEventListener('load', function () {
|
||||
MathJax.Hub.Register.StartupHook('End', function () {
|
||||
window.setTimeout(window.print, 100);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{{else}}
|
||||
<script>
|
||||
window.addEventListener('load', function() {
|
||||
window.setTimeout(window.print, 100);
|
||||
});
|
||||
window.addEventListener('load', function () {
|
||||
window.setTimeout(window.print, 100);
|
||||
});
|
||||
</script>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in New Issue
Block a user