Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The book doesn't really work locally #1106

Closed
DjebbZ opened this issue Sep 25, 2018 · 5 comments
Closed

The book doesn't really work locally #1106

DjebbZ opened this issue Sep 25, 2018 · 5 comments

Comments

@DjebbZ
Copy link

DjebbZ commented Sep 25, 2018

Hello,

While trying to solve another problem (#1105), I noticed that it doesn't really work locally. I was trying with mdbook 0.1.8 in the train while commuting this morning, and page rendering was blocked by the several calls to CDNs for various js libs. Since I was connected but had poor connectivity, the downloads of the js libs never really happened but the browser kept trying in vain. I expected the book to work fully locally since the README says If you'd like to read it locally -- apart from running the code, but at least this part is explicit in the README.

I think of several things that could solve the problem:

  • add async to the script tags so they don't block the rendering of the HTML,
  • put script tags to the end,
  • just don't use CDN and always serve assets locally.

I know nothing about mdbook, maybe it should be done there? Maybe it's specific to rust-by-example? Maybe these things have already been discussed and the current situation is what you want?

@steveklabnik
Copy link
Member

I think this should be on mdbook, but I'd have to double check. We want everything to work offline, but maybe something regressed...

@ghost
Copy link

ghost commented Oct 25, 2018

Hardcoded book.css appears to be now css/chrome.css (mdBook v0.2.3-alpha.0) otherwise not found.

<link rel="stylesheet" href="book.css">

Hardcoded store.js is not found (guessing it was generated by an older mdBook?)

<script src="store.js"></script>

Hardcoded cdn urls:

<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

<script src="https://cdn.jsdelivr.net/clipboard.js/1.6.1/clipboard.min.js"></script>

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

Thus fails to render locally even when allowed CDNs (possibly due to store.js ? or due to using newer mdBook)
screenshot_2018-10-25_18-04-28

EDIT: Note to self: it works but must build using mdBook 0.1.7 Thanks steveklabnik
EDIT2: I just noticed that the fact that 0.1.7 is needed is already (indirectly)mentioned in rust-lang/book repo here: https://github.com/rust-lang/book/blob/7fcf50e414ef92a3067cd6532b81975c25561ab9/README.md#requirements

@kstenerud
Copy link

I tried it using the latest mdbook (2.2) and it doesn't work. It tries and fails to connect to a whole bunch of sites. Also, once I do connect to the internet, it still doesn't display correctly, and half of the chapter links don't work.

This is how it renders on every page (that works). The complete TOC listed in full on every page is how it actually renders (in FF).

Introduction
1. Hello World
    1.1. Comments
    1.2. Formatted print
        1.2.1. Debug
        1.2.2. Display
            1.2.2.1. Testcase: List
        1.2.3. Formatting
2. Primitives
    2.1. Literals and operators
    2.2. Tuples
    2.3. Arrays and Slices
3. Custom Types
    3.1. Structures
    3.2. Enums
        3.2.1. use
        3.2.2. C-like
        3.2.3. Testcase: linked-list
    3.3. constants
4. Variable Bindings
    4.1. Mutability
    4.2. Scope and Shadowing
    4.3. Declare first
5. Types
    5.1. Casting
    5.2. Literals
    5.3. Inference
    5.4. Aliasing
6. Conversion
    6.1. From and Into
    6.2. To and from Strings
7. Expressions
8. Flow Control
    8.1. if/else
    8.2. loop
        8.2.1. Nesting and labels
        8.2.2. Returning from loops
    8.3. while
    8.4. for and range
    8.5. match
        8.5.1. Destructuring
            8.5.1.1. tuples
            8.5.1.2. enums
            8.5.1.3. pointers/ref
            8.5.1.4. structs
        8.5.2. Guards
        8.5.3. Binding
    8.6. if let
    8.7. while let
9. Functions
    9.1. Methods
    9.2. Closures
        9.2.1. Capturing
        9.2.2. As input parameters
        9.2.3. Type anonymity
        9.2.4. Input functions
        9.2.5. As output parameters
        9.2.6. Examples in std
            9.2.6.1. Iterator::any
            9.2.6.2. Iterator::find
    9.3. Higher Order Functions
    9.4. Diverging functions
10. Modules
    10.1. Visibility
    10.2. Struct visibility
    10.3. The use declaration
    10.4. super and self
    10.5. File hierarchy
11. Crates
    11.1. Library
    11.2. extern crate
12. Cargo
    12.1. Dependencies
    12.2. Conventions
    12.3. Tests
    12.4. Build Scripts
13. Attributes
    13.1. dead_code
    13.2. Crates
    13.3. cfg
        13.3.1. Custom
14. Generics
    14.1. Functions
    14.2. Implementation
    14.3. Traits
    14.4. Bounds
        14.4.1. Testcase: empty bounds
    14.5. Multiple bounds
    14.6. Where clauses
    14.7. New Type Idiom
    14.8. Associated items
        14.8.1. The Problem
        14.8.2. Associated types
    14.9. Phantom type parameters
        14.9.1. Testcase: unit clarification
15. Scoping rules
    15.1. RAII
    15.2. Ownership and moves
        15.2.1. Mutability
    15.3. Borrowing
        15.3.1. Mutability
        15.3.2. Freezing
        15.3.3. Aliasing
        15.3.4. The ref pattern
    15.4. Lifetimes
        15.4.1. Explicit annotation
        15.4.2. Functions
        15.4.3. Methods
        15.4.4. Structs
        15.4.5. Bounds
        15.4.6. Coercion
        15.4.7. Static
        15.4.8. Elision
16. Traits
    16.1. Derive
    16.2. Operator Overloading
    16.3. Drop
    16.4. Iterators
    16.5. Clone
17. macro_rules!
    17.1. Syntax
        17.1.1. Designators
        17.1.2. Overload
        17.1.3. Repeat
    17.2. DRY (Don't Repeat Yourself)
    17.3. DSL (Domain Specific Languages)
    17.4. Variadics
18. Error handling
    18.1. panic
    18.2. Option & unwrap
        18.2.1. Combinators: map
        18.2.2. Combinators: and_then
    18.3. Result
        18.3.1. map for Result
        18.3.2. aliases for Result
        18.3.3. Early returns
        18.3.4. Introducing ?
    18.4. Multiple error types
        18.4.1. Pulling Results out of Options
        18.4.2. Defining an error type
        18.4.3. Boxing errors
        18.4.4. Other uses of ?
        18.4.5. Wrapping errors
    18.5. Iterating over Results
19. Std library types
    19.1. Box, stack and heap
    19.2. Vectors
    19.3. Strings
    19.4. Option
    19.5. Result
        19.5.1. ?
    19.6. panic!
    19.7. HashMap
        19.7.1. Alternate/custom key types
        19.7.2. HashSet
20. Std misc
    20.1. Threads
        20.1.1. Testcase: map-reduce
    20.2. Channels
    20.3. Path
    20.4. File I/O
        20.4.1. open
        20.4.2. create
    20.5. Child processes
        20.5.1. Pipes
        20.5.2. Wait
    20.6. Filesystem Operations
    20.7. Program arguments
        20.7.1. Argument parsing
    20.8. Foreign Function Interface
21. Testing
    21.1. Unit testing
    21.2. Documentation testing
    21.3. Integration testing
    21.4. Dev-dependencies
22. Unsafe Operations
23. Compatibility
    23.1. Raw identifiers
24. Meta
    24.1. Documentation

Edit
Rust By Example
Primitives

Rust provides access to a wide variety of
primitives
. A sample includes:
Scalar Types

signed integers:
i8
,
i16
,
i32
,
i64
,
i128
and
isize
(pointer size)
unsigned integers:
u8
,
u16
,
u32
,
u64
,
u128
and
usize
(pointer size)
floating point:
f32
,
f64
char
Unicode scalar values like
'a'
,
'α'
and
'∞'
(4 bytes each)
bool
either
true
or
false
and the unit type
()
, whose only possible value is an empty tuple:
()

Despite the value of a unit type being a tuple, it is not considered a compound type because it does not contain multiple values.
Compound Types

arrays like
[1, 2, 3]
tuples like
(1, true)

Variables can always be type annotated. Numbers may additionally be annotated via a suffix or by default. Integers default to
i32
and floats to
f64
. Note that Rust can also infer types from context.

fn main() {
// Variables can be type annotated.
let logical: bool = true;

let a_float: f64 = 1.0;  // Regular annotation
let an_integer   = 5i32; // Suffix annotation

// Or a default will be used.
let default_float   = 3.0; // `f64`
let default_integer = 7;   // `i32`

// A type can also be inferred from context 
let mut inferred_type = 12; // Type i64 is inferred from another line
inferred_type = 4294967296i64;

// A mutable variable's value can be changed.
let mut mutable = 12; // Mutable `i32`
mutable = 21;

// Error! The type of a variable can't be changed.
mutable = true;

// Variables can be overwritten with shadowing.
let mutable = true;

}

See also:

the
std
library,
mut
, inference, and shadowing
ws://localhost:3001

@ghost
Copy link

ghost commented Nov 12, 2018

I tried it using the latest mdbook (2.2) and it doesn't work. It tries and fails to connect to a whole bunch of sites. Also, once I do connect to the internet, it still doesn't display correctly, and half of the chapter links don't work.

You might have to use (like I did) mdBook version 0.1.7 (as per this which leads to this). Also mentioned here.

@ghost
Copy link

ghost commented Jan 3, 2019

works for me today even though I've mdBook v0.2.3-alpha.0 installed (more info)
maybe it's no longer an issue?

The only thing is trying to get from the internet is two fonts.googleapis.com fonts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants