diff --git a/Cargo.lock b/Cargo.lock index 78e0b8c9..b076a63f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,17 +3,18 @@ name = "gutenberg" version = "0.1.0" dependencies = [ "clap 2.20.5 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syntect 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tera 0.7.2 (git+https://github.com/Keats/tera?branch=next)", - "toml 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syntect 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tera 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -39,8 +40,8 @@ dependencies = [ "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -50,7 +51,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -59,7 +60,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -74,11 +75,6 @@ name = "bitflags" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "bitflags" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "byteorder" version = "0.5.3" @@ -99,7 +95,7 @@ name = "chrono" version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -108,7 +104,7 @@ name = "chrono" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -119,7 +115,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "term_size 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -129,7 +125,7 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", @@ -151,7 +147,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "error-chain" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -162,7 +158,7 @@ name = "flate2" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -222,7 +218,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.20" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -235,7 +231,7 @@ name = "memchr" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -244,39 +240,39 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-integer" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-iter" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -286,7 +282,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "onig_sys 61.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -295,8 +291,8 @@ name = "onig_sys" version = "61.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "cmake 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -312,14 +308,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "plist" -version = "0.1.1" +version = "0.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", - "xml-rs 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -333,7 +329,7 @@ dependencies = [ [[package]] name = "quote" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -353,6 +349,11 @@ dependencies = [ "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "regex-syntax" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "regex-syntax" version = "0.4.0" @@ -360,7 +361,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rustc-demangle" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -377,6 +378,11 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "serde" version = "0.8.23" @@ -384,25 +390,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "0.9.8" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde_codegen_internals" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "syn 0.11.6 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "0.9.8" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "quote 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_codegen_internals 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.11.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_codegen_internals 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -412,8 +418,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -431,17 +437,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.11.6" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "quote 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "synom" -version = "0.11.0" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -449,35 +455,35 @@ dependencies = [ [[package]] name = "syntect" -version = "1.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bincode 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "onig 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "plist 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "plist 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", - "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tera" -version = "0.7.2" -source = "git+https://github.com/Keats/tera?branch=next#cd13a801b61e8c11ef829943bd3f34ae7d9d4bab" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "chrono 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "humansize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "pest 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", "slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -489,7 +495,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -499,7 +505,7 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -517,17 +523,17 @@ version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "toml" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -595,6 +601,15 @@ name = "void" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "walkdir" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "walkdir" version = "1.0.7" @@ -617,7 +632,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "xml-rs" -version = "0.3.8" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -636,17 +651,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bincode 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "55eb0b7fd108527b0c77860f75eca70214e11a8b4c6ef05148c54c05a25d48ad" "checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" -"checksum bitflags 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e1ab483fc81a8143faa7203c4a3c02888ebd1a782e37e41fa34753ba9a162" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" "checksum chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00" "checksum chrono 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "158b0bd7d75cbb6bf9c25967a48a2e9f77da95876b858eadfabaa99cd069de6e" "checksum clap 2.20.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7db281b0520e97fbd15cd615dcd8f8bcad0c26f5f7d5effe705f090f39e9a758" -"checksum cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "a3a6805df695087e7c1bcd9a82e03ad6fb864c8e67ac41b1348229ce5b7f0407" +"checksum cmake 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "e1acc68a3f714627af38f9f5d09706a28584ba60dfe2cca68f40bf779f941b25" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" "checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90" -"checksum error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e92ecf0a508c8e074c0e6fa8fe0fa38414848ad4dfc4db6f74c5e9753330b248" +"checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8" "checksum flate2 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "d4e4d0c15ef829cbc1b7cda651746be19cceeb238be7b1049227b14891df9e25" "checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344" "checksum gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)" = "c07c758b972368e703a562686adb39125707cc1ef3399da8c019fc6c2498a75d" @@ -657,43 +671,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b" -"checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5" +"checksum libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "88ee81885f9f04bff991e306fea7c1c60a5f0f9e409e99f6b40e3311a3363135" "checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1" "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" "checksum miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "28eaee17666671fa872e567547e8428e83308ebe5808cdf6a0e28397dbe2c726" -"checksum num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "bde7c03b09e7c6a301ee81f6ddf66d7a28ec305699e3d3b056d2fc56470e3120" -"checksum num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "fb24d9bfb3f222010df27995441ded1e954f8f69cd35021f6bef02ca9552fb92" -"checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c" -"checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c" +"checksum num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "98b15ba84e910ea7a1973bccd3df7b31ae282bf9d8bd2897779950c9b8303d40" +"checksum num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "21e4df1098d1d797d27ef0c69c178c3fab64941559b290fcae198e0825c9c8b5" +"checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e" +"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99" "checksum onig 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c5f586e53fa11ead18582956ea282c30baea1f25d3ee4c5fb85803f98727cb7" "checksum onig_sys 61.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a35f2cca300f0945538564da6052a449db55e65870cf0e9d443c1bce3d5dda47" "checksum pest 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e823a5967bb4cdc6d3e46f47baaf4ecfeae44413a642b74ad44e59e49c7f6" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" -"checksum plist 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c201fd99d98798fce524e3ea5dd91883c7def66d9ef6467ce014a05329de0799" +"checksum plist 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "29f7f7deddf1244a97e2771e47edb01e5b5603d133bd4a0e516ea0e6817adc64" "checksum pulldown-cmark 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1058d7bb927ca067656537eec4e02c2b4b70eaaa129664c5b90c111e20326f41" -"checksum quote 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "08de3f12e670f83f61e450443cbae34496a35b665691fd8e99b24ec662f75865" +"checksum quote 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7375cf7ad34a92e8fd18dd9c42f58b9a11def59ab48bec955bf359a788335592" "checksum redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd35cc9a8bdec562c757e3d43c1526b5c6d2653e23e2315065bc25556550753" "checksum regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4278c17d0f6d62dfef0ab00028feb45bd7d2102843f80763474eeb1be8a10c01" +"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" "checksum regex-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9191b1f57603095f105d317e375d19b1c9c5c3185ea9633a99a6dcbed04457" -"checksum rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1430d286cadb237c17c885e25447c982c97113926bb579f4379c0eca8d9586dc" +"checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" "checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b" "checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7" +"checksum serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0e0732aa8ec4267f61815a396a942ba3525062e3bd5520aa8419927cfc0a92" "checksum serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" -"checksum serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "204db0f2a5335be7313fd4453132fd56d2085aed081c673140a256772903e116" -"checksum serde_codegen_internals 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a5113d5bd16471b183803b374f0fe4877ad9658b95e33b11f4a004d73aacc74a" -"checksum serde_derive 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "e88ec062a02cbebfd6276044a305d665a9919b497aa6acb2e12c070d1a50d32d" +"checksum serde 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "a78def33a828eb05eb7f0167499f19cca368faf27601f6c43bc70316825d9adf" +"checksum serde_codegen_internals 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d52006899f910528a10631e5b727973fe668f3228109d1707ccf5bad5490b6e" +"checksum serde_derive 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "789ee9f3cd78c850948b94121020147f5220b47dafbf230d7098a93a58f726cf" "checksum serde_json 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6501ac6f8b74f9b1033f7ddf79a08edfa0f58d6f8e3190cb8dc97736afa257a8" "checksum slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f5ff4b43cb07b86c5f9236c92714a22cdf9e5a27a7d85e398e2c9403328cb8" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" -"checksum syn 0.11.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0e28da8d02d75d1e58b89258e0741128f0b0d8a8309fb5c627be0fbd37a76c67" -"checksum synom 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8fece1853fb872b0acdc3ff88f37c474018e125ef81cd4cb8c0ca515746b62ed" -"checksum syntect 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f79be04af68d5fa09e71b3274159a955a25f25a5cbfba9a6ff64139b71d848a" -"checksum tera 0.7.2 (git+https://github.com/Keats/tera?branch=next)" = "" +"checksum syn 0.11.8 (registry+https://github.com/rust-lang/crates.io-index)" = "37c279fb816210c9bb28b2c292664581e7b87b4561e86b94df462664d8620bb8" +"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" +"checksum syntect 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e9d678dfa7f7f9c90535caaa81778c971765942fcd57aceffc3acd34564fc0fd" +"checksum tera 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb775e4a7318e080e9c3000b150f720caf5825b66504f56f358df35b74fd0c14" "checksum term_size 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "07b6c1ac5b3fffd75073276bca1ceed01f67a28537097a2a9539e116e50fb21a" "checksum thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4437c97558c70d129e40629a5b385b3fb1ffac301e63941335e4d354081ec14a" "checksum thread_local 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c85048c6260d17cf486ceae3282d9fb6b90be220bf5b28c400f5485ffc29f0c7" "checksum time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "211b63c112206356ef1ff9b19355f43740fc3f85960c598a93d3a3d3ba7beade" -"checksum toml 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08272367dd2e766db3fa38f068067d17aa6a9dfd7259af24b3927db92f1e0c2f" +"checksum toml 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3474f3c6eaf32eedb4f4a66a26214f020f828a6d96c37e38a35e3a379bbcfd11" "checksum unicode-bidi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a078ebdd62c0e71a709c3d53d2af693fe09fe93fbff8344aebe289b78f9032" "checksum unicode-normalization 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e28fa37426fceeb5cf8f41ee273faa7c82c47dc8fba5853402841e665fcd86ff" "checksum unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18127285758f0e2c6cf325bb3f3d138a12fee27de4f23e146cd6a179f26c2cf3" @@ -705,8 +721,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cac5efe5cb0fa14ec2f84f83c701c562ee63f6dcc680861b21d65c682adfb05f" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +"checksum walkdir 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c66c0b9792f0a765345452775f3adbd28dde9d33f30d13e5dcc5ae17cf6f3780" "checksum walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bb08f9e670fab86099470b97cd2b252d6527f0b3cc1401acdb595ffc9dd288ff" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum xml-rs 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "729264a98260c6469f7a7d7162baaf5869da5573f69ee08ccf3f3d9110cafe3b" +"checksum xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7ec6c39eaa68382c8e31e35239402c0a9489d4141a8ceb0c716099a0b515b562" "checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" diff --git a/Cargo.toml b/Cargo.toml index 8963a220..f8f1fdb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/Keats/gutenberg" keywords = ["static", "site", "generator", "blog"] [dependencies] -error-chain = "0.9" +error-chain = "0.10" clap = "2.19" walkdir = "1" pulldown-cmark = "0" @@ -20,7 +20,9 @@ glob = "0.2" serde = "0.9" serde_json = "0.9" serde_derive = "0.9" -tera = { git = "https://github.com/Keats/tera", branch = "next" } +# tera = { git = "https://github.com/Keats/tera", branch = "next" } +tera = "0.8" +slug = "0.1" syntect = "1" [dependencies.toml] diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 85e6aadc..f5fc79fe 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -1,87 +1,7 @@ -use std::collections::HashMap; -use std::fs::{create_dir, remove_dir_all}; -use std::path::Path; - -use glob::glob; -use tera::{Tera, Context}; - -use config:: Config; -use errors::{Result, ResultExt}; -use page::{Page, order_pages}; -use utils::create_file; +use errors::Result; +use site::Site; - -pub fn build(config: Config) -> Result<()> { - if Path::new("public").exists() { - // Delete current `public` directory so we can start fresh - remove_dir_all("public").chain_err(|| "Couldn't delete `public` directory")?; - } - - let tera = Tera::new("templates/**/*").chain_err(|| "Error parsing templates")?; - - // ok we got all the pages HTML, time to write them down to disk - create_dir("public")?; - let public = Path::new("public"); - let mut pages: Vec = vec![]; - let mut sections: HashMap> = HashMap::new(); - - // First step: do all the articles and group article by sections - // hardcoded pattern so can't error - for entry in glob("content/**/*.md").unwrap().filter_map(|e| e.ok()) { - let path = entry.as_path(); - let mut page = Page::from_file(&path)?; - - let mut current_path = public.to_path_buf(); - - for section in &page.sections { - current_path.push(section); - - if !current_path.exists() { - create_dir(¤t_path)?; - } - - let str_path = current_path.as_path().to_string_lossy().to_string(); - sections.entry(str_path).or_insert_with(|| vec![page.clone()]); - } - - if let Some(ref url) = page.meta.url { - println!("URL: {:?}", url); - current_path.push(url); - } else { - println!("REMOVE ME IF YOU DONT SEE ME"); - current_path.push(&page.get_slug()); - } - - create_dir(¤t_path)?; - create_file(current_path.join("index.html"), &page.render_html(&tera, &config)?)?; - pages.push(page); - } - - for (section, pages) in sections { - render_section_index(section, pages, &tera, &config)?; - } - - // and now the index page - let mut context = Context::new(); - context.add("pages", &order_pages(pages)); - context.add("config", &config); - create_file(public.join("index.html"), &tera.render("index.html", &context)?)?; - - Ok(()) -} - - -fn render_section_index(section: String, pages: Vec, tera: &Tera, config: &Config) -> Result<()> { - let path = Path::new(§ion); - let mut context = Context::new(); - context.add("pages", &order_pages(pages)); - context.add("config", &config); - - let section_name = match path.components().into_iter().last() { - Some(s) => s.as_ref().to_string_lossy().to_string(), - None => bail!("Couldn't find a section name in {:?}", path.display()) - }; - - create_file(path.join("index.html"), &tera.render(&format!("{}.html", section_name), &context)?) +pub fn build() -> Result<()> { + Site::new()?.build() } diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 1af65e3f..e3c62b5e 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -1,5 +1,7 @@ mod init; mod build; +mod serve; pub use self::init::create_new_project; pub use self::build::build; +pub use self::serve::serve; diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs new file mode 100644 index 00000000..d19eec1f --- /dev/null +++ b/src/cmd/serve.rs @@ -0,0 +1,5 @@ +use errors::{Result, ResultExt}; + +pub fn serve(interface: &str, port: &str) -> Result<()> { + Ok(()) +} diff --git a/src/config.rs b/src/config.rs index 96696dbd..3808da7f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,11 +14,13 @@ pub struct Config { pub title: String, /// Base URL of the site pub base_url: String, + /// Whether to highlight all code found in markdown files. Defaults to true + pub highlight_code: Option, /// Description of the site pub description: Option, /// The language used in the site. Defaults to "en" pub language_code: Option, - /// Whether to disable RSS generation, defaults to None (== generate RSS) + /// Whether to disable RSS generation, defaults to false (== generate RSS) pub disable_rss: Option, /// All user params set in [extra] in the config pub extra: Option>, @@ -32,10 +34,19 @@ impl Config { Ok(c) => c, Err(e) => bail!(e) }; + if config.language_code.is_none() { config.language_code = Some("en".to_string()); } + if config.highlight_code.is_none() { + config.highlight_code = Some(true); + } + + if config.disable_rss.is_none() { + config.disable_rss = Some(false); + } + Ok(config) } @@ -51,6 +62,20 @@ impl Config { } +/// Get and parse the config. +/// If it doesn't succeed, exit +pub fn get_config() -> Config { + match Config::from_file("config.toml") { + Ok(c) => c, + Err(e) => { + println!("Failed to load config.toml"); + println!("Error: {}", e); + ::std::process::exit(1); + } + } +} + + #[cfg(test)] mod tests { use super::{Config}; diff --git a/src/front_matter.rs b/src/front_matter.rs index 384d19c9..e83f4c73 100644 --- a/src/front_matter.rs +++ b/src/front_matter.rs @@ -11,11 +11,15 @@ use errors::{Result}; /// The front matter of every page #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FrontMatter { - // of the page + // Mandatory fields + + /// <title> of the page pub title: String, /// Description that appears when linked, e.g. on twitter pub description: String, + // Optional stuff + /// Date if we want to order pages (ie blog post) pub date: Option<String>, /// The page slug. Will be used instead of the filename if present @@ -44,7 +48,7 @@ impl FrontMatter { bail!("Front matter of file is missing"); } - let mut f: FrontMatter = match toml::from_str(toml) { + let f: FrontMatter = match toml::from_str(toml) { Ok(d) => d, Err(e) => bail!(e), }; diff --git a/src/main.rs b/src/main.rs index b71b4c80..4a52e6ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,34 +14,18 @@ extern crate regex; extern crate tera; extern crate glob; extern crate syntect; +extern crate slug; +use std::time::Instant; + mod utils; mod config; mod errors; mod cmd; mod page; mod front_matter; - - -use config::Config; - - -// Get and parse the config. -// If it doesn't succeed, exit -fn get_config() -> Config { - match Config::from_file("config.toml") { - Ok(c) => c, - Err(e) => { - println!("Failed to load config.toml"); - println!("Error: {}", e); - for e in e.iter().skip(1) { - println!("Reason: {}", e) - } - ::std::process::exit(1); - } - } -} +mod site; fn main() { @@ -57,6 +41,11 @@ fn main() { (@subcommand build => (about: "Builds the site") ) + (@subcommand serve => + (about: "Serve the site. Rebuild and reload on change automatically") + (@arg interface: "Interface to bind on (default to 127.0.0.1)") + (@arg port: "Which port to use (default to 1111)") + ) ).get_matches(); match matches.subcommand() { @@ -64,7 +53,6 @@ fn main() { match cmd::create_new_project(matches.value_of("name").unwrap()) { Ok(()) => { println!("Project created"); - println!("You will now need to set a theme in `config.toml`"); }, Err(e) => { println!("Error: {}", e); @@ -73,9 +61,11 @@ fn main() { }; }, ("build", Some(_)) => { - match cmd::build(get_config()) { + let start = Instant::now(); + match cmd::build() { Ok(()) => { - println!("Project built."); + let duration = start.elapsed(); + println!("Site built in {}s.", duration.as_secs()); }, Err(e) => { println!("Failed to build the site"); @@ -87,6 +77,20 @@ fn main() { }, }; }, + ("serve", Some(matches)) => { + let interface = matches.value_of("interface").unwrap_or("127.0.0.1"); + let port = matches.value_of("port").unwrap_or("1111"); + match cmd::serve(interface, port) { + Ok(()) => { + println!("Project created"); + println!("You will now need to set a theme in `config.toml`"); + }, + Err(e) => { + println!("Error: {}", e); + ::std::process::exit(1); + }, + }; + }, _ => unreachable!(), } } diff --git a/src/page.rs b/src/page.rs index 0efb2695..b763ec06 100644 --- a/src/page.rs +++ b/src/page.rs @@ -9,6 +9,7 @@ use pulldown_cmark as cmark; use regex::Regex; use tera::{Tera, Context}; use serde::ser::{SerializeStruct, self}; +use slug::slugify; use errors::{Result, ResultExt}; use config::Config; @@ -67,10 +68,22 @@ impl Page { if let Some(ref slug) = self.meta.slug { slug.to_string() } else { - self.filename.clone() + slugify(self.filename.clone()) } } + pub fn get_url(&self) -> String { + if let Some(ref u) = self.meta.url { + return u.to_string(); + } + + if !self.sections.is_empty() { + return format!("/{}/{}", self.sections.join("/"), self.get_slug()); + } + + format!("/{}", self.get_slug()) + } + // Parse a page given the content of the .md file // Files without front matter or with invalid front matter are considered // erroneous @@ -110,14 +123,6 @@ impl Page { for section in path.parent().unwrap().components() { page.sections.push(section.as_ref().to_string_lossy().to_string()); } - - // now the url - // We get it from a combination of sections + slug - if !page.sections.is_empty() { - page.meta.url = Some(format!("/{}/{}", page.sections.join("/"), page.get_slug())); - } else { - page.meta.url = Some(format!("/{}", page.get_slug())); - }; } Ok(page) @@ -143,7 +148,7 @@ impl Page { } } - pub fn render_html(&mut self, tera: &Tera, config: &Config) -> Result<String> { + pub fn render_html(&self, tera: &Tera, config: &Config) -> Result<String> { let tpl = self.get_layout_name(); let mut context = Context::new(); context.add("site", config); @@ -161,8 +166,8 @@ impl ser::Serialize for Page { state.serialize_field("title", &self.meta.title)?; state.serialize_field("description", &self.meta.description)?; state.serialize_field("date", &self.meta.date)?; - state.serialize_field("slug", &self.meta.slug)?; - state.serialize_field("url", &self.meta.url)?; + state.serialize_field("slug", &self.get_slug())?; + state.serialize_field("url", &self.get_url())?; state.serialize_field("tags", &self.meta.tags)?; state.serialize_field("draft", &self.meta.draft)?; state.serialize_field("category", &self.meta.category)?; @@ -244,7 +249,7 @@ Hello world"#; let res = Page::parse("posts/intro/start.md", content); assert!(res.is_ok()); let page = res.unwrap(); - assert_eq!(page.meta.url.unwrap(), "/posts/intro/hello-world"); + assert_eq!(page.get_url(), "/posts/intro/hello-world"); } #[test] @@ -259,7 +264,7 @@ Hello world"#; let res = Page::parse("start.md", content); assert!(res.is_ok()); let page = res.unwrap(); - assert_eq!(page.meta.url.unwrap(), "/hello-world"); + assert_eq!(page.get_url(), "/hello-world"); } #[test] @@ -273,4 +278,18 @@ Hello world"#; let res = Page::parse("start.md", content); assert!(res.is_err()); } + + #[test] + fn test_can_make_slug_from_non_slug_filename() { + let content = r#" ++++ +title = "Hello" +description = "hey there" ++++ +Hello world"#; + let res = Page::parse("file with space.md", content); + assert!(res.is_ok()); + let page = res.unwrap(); + assert_eq!(page.get_slug(), "file-with-space"); + } } diff --git a/src/site.rs b/src/site.rs new file mode 100644 index 00000000..fe0d229b --- /dev/null +++ b/src/site.rs @@ -0,0 +1,107 @@ +use std::collections::HashMap; +use std::fs::{create_dir, remove_dir_all}; +use std::path::Path; + +use glob::glob; +use tera::{Tera, Context}; + +use errors::{Result, ResultExt}; +use config::{Config, get_config}; +use page::Page; +use utils::create_file; + + +#[derive(Debug)] +pub struct Site { + config: Config, + pages: HashMap<String, Page>, + sections: HashMap<String, Vec<String>>, + templates: Tera, +} + +impl Site { + pub fn new() -> Result<Site> { + let tera = Tera::new("templates/**/*").chain_err(|| "Error parsing templates")?; + let mut site = Site { + config: get_config(), + pages: HashMap::new(), + sections: HashMap::new(), + templates: tera, + }; + site.parse_site()?; + + Ok(site) + } + + /// Reads all .md files in the `content` directory and create pages + /// out of them + fn parse_site(&mut self) -> Result<()> { + // First step: do all the articles and group article by sections + // hardcoded pattern so can't error + for entry in glob("content/**/*.md").unwrap().filter_map(|e| e.ok()) { + let page = Page::from_file(&entry.as_path())?; + + for section in &page.sections { + self.sections.entry(section.clone()).or_insert(vec![]).push(page.get_slug()); + } + + self.pages.insert(page.get_slug(), page); + } + + Ok(()) + } + + /// Builds the site to the `public` directory after deleting it + pub fn build(&self) -> Result<()> { + if Path::new("public").exists() { + // Delete current `public` directory so we can start fresh + remove_dir_all("public").chain_err(|| "Couldn't delete `public` directory")?; + } + + // Start from scratch + create_dir("public")?; + let public = Path::new("public"); + + let mut pages = vec![]; + // First we render the pages themselves + for page in self.pages.values() { + // Copy the nesting of the content directory if we have sections for that page + let mut current_path = public.to_path_buf(); + + // This loop happens when the page doesn't have a set URL + for section in &page.sections { + current_path.push(section); + + if !current_path.exists() { + create_dir(¤t_path)?; + } + } + + // if we have a url already set, use that as base + if let Some(ref url) = page.meta.url { + current_path.push(url); + } + + // Make sure the folder exists + create_dir(¤t_path)?; + // Finally, create a index.html file there with the page rendered + let output = page.render_html(&self.templates, &self.config)?; + create_file(current_path.join("index.html"), &output)?; + pages.push(page); + } + + // Then the section pages + // The folders have already been created in the page loop so no need to `create_dir` here +// for (section, slugs) in &self.sections { +// // TODO +// } + + // And finally the index page + let mut context = Context::new(); + context.add("pages", &pages); + context.add("config", &self.config); + create_file(public.join("index.html"), &self.templates.render("index.html", &context)?)?; + + Ok(()) + } +}