Arc-ify Library

This commit is contained in:
Vincent Prouillet 2019-01-27 18:57:07 +01:00
parent 99a191bf85
commit 21d67235ae
7 changed files with 324 additions and 274 deletions

154
Cargo.lock generated
View file

@ -22,16 +22,16 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-signal 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"trust-dns-proto 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trust-dns-resolver 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"trust-dns-resolver 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -48,15 +48,15 @@ dependencies = [
"net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-current-thread 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"tower-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trust-dns-resolver 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"trust-dns-resolver 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -98,12 +98,12 @@ dependencies = [
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-current-thread 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"v_htmlescape 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -382,6 +382,21 @@ dependencies = [
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "crossbeam"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-channel 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "crossbeam-channel"
version = "0.3.6"
@ -712,6 +727,11 @@ dependencies = [
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fuchsia-cprng"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
@ -891,13 +911,13 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -937,7 +957,7 @@ dependencies = [
"same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1372,10 +1392,9 @@ dependencies = [
[[package]]
name = "num-derive"
version = "0.2.3"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1642,10 +1661,10 @@ dependencies = [
[[package]]
name = "rand"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1654,13 +1673,13 @@ dependencies = [
[[package]]
name = "rand"
version = "0.5.5"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1690,14 +1709,6 @@ dependencies = [
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_core"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_core"
version = "0.3.1"
@ -1818,14 +1829,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.4"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1881,11 +1892,11 @@ dependencies = [
"serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_urlencoded 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1941,7 +1952,7 @@ name = "same-file"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2248,7 +2259,7 @@ dependencies = [
"lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"onig 4.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"plist 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2360,7 +2371,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -2376,7 +2387,7 @@ dependencies = [
[[package]]
name = "tokio"
version = "0.1.14"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2389,9 +2400,10 @@ dependencies = [
"tokio-fs 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-sync 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -2431,7 +2443,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2477,6 +2489,14 @@ dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-sync"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-tcp"
version = "0.1.3"
@ -2492,9 +2512,10 @@ dependencies = [
[[package]]
name = "tokio-threadpool"
version = "0.1.10"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crossbeam 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-channel 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2502,12 +2523,13 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-timer"
version = "0.2.8"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2574,21 +2596,21 @@ dependencies = [
"idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "trust-dns-proto"
version = "0.6.2"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2597,21 +2619,21 @@ dependencies = [
"idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "trust-dns-resolver"
version = "0.10.2"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2623,8 +2645,8 @@ dependencies = [
"lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"resolv-conf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"trust-dns-proto 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"trust-dns-proto 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2785,7 +2807,7 @@ name = "uuid"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2875,7 +2897,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2919,7 +2941,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-util"
version = "0.1.1"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2936,7 +2958,7 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2966,7 +2988,7 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3057,6 +3079,7 @@ dependencies = [
"checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa"
"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb"
"checksum crc32fast 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e91d5240c6975ef33aeb5f148f35275c25eda8e8a5f95abe421978b05b8bf192"
"checksum crossbeam 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad4c7ea749d9fb09e23c5cb17e3b70650860553a0e2744e38446b1803bf7db94"
"checksum crossbeam-channel 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "137bc235f622ffaa0428e3854e24acb53291fc0b3ff6fb2cb75a8be6fb02f06b"
"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3"
"checksum crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "05e44b8cf3e1a625844d1750e1f7820da46044ff6d28f4d43e455ba3e5bb2c13"
@ -3093,6 +3116,7 @@ dependencies = [
"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
"checksum fsevent 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c4bbbf71584aeed076100b5665ac14e3d85eeb31fdbb45fbd41ef9a682b5ec05"
"checksum fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a772d36c338d07a032d5375a36f15f9a7043bf0cb8ce7cee658e037c6032874"
"checksum fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81f7f8eb465745ea9b02e2704612a9946a59fa40572086c6fd49d6ddcf30bf31"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum futf 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7c9c1ce3fa9336301af935ab852c437817d14cd33690446569392e65170aac3b"
@ -3159,7 +3183,7 @@ dependencies = [
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum nom 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9c349f68f25f596b9f44cf0e7c69752a5c633b0550c3ff849518bfba0233774a"
"checksum notify 4.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c968cf37cf949114b00d51b0b23536d1c3a4a3963767cf4c969c65a6af78dc7d"
"checksum num-derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8af1847c907c2f04d7bfd572fb25bbb4385c637fe5be163cf2f8c5d778fe1e7d"
"checksum num-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d9fe8fcafd1b86a37ce8a1cfa15ae504817e0c8c2e7ad42767371461ac1d316d"
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124"
"checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10"
@ -3190,11 +3214,10 @@ dependencies = [
"checksum pulldown-cmark 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eef52fac62d0ea7b9b4dc7da092aa64ea7ec3d90af6679422d3d7e0e14b6ee15"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
"checksum rand 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dee497e66d8d76bf08ce20c8d36e16f93749ab0bf89975b4f8ae5cee660c2da2"
"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c"
"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
"checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9"
"checksum rand 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3906503e80ac6cbcacb2c2973fa8e473f24d7e2747c8c92bb230c2441cad96b5"
"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
"checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372"
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
@ -3208,7 +3231,7 @@ dependencies = [
"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f"
"checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1"
"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum reqwest 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)" = "09d6e187a58d923ee132fcda141c94e716bcfe301c2ea2bef5c81536e0085376"
"checksum resolv-conf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b263b4aa1b5de9ffc0054a2386f96992058bb6870aab516f8cdeb8a667d56dcb"
@ -3261,7 +3284,7 @@ dependencies = [
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum tiff 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a2cc6c4fd13cb1cfd20abdb196e794ceccb29371855b7e7f575945f920a5b3c2"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
"checksum tokio 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4790d0be6f4ba6ae4f48190efa2ed7780c9e3567796abdb285003cf39840d9c5"
"checksum tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "e0500b88064f08bebddd0c0bed39e19f5c567a5f30975bee52b0c0d3e2eeb38c"
"checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f"
"checksum tokio-current-thread 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "331c8acc267855ec06eb0c94618dcbbfea45bed2d20b77252940095273fb58f6"
"checksum tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30c6dbf2d1ad1de300b393910e8a3aa272b724a400b6531da03eed99e329fbf0"
@ -3269,16 +3292,17 @@ dependencies = [
"checksum tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b53aeb9d3f5ccf2ebb29e19788f96987fa1355f8fe45ea193928eaaaf3ae820f"
"checksum tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "afbcdb0f0d2a1e4c440af82d7bbf0bf91a8a8c0575bcd20c05d15be7e9d3a02f"
"checksum tokio-signal 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "dd6dc5276ea05ce379a16de90083ec80836440d5ef8a6a39545a3207373b8296"
"checksum tokio-sync 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d65a58e2215c13179e6eeb2cf00511e0aee455cad40a9bfaef15a2fd8aab1c7"
"checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119"
"checksum tokio-threadpool 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "17465013014410310f9f61fa10bf4724803c149ea1d51efece131c38efca93aa"
"checksum tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4f37f0111d76cc5da132fe9bc0590b9b9cfd079bc7e75ac3846278430a299ff8"
"checksum tokio-threadpool 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c3fd86cb15547d02daa2b21aadaf4e37dee3368df38a526178a5afa3c034d2fb"
"checksum tokio-timer 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "21c04a314a1f69f73c0227beba6250e06cdc1e9a62e7eff912bf54a59b6d1b94"
"checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92"
"checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445"
"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
"checksum tower-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b32f72af77f1bfe3d3d4da8516a238ebe7039b51dd8637a09841ac7f16d2c987"
"checksum trust-dns-proto 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0838272e89f1c693b4df38dc353412e389cf548ceed6f9fd1af5a8d6e0e7cf74"
"checksum trust-dns-proto 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30dde452f5d142d5e316a3b32386da95280c98b7e266639f8f3bc6fdf507d279"
"checksum trust-dns-resolver 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "de630f95a192f793436ffae5137e88253cc4142a97d9a8e73c8d804fa85ddf0a"
"checksum trust-dns-proto 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "09144f0992b0870fa8d2972cc069cbf1e3c0fda64d1f3d45c4d68d0e0b52ad4e"
"checksum trust-dns-resolver 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8a9f877f7a1ad821ab350505e1f1b146a4960402991787191d6d8cab2ce2de2c"
"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
"checksum ucd-trie 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "71a9c5b1fe77426cf144cc30e49e955270f5086e31a6441dfa8b32efc09b9d77"
@ -3318,7 +3342,7 @@ dependencies = [
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab"
"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba"
"checksum winreg 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a27a759395c1195c4cc5cda607ef6f8f6498f64e78f7900f5de0a127a424704a"

View file

@ -98,22 +98,21 @@ fn find_page_front_matter_changes(
/// Handles a path deletion: could be a page, a section, a folder
fn delete_element(site: &mut Site, path: &Path, is_section: bool) -> Result<()> {
// Ignore the event if this path was not known
if !site.library.contains_section(&path.to_path_buf())
&& !site.library.contains_page(&path.to_path_buf())
{
return Ok(());
}
if is_section {
if let Some(s) = site.library.remove_section(&path.to_path_buf()) {
site.permalinks.remove(&s.file.relative);
let mut library = site.library.write().unwrap();
// Ignore the event if this path was not known
if !library.contains_section(&path.to_path_buf())
&& !library.contains_page(&path.to_path_buf())
{
return Ok(());
}
} else if let Some(p) = site.library.remove_page(&path.to_path_buf()) {
site.permalinks.remove(&p.file.relative);
if !p.meta.taxonomies.is_empty() {
site.populate_taxonomies()?;
if is_section {
if let Some(s) = library.remove_section(&path.to_path_buf()) {
site.permalinks.remove(&s.file.relative);
}
} else if let Some(p) = library.remove_page(&path.to_path_buf()) {
site.permalinks.remove(&p.file.relative);
}
}
@ -135,28 +134,32 @@ fn handle_section_editing(site: &mut Site, path: &Path) -> Result<()> {
// Updating a section
Some(prev) => {
site.populate_sections();
{
let library = site.library.read().unwrap();
if site.library.get_section(&pathbuf).unwrap().meta == prev.meta {
// Front matter didn't change, only content did
// so we render only the section page, not its pages
return site.render_section(&site.library.get_section(&pathbuf).unwrap(), false);
if library.get_section(&pathbuf).unwrap().meta == prev.meta {
// Front matter didn't change, only content did
// so we render only the section page, not its pages
return site.render_section(&library.get_section(&pathbuf).unwrap(), false);
}
}
// Front matter changed
for changes in find_section_front_matter_changes(
&site.library.get_section(&pathbuf).unwrap().meta,
let changes = find_section_front_matter_changes(
&site.library.read().unwrap().get_section(&pathbuf).unwrap().meta,
&prev.meta,
) {
);
for change in changes {
// Sort always comes first if present so the rendering will be fine
match changes {
match change {
SectionChangesNeeded::Sort => {
site.register_tera_global_fns();
}
SectionChangesNeeded::Render => {
site.render_section(&site.library.get_section(&pathbuf).unwrap(), false)?
site.render_section(&site.library.read().unwrap().get_section(&pathbuf).unwrap(), false)?
}
SectionChangesNeeded::RenderWithPages => {
site.render_section(&site.library.get_section(&pathbuf).unwrap(), true)?
site.render_section(&site.library.read().unwrap().get_section(&pathbuf).unwrap(), true)?
}
// not a common enough operation to make it worth optimizing
SectionChangesNeeded::Delete | SectionChangesNeeded::Transparent => {
@ -170,14 +173,14 @@ fn handle_section_editing(site: &mut Site, path: &Path) -> Result<()> {
None => {
site.populate_sections();
site.register_tera_global_fns();
site.render_section(&site.library.get_section(&pathbuf).unwrap(), true)
site.render_section(&site.library.read().unwrap().get_section(&pathbuf).unwrap(), true)
}
}
}
macro_rules! render_parent_section {
($site: expr, $path: expr) => {
if let Some(s) = $site.library.find_parent_section($path) {
if let Some(s) = $site.library.read().unwrap().find_parent_section($path) {
$site.render_section(s, false)?;
};
};
@ -192,27 +195,31 @@ fn handle_page_editing(site: &mut Site, path: &Path) -> Result<()> {
Some(prev) => {
site.populate_sections();
site.populate_taxonomies()?;
site.register_tera_global_fns();
{
let library = site.library.read().unwrap();
// Front matter didn't change, only content did
if site.library.get_page(&pathbuf).unwrap().meta == prev.meta {
// Other than the page itself, the summary might be seen
// on a paginated list for a blog for example
if site.library.get_page(&pathbuf).unwrap().summary.is_some() {
render_parent_section!(site, path);
// Front matter didn't change, only content did
if library.get_page(&pathbuf).unwrap().meta == prev.meta {
// Other than the page itself, the summary might be seen
// on a paginated list for a blog for example
if library.get_page(&pathbuf).unwrap().summary.is_some() {
render_parent_section!(site, path);
}
return site.render_page(&library.get_page(&pathbuf).unwrap());
}
site.register_tera_global_fns();
return site.render_page(&site.library.get_page(&pathbuf).unwrap());
}
// Front matter changed
for changes in find_page_front_matter_changes(
&site.library.get_page(&pathbuf).unwrap().meta,
let changes = find_page_front_matter_changes(
&site.library.read().unwrap().get_page(&pathbuf).unwrap().meta,
&prev.meta,
) {
);
for change in changes {
site.register_tera_global_fns();
// Sort always comes first if present so the rendering will be fine
match changes {
match change {
PageChangesNeeded::Taxonomies => {
site.populate_taxonomies()?;
site.render_taxonomies()?;
@ -222,7 +229,7 @@ fn handle_page_editing(site: &mut Site, path: &Path) -> Result<()> {
}
PageChangesNeeded::Render => {
render_parent_section!(site, path);
site.render_page(&site.library.get_page(&path.to_path_buf()).unwrap())?;
site.render_page(&site.library.read().unwrap().get_page(&path.to_path_buf()).unwrap())?;
}
};
}
@ -275,8 +282,11 @@ pub fn after_content_rename(site: &mut Site, old: &Path, new: &Path) -> Result<(
if new_path.file_name().unwrap() == "_index.md" {
// We aren't entirely sure where the original thing was so just try to delete whatever was
// at the old path
site.library.remove_page(&old.to_path_buf());
site.library.remove_section(&old.to_path_buf());
{
let mut library = site.library.write().unwrap();
library.remove_page(&old.to_path_buf());
library.remove_section(&old.to_path_buf());
}
return handle_section_editing(site, &new_path);
}
@ -287,7 +297,7 @@ pub fn after_content_rename(site: &mut Site, old: &Path, new: &Path) -> Result<(
} else {
old.to_path_buf()
};
site.library.remove_page(&old_path);
site.library.write().unwrap().remove_page(&old_path);
handle_page_editing(site, &new_path)
}
@ -350,7 +360,7 @@ pub fn after_template_change(site: &mut Site, path: &Path) -> Result<()> {
match filename {
"sitemap.xml" => site.render_sitemap(),
"rss.xml" => site.render_rss_feed(site.library.pages_values(), None),
"rss.xml" => site.render_rss_feed(site.library.read().unwrap().pages_values(), None),
"robots.txt" => site.render_robots(),
"single.html" | "list.html" => site.render_taxonomies(),
"page.html" => {

View file

@ -22,7 +22,7 @@ extern crate tempfile;
use std::collections::HashMap;
use std::fs::{copy, create_dir_all, remove_dir_all};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::sync::{Arc, Mutex, RwLock};
use glob::glob;
use rayon::prelude::*;
@ -72,7 +72,7 @@ pub struct Site {
/// We need that if there are relative links in the content that need to be resolved
pub permalinks: HashMap<String, String>,
/// Contains all pages and sections of the site
pub library: Library,
pub library: Arc<RwLock<Library>>,
}
impl Site {
@ -141,7 +141,7 @@ impl Site {
taxonomies: Vec::new(),
permalinks: HashMap::new(),
// We will allocate it properly later on
library: Library::new(0, 0, false),
library: Arc::new(RwLock::new(Library::new(0, 0, false))),
};
Ok(site)
@ -167,9 +167,9 @@ impl Site {
self.live_reload = get_available_port(port_to_avoid);
}
/// Get all the orphan (== without section) pages in the site
pub fn get_all_orphan_pages(&self) -> Vec<&Page> {
self.library.get_all_orphan_pages()
/// Get the number of orphan (== without section) pages in the site
pub fn get_number_orphan_pages(&self) -> usize {
self.library.read().unwrap().get_all_orphan_pages().len()
}
pub fn set_base_url(&mut self, base_url: String) {
@ -197,7 +197,7 @@ impl Site {
});
self.library =
Library::new(page_entries.len(), section_entries.len(), self.config.is_multilingual());
Arc::new(RwLock::new(Library::new(page_entries.len(), section_entries.len(), self.config.is_multilingual())));
let sections = {
let config = &self.config;
@ -233,7 +233,7 @@ impl Site {
// Insert a default index section for each language if necessary so we don't need to create
// a _index.md to render the index page at the root of the site
for (index_path, lang) in self.index_section_paths() {
if let Some(ref index_section) = self.library.get_section(&index_path) {
if let Some(ref index_section) = self.library.read().unwrap().get_section(&index_path) {
if self.config.build_search_index && !index_section.meta.in_search_index {
bail!(
"You have enabled search in the config but disabled it in the index section: \
@ -242,8 +242,9 @@ impl Site {
)
}
}
let mut library = self.library.write().expect("Get lock for load");
// Not in else because of borrow checker
if !self.library.contains_section(&index_path) {
if !library.contains_section(&index_path) {
let mut index_section = Section::default();
index_section.file.parent = self.content_path.clone();
index_section.file.filename =
@ -261,7 +262,7 @@ impl Site {
index_section.file.path = self.content_path.join("_index.md");
index_section.file.relative = "_index.md".to_string();
}
self.library.insert_section(index_section);
library.insert_section(index_section);
}
}
@ -295,14 +296,15 @@ impl Site {
// This is needed in the first place because of silly borrow checker
let mut pages_insert_anchors = HashMap::new();
for (_, p) in self.library.pages() {
for (_, p) in self.library.read().unwrap().pages() {
pages_insert_anchors.insert(
p.file.path.clone(),
self.find_parent_section_insert_anchor(&p.file.parent.clone(), &p.lang),
);
}
self.library
let mut library = self.library.write().expect("Get lock for render_markdown");
library
.pages_mut()
.values_mut()
.collect::<Vec<_>>()
@ -313,7 +315,7 @@ impl Site {
})
.collect::<Result<()>>()?;
self.library
library
.sections_mut()
.values_mut()
.collect::<Vec<_>>()
@ -347,11 +349,11 @@ impl Site {
}
pub fn register_tera_global_fns(&mut self) {
self.tera.register_function("get_page", global_fns::GetPage::new(&self.library));
self.tera.register_function("get_section", global_fns::GetSection::new(&self.library));
self.tera.register_function("get_page", global_fns::GetPage::new(self.base_path.clone(), self.library.clone()));
self.tera.register_function("get_section", global_fns::GetSection::new(self.base_path.clone(), self.library.clone()));
self.tera.register_function(
"get_taxonomy",
global_fns::GetTaxonomy::new(&self.taxonomies, &self.library),
global_fns::GetTaxonomy::new(self.taxonomies.clone(), self.library.clone()),
);
}
@ -366,8 +368,9 @@ impl Site {
self.find_parent_section_insert_anchor(&page.file.parent, &page.lang);
page.render_markdown(&self.permalinks, &self.tera, &self.config, insert_anchor)?;
}
let prev = self.library.remove_page(&page.file.path);
self.library.insert_page(page);
let mut library = self.library.write().expect("Get lock for add_page");
let prev = library.remove_page(&page.file.path);
library.insert_page(page);
Ok(prev)
}
@ -381,8 +384,9 @@ impl Site {
if render {
section.render_markdown(&self.permalinks, &self.tera, &self.config)?;
}
let prev = self.library.remove_section(&section.file.path);
self.library.insert_section(section);
let mut library = self.library.write().expect("Get lock for add_section");
let prev = library.remove_section(&section.file.path);
library.insert_section(section);
Ok(prev)
}
@ -399,7 +403,7 @@ impl Site {
} else {
parent_path.join("_index.md")
};
match self.library.get_section(&parent) {
match self.library.read().unwrap().get_section(&parent) {
Some(s) => s.meta.insert_anchor_links,
None => InsertAnchor::None,
}
@ -408,7 +412,8 @@ impl Site {
/// Find out the direct subsections of each subsection if there are some
/// as well as the pages for each section
pub fn populate_sections(&mut self) {
self.library.populate_sections();
let mut library = self.library.write().expect("Get lock for populate_sections");
library.populate_sections();
}
/// Find all the tags and categories if it's asked in the config
@ -417,7 +422,7 @@ impl Site {
return Ok(());
}
self.taxonomies = find_taxonomies(&self.config, &self.library)?;
self.taxonomies = find_taxonomies(&self.config, &self.library.read().unwrap())?;
Ok(())
}
@ -495,7 +500,7 @@ impl Site {
create_directory(&current_path)?;
// Finally, create a index.html file there with the page rendered
let output = page.render_html(&self.tera, &self.config, &self.library)?;
let output = page.render_html(&self.tera, &self.config, &self.library.read().unwrap())?;
create_file(&current_path.join("index.html"), &self.inject_livereload(output))?;
// Copy any asset we found previously into the same directory as the index.html
@ -520,16 +525,17 @@ impl Site {
self.render_orphan_pages()?;
self.render_sitemap()?;
let library = self.library.read().unwrap();
if self.config.generate_rss {
let pages = if self.config.is_multilingual() {
self.library
library
.pages_values()
.iter()
.filter(|p| p.lang.is_none())
.map(|p| *p)
.collect()
} else {
self.library.pages_values()
library.pages_values()
};
self.render_rss_feed(pages, None)?;
}
@ -538,8 +544,7 @@ impl Site {
if !lang.rss {
continue;
}
let pages = self
.library
let pages = library
.pages_values()
.iter()
.filter(|p| if let Some(ref l) = p.lang { l == &lang.code } else { false })
@ -579,7 +584,7 @@ impl Site {
&self.output_path.join(&format!("search_index.{}.js", self.config.default_language)),
&format!(
"window.searchIndex = {};",
search::build_index(&self.config.default_language, &self.library)?
search::build_index(&self.config.default_language, &self.library.read().unwrap())?
),
)?;
@ -656,7 +661,7 @@ impl Site {
pub fn render_aliases(&self) -> Result<()> {
ensure_directory_exists(&self.output_path)?;
for (_, page) in self.library.pages() {
for (_, page) in self.library.read().unwrap().pages() {
for alias in &page.meta.aliases {
let mut output_path = self.output_path.to_path_buf();
let mut split = alias.split('/').collect::<Vec<_>>();
@ -730,10 +735,10 @@ impl Site {
} else {
self.output_path.join(&taxonomy.kind.name)
};
let list_output = taxonomy.render_all_terms(&self.tera, &self.config, &self.library)?;
let list_output = taxonomy.render_all_terms(&self.tera, &self.config, &self.library.read().unwrap())?;
create_directory(&output_path)?;
create_file(&output_path.join("index.html"), &self.inject_livereload(list_output))?;
let library = self.library.read().unwrap();
taxonomy
.items
.par_iter()
@ -742,18 +747,18 @@ impl Site {
if taxonomy.kind.is_paginated() {
self.render_paginated(
&path,
&Paginator::from_taxonomy(&taxonomy, item, &self.library),
&Paginator::from_taxonomy(&taxonomy, item, &library),
)?;
} else {
let single_output =
taxonomy.render_term(item, &self.tera, &self.config, &self.library)?;
taxonomy.render_term(item, &self.tera, &self.config, &library)?;
create_directory(&path)?;
create_file(&path.join("index.html"), &self.inject_livereload(single_output))?;
}
if taxonomy.kind.rss {
self.render_rss_feed(
item.pages.iter().map(|p| self.library.get_page_by_key(*p)).collect(),
item.pages.iter().map(|p| library.get_page_by_key(*p)).collect(),
Some(&PathBuf::from(format!("{}/{}", taxonomy.kind.name, item.slug))),
)
} else {
@ -771,6 +776,8 @@ impl Site {
let mut pages = self
.library
.read()
.unwrap()
.pages_values()
.iter()
.filter(|p| !p.is_draft())
@ -787,12 +794,13 @@ impl Site {
let mut sections = self
.library
.read().unwrap()
.sections_values()
.iter()
.map(|s| SitemapEntry::new(s.permalink.clone(), None))
.collect::<Vec<_>>();
for section in
self.library.sections_values().iter().filter(|s| s.meta.paginate_by.is_some())
self.library.read().unwrap().sections_values().iter().filter(|s| s.meta.paginate_by.is_some())
{
let number_pagers = (section.pages.len() as f64
/ section.meta.paginate_by.unwrap() as f64)
@ -872,12 +880,13 @@ impl Site {
pages.par_sort_unstable_by(sort_actual_pages_by_date);
context.insert("last_build_date", &pages[0].meta.date.clone());
let library = self.library.read().unwrap();
// limit to the last n elements if the limit is set; otherwise use all.
let num_entries = self.config.rss_limit.unwrap_or_else(|| pages.len());
let p = pages
.iter()
.take(num_entries)
.map(|x| x.to_serialized_basic(&self.library))
.map(|x| x.to_serialized_basic(&library))
.collect::<Vec<_>>();
context.insert("pages", &p);
@ -943,7 +952,7 @@ impl Site {
section
.pages
.par_iter()
.map(|k| self.render_page(self.library.get_page_by_key(*k)))
.map(|k| self.render_page(self.library.read().unwrap().get_page_by_key(*k)))
.collect::<Result<()>>()?;
}
@ -961,9 +970,9 @@ impl Site {
}
if section.meta.is_paginated() {
self.render_paginated(&output_path, &Paginator::from_section(&section, &self.library))?;
self.render_paginated(&output_path, &Paginator::from_section(&section, &self.library.read().unwrap()))?;
} else {
let output = section.render_html(&self.tera, &self.config, &self.library)?;
let output = section.render_html(&self.tera, &self.config, &self.library.read().unwrap())?;
create_file(&output_path.join("index.html"), &self.inject_livereload(output))?;
}
@ -975,6 +984,7 @@ impl Site {
self.render_section(
&self
.library
.read().unwrap()
.get_section(&self.content_path.join("_index.md"))
.expect("Failed to get index section"),
false,
@ -984,6 +994,7 @@ impl Site {
/// Renders all sections
pub fn render_sections(&self) -> Result<()> {
self.library
.read().unwrap()
.sections_values()
.into_par_iter()
.map(|s| self.render_section(s, true))
@ -993,8 +1004,8 @@ impl Site {
/// Renders all pages that do not belong to any sections
pub fn render_orphan_pages(&self) -> Result<()> {
ensure_directory_exists(&self.output_path)?;
for page in self.get_all_orphan_pages() {
let library = self.library.read().unwrap();
for page in library.get_all_orphan_pages() {
self.render_page(page)?;
}
@ -1015,7 +1026,7 @@ impl Site {
let page_path = folder_path.join(&format!("{}", pager.index));
create_directory(&page_path)?;
let output =
paginator.render_pager(pager, &self.config, &self.tera, &self.library)?;
paginator.render_pager(pager, &self.config, &self.tera, &self.library.read().unwrap())?;
if pager.index > 1 {
create_file(&page_path.join("index.html"), &self.inject_livereload(output))?;
} else {

View file

@ -16,59 +16,59 @@ fn can_parse_site() {
path.push("test_site");
let mut site = Site::new(&path, "config.toml").unwrap();
site.load().unwrap();
let library = site.library.read().unwrap();
// Correct number of pages (sections do not count as pages)
assert_eq!(site.library.pages().len(), 22);
assert_eq!(library.pages().len(), 22);
let posts_path = path.join("content").join("posts");
// Make sure the page with a url doesn't have any sections
let url_post = site.library.get_page(&posts_path.join("fixed-url.md")).unwrap();
let url_post = library.get_page(&posts_path.join("fixed-url.md")).unwrap();
assert_eq!(url_post.path, "a-fixed-url/");
// Make sure the article in a folder with only asset doesn't get counted as a section
let asset_folder_post =
site.library.get_page(&posts_path.join("with-assets").join("index.md")).unwrap();
library.get_page(&posts_path.join("with-assets").join("index.md")).unwrap();
assert_eq!(asset_folder_post.file.components, vec!["posts".to_string()]);
// That we have the right number of sections
assert_eq!(site.library.sections().len(), 11);
assert_eq!(library.sections().len(), 11);
// And that the sections are correct
let index_section = site.library.get_section(&path.join("content").join("_index.md")).unwrap();
let index_section = library.get_section(&path.join("content").join("_index.md")).unwrap();
assert_eq!(index_section.subsections.len(), 4);
assert_eq!(index_section.pages.len(), 1);
assert!(index_section.ancestors.is_empty());
let posts_section = site.library.get_section(&posts_path.join("_index.md")).unwrap();
let posts_section = library.get_section(&posts_path.join("_index.md")).unwrap();
assert_eq!(posts_section.subsections.len(), 2);
assert_eq!(posts_section.pages.len(), 10);
assert_eq!(
posts_section.ancestors,
vec![*site.library.get_section_key(&index_section.file.path).unwrap()]
vec![*library.get_section_key(&index_section.file.path).unwrap()]
);
// Make sure we remove all the pwd + content from the sections
let basic = site.library.get_page(&posts_path.join("simple.md")).unwrap();
let basic = library.get_page(&posts_path.join("simple.md")).unwrap();
assert_eq!(basic.file.components, vec!["posts".to_string()]);
assert_eq!(
basic.ancestors,
vec![
*site.library.get_section_key(&index_section.file.path).unwrap(),
*site.library.get_section_key(&posts_section.file.path).unwrap(),
*library.get_section_key(&index_section.file.path).unwrap(),
*library.get_section_key(&posts_section.file.path).unwrap(),
]
);
let tutorials_section =
site.library.get_section(&posts_path.join("tutorials").join("_index.md")).unwrap();
library.get_section(&posts_path.join("tutorials").join("_index.md")).unwrap();
assert_eq!(tutorials_section.subsections.len(), 2);
let sub1 = site.library.get_section_by_key(tutorials_section.subsections[0]);
let sub2 = site.library.get_section_by_key(tutorials_section.subsections[1]);
let sub1 = library.get_section_by_key(tutorials_section.subsections[0]);
let sub2 = library.get_section_by_key(tutorials_section.subsections[1]);
assert_eq!(sub1.clone().meta.title.unwrap(), "Programming");
assert_eq!(sub2.clone().meta.title.unwrap(), "DevOps");
assert_eq!(tutorials_section.pages.len(), 0);
let devops_section = site
.library
let devops_section = library
.get_section(&posts_path.join("tutorials").join("devops").join("_index.md"))
.unwrap();
assert_eq!(devops_section.subsections.len(), 0);
@ -76,14 +76,13 @@ fn can_parse_site() {
assert_eq!(
devops_section.ancestors,
vec![
*site.library.get_section_key(&index_section.file.path).unwrap(),
*site.library.get_section_key(&posts_section.file.path).unwrap(),
*site.library.get_section_key(&tutorials_section.file.path).unwrap(),
*library.get_section_key(&index_section.file.path).unwrap(),
*library.get_section_key(&posts_section.file.path).unwrap(),
*library.get_section_key(&tutorials_section.file.path).unwrap(),
]
);
let prog_section = site
.library
let prog_section = library
.get_section(&posts_path.join("tutorials").join("programming").join("_index.md"))
.unwrap();
assert_eq!(prog_section.subsections.len(), 0);
@ -234,15 +233,18 @@ fn can_build_site_with_live_reload() {
fn can_build_site_with_taxonomies() {
let (site, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
site.load().unwrap();
for (i, (_, page)) in site.library.pages_mut().iter_mut().enumerate() {
page.meta.taxonomies = {
let mut taxonomies = HashMap::new();
taxonomies.insert(
"categories".to_string(),
vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
);
taxonomies
};
{
let mut library = site.library.write().unwrap();
for (i, (_, page)) in library.pages_mut().iter_mut().enumerate() {
page.meta.taxonomies = {
let mut taxonomies = HashMap::new();
taxonomies.insert(
"categories".to_string(),
vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
);
taxonomies
};
}
}
site.populate_taxonomies().unwrap();
(site, false)
@ -311,12 +313,15 @@ fn can_build_site_and_insert_anchor_links() {
fn can_build_site_with_pagination_for_section() {
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
site.load().unwrap();
for (_, section) in site.library.sections_mut() {
if section.is_index() {
continue;
{
let mut library = site.library.write().unwrap();
for (_, section) in library.sections_mut() {
if section.is_index() {
continue;
}
section.meta.paginate_by = Some(2);
section.meta.template = Some("section_paginated.html".to_string());
}
section.meta.paginate_by = Some(2);
section.meta.template = Some("section_paginated.html".to_string());
}
(site, false)
});
@ -425,12 +430,14 @@ fn can_build_site_with_pagination_for_index() {
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
site.load().unwrap();
{
let index = site
.library
.get_section_mut(&site.base_path.join("content").join("_index.md"))
.unwrap();
index.meta.paginate_by = Some(2);
index.meta.template = Some("index_paginated.html".to_string());
let mut library = site.library.write().unwrap();
{
let index = library
.get_section_mut(&site.base_path.join("content").join("_index.md"))
.unwrap();
index.meta.paginate_by = Some(2);
index.meta.template = Some("index_paginated.html".to_string());
}
}
(site, false)
});
@ -482,16 +489,19 @@ fn can_build_site_with_pagination_for_taxonomy() {
lang: None,
});
site.load().unwrap();
{
let mut library = site.library.write().unwrap();
for (i, (_, page)) in site.library.pages_mut().iter_mut().enumerate() {
page.meta.taxonomies = {
let mut taxonomies = HashMap::new();
taxonomies.insert(
"tags".to_string(),
vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
);
taxonomies
};
for (i, (_, page)) in library.pages_mut().iter_mut().enumerate() {
page.meta.taxonomies = {
let mut taxonomies = HashMap::new();
taxonomies.insert(
"tags".to_string(),
vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
);
taxonomies
};
}
}
site.populate_taxonomies().unwrap();
(site, false)
@ -594,38 +604,38 @@ fn can_apply_page_templates() {
site.load().unwrap();
let template_path = path.join("content").join("applying_page_template");
let library = site.library.read().unwrap();
let template_section = site.library.get_section(&template_path.join("_index.md")).unwrap();
let template_section = library.get_section(&template_path.join("_index.md")).unwrap();
assert_eq!(template_section.subsections.len(), 2);
assert_eq!(template_section.pages.len(), 2);
let from_section_config = site.library.get_page_by_key(template_section.pages[0]);
let from_section_config = library.get_page_by_key(template_section.pages[0]);
assert_eq!(from_section_config.meta.template, Some("page_template.html".into()));
assert_eq!(from_section_config.meta.title, Some("From section config".into()));
let override_page_template = site.library.get_page_by_key(template_section.pages[1]);
let override_page_template = library.get_page_by_key(template_section.pages[1]);
assert_eq!(override_page_template.meta.template, Some("page_template_override.html".into()));
assert_eq!(override_page_template.meta.title, Some("Override".into()));
// It should have applied recursively as well
let another_section =
site.library.get_section(&template_path.join("another_section").join("_index.md")).unwrap();
library.get_section(&template_path.join("another_section").join("_index.md")).unwrap();
assert_eq!(another_section.subsections.len(), 0);
assert_eq!(another_section.pages.len(), 1);
let changed_recursively = site.library.get_page_by_key(another_section.pages[0]);
let changed_recursively = library.get_page_by_key(another_section.pages[0]);
assert_eq!(changed_recursively.meta.template, Some("page_template.html".into()));
assert_eq!(changed_recursively.meta.title, Some("Changed recursively".into()));
// But it should not have override a children page_template
let yet_another_section = site
.library
let yet_another_section = library
.get_section(&template_path.join("yet_another_section").join("_index.md"))
.unwrap();
assert_eq!(yet_another_section.subsections.len(), 0);
assert_eq!(yet_another_section.pages.len(), 1);
let child = site.library.get_page_by_key(yet_another_section.pages[0]);
let child = library.get_page_by_key(yet_another_section.pages[0]);
assert_eq!(child.meta.template, Some("page_template_child.html".into()));
assert_eq!(child.meta.title, Some("Local section override".into()));
}

View file

@ -13,44 +13,45 @@ fn can_parse_multilingual_site() {
let mut site = Site::new(&path, "config.toml").unwrap();
site.load().unwrap();
assert_eq!(site.library.pages().len(), 10);
assert_eq!(site.library.sections().len(), 6);
let library = site.library.read().unwrap();
assert_eq!(library.pages().len(), 10);
assert_eq!(library.sections().len(), 6);
// default index sections
let default_index_section =
site.library.get_section(&path.join("content").join("_index.md")).unwrap();
library.get_section(&path.join("content").join("_index.md")).unwrap();
assert_eq!(default_index_section.pages.len(), 1);
assert!(default_index_section.ancestors.is_empty());
let fr_index_section =
site.library.get_section(&path.join("content").join("_index.fr.md")).unwrap();
library.get_section(&path.join("content").join("_index.fr.md")).unwrap();
assert_eq!(fr_index_section.pages.len(), 1);
assert!(fr_index_section.ancestors.is_empty());
// blog sections get only their own language pages
let blog_path = path.join("content").join("blog");
let default_blog = site.library.get_section(&blog_path.join("_index.md")).unwrap();
let default_blog = library.get_section(&blog_path.join("_index.md")).unwrap();
assert_eq!(default_blog.subsections.len(), 0);
assert_eq!(default_blog.pages.len(), 4);
assert_eq!(
default_blog.ancestors,
vec![*site.library.get_section_key(&default_index_section.file.path).unwrap()]
vec![*library.get_section_key(&default_index_section.file.path).unwrap()]
);
for key in &default_blog.pages {
let page = site.library.get_page_by_key(*key);
let page = library.get_page_by_key(*key);
assert_eq!(page.lang, None);
}
let fr_blog = site.library.get_section(&blog_path.join("_index.fr.md")).unwrap();
let fr_blog = library.get_section(&blog_path.join("_index.fr.md")).unwrap();
assert_eq!(fr_blog.subsections.len(), 0);
assert_eq!(fr_blog.pages.len(), 3);
assert_eq!(
fr_blog.ancestors,
vec![*site.library.get_section_key(&fr_index_section.file.path).unwrap()]
vec![*library.get_section_key(&fr_index_section.file.path).unwrap()]
);
for key in &fr_blog.pages {
let page = site.library.get_page_by_key(*key);
let page = library.get_page_by_key(*key);
assert_eq!(page.lang, Some("fr".to_string()));
}
}

View file

@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::path::PathBuf;
use std::sync::{Arc, Mutex, RwLock};
use tera::{from_value, to_value, Function as TeraFn, Result, Value};
@ -190,18 +191,12 @@ impl TeraFn for GetTaxonomyUrl {
#[derive(Debug)]
pub struct GetPage {
pages: HashMap<String, Value>,
base_path: PathBuf,
library: Arc<RwLock<Library>>,
}
impl GetPage {
pub fn new(library: &Library) -> Self {
let mut pages = HashMap::new();
for page in library.pages_values() {
pages.insert(
page.file.relative.clone(),
to_value(library.get_page(&page.file.path).unwrap().to_serialized(library)).unwrap(),
);
}
Self {pages}
pub fn new(base_path: PathBuf, library: Arc<RwLock<Library>>) -> Self {
Self {base_path: base_path.join("content"), library}
}
}
impl TeraFn for GetPage {
@ -211,8 +206,12 @@ impl TeraFn for GetPage {
args.get("path"),
"`get_page` requires a `path` argument with a string value"
);
match self.pages.get(&path) {
Some(p) => Ok(p.clone()),
let full_path = self.base_path.join(&path);
let library = self.library.read().unwrap();
match library.get_page(&full_path) {
Some(p) => {
Ok(to_value(p.to_serialized(&library)).unwrap())
},
None => Err(format!("Page `{}` not found.", path).into()),
}
}
@ -220,27 +219,12 @@ impl TeraFn for GetPage {
#[derive(Debug)]
pub struct GetSection {
sections: HashMap<String, Value>,
sections_basic: HashMap<String, Value>,
base_path: PathBuf,
library: Arc<RwLock<Library>>,
}
impl GetSection {
pub fn new(library: &Library) -> Self {
let mut sections = HashMap::new();
let mut sections_basic = HashMap::new();
for section in library.sections_values() {
sections.insert(
section.file.relative.clone(),
to_value(library.get_section(&section.file.path).unwrap().to_serialized(library))
.unwrap(),
);
sections_basic.insert(
section.file.relative.clone(),
to_value(library.get_section(&section.file.path).unwrap().to_serialized_basic(library))
.unwrap(),
);
}
Self {sections, sections_basic}
pub fn new(base_path: PathBuf, library: Arc<RwLock<Library>>) -> Self {
Self {base_path: base_path.join("content"), library}
}
}
impl TeraFn for GetSection {
@ -255,10 +239,17 @@ impl TeraFn for GetSection {
.get("metadata_only")
.map_or(false, |c| from_value::<bool>(c.clone()).unwrap_or(false));
let container = if metadata_only { &self.sections_basic } else { &self.sections };
let full_path = self.base_path.join(&path);
let library = self.library.read().unwrap();
match container.get(&path) {
Some(p) => Ok(p.clone()),
match library.get_section(&full_path) {
Some(s) => {
if metadata_only {
Ok(to_value(s.to_serialized_basic(&library)).unwrap())
} else {
Ok(to_value(s.to_serialized(&library)).unwrap())
}
},
None => Err(format!("Section `{}` not found.", path).into()),
}
}
@ -267,16 +258,16 @@ impl TeraFn for GetSection {
#[derive(Debug)]
pub struct GetTaxonomy {
taxonomies: HashMap<String, Value>,
library: Arc<RwLock<Library>>,
taxonomies: HashMap<String, Taxonomy>,
}
impl GetTaxonomy {
pub fn new(all_taxonomies: &[Taxonomy], library: &Library) -> Self {
pub fn new(all_taxonomies: Vec<Taxonomy>, library: Arc<RwLock<Library>>) -> Self {
let mut taxonomies = HashMap::new();
for taxonomy in all_taxonomies {
taxonomies
.insert(taxonomy.kind.name.clone(), to_value(taxonomy.to_serialized(library)).unwrap());
for taxo in all_taxonomies {
taxonomies.insert(taxo.kind.name.clone(), taxo);
}
Self {taxonomies}
Self {taxonomies, library}
}
}
impl TeraFn for GetTaxonomy {
@ -286,18 +277,19 @@ impl TeraFn for GetTaxonomy {
args.get("kind"),
"`get_taxonomy` requires a `kind` argument with a string value"
);
let container = match self.taxonomies.get(&kind) {
Some(c) => c,
match self.taxonomies.get(&kind) {
Some(t) => {
Ok(to_value(t.to_serialized(&self.library.read().unwrap())).unwrap())
},
None => {
return Err(format!(
Err(format!(
"`get_taxonomy` received an unknown taxonomy as kind: {}",
kind
)
.into());
.into())
}
};
Ok(to_value(container).unwrap())
}
}
}
@ -306,6 +298,7 @@ mod tests {
use super::{GetTaxonomy, GetTaxonomyUrl, GetUrl, Trans};
use std::collections::HashMap;
use std::sync::{RwLock, Arc};
use tera::{to_value, Value, Function};
@ -355,12 +348,12 @@ mod tests {
#[test]
fn can_get_taxonomy() {
let taxo_config = TaxonomyConfig { name: "tags".to_string(), ..TaxonomyConfig::default() };
let library = Library::new(0, 0, false);
let tag = TaxonomyItem::new("Programming", &taxo_config, &Config::default(), vec![], &library);
let library = Arc::new(RwLock::new(Library::new(0, 0, false)));
let tag = TaxonomyItem::new("Programming", &taxo_config, &Config::default(), vec![], &library.read().unwrap());
let tags = Taxonomy { kind: taxo_config, items: vec![tag] };
let taxonomies = vec![tags.clone()];
let static_fn = GetTaxonomy::new(&taxonomies, &library);
let static_fn = GetTaxonomy::new(taxonomies.clone(), library.clone());
// can find it correctly
let mut args = HashMap::new();
args.insert("kind".to_string(), to_value("tags").unwrap());

View file

@ -47,23 +47,24 @@ fn colorize(message: &str, color: &ColorSpec) {
/// Display in the console the number of pages/sections in the site
pub fn notify_site_size(site: &Site) {
let library = site.library.read().unwrap();
println!(
"-> Creating {} pages ({} orphan), {} sections, and processing {} images",
site.library.pages().len(),
site.get_all_orphan_pages().len(),
site.library.sections().len() - 1, // -1 since we do not the index as a section
library.pages().len(),
site.get_number_orphan_pages(),
library.sections().len() - 1, // -1 since we do not the index as a section
site.num_img_ops(),
);
}
/// Display a warning in the console if there are ignored pages in the site
pub fn warn_about_ignored_pages(site: &Site) {
let ignored_pages: Vec<_> = site
.library
let library = site.library.read().unwrap();
let ignored_pages: Vec<_> = library
.sections_values()
.iter()
.flat_map(|s| {
s.ignored_pages.iter().map(|k| site.library.get_page_by_key(*k).file.path.clone())
s.ignored_pages.iter().map(|k| library.get_page_by_key(*k).file.path.clone())
})
.collect();