diff --git a/Cargo.lock b/Cargo.lock index 6cca68c..dbdb77a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -146,6 +146,14 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "codegen" version = "0.1.0" @@ -699,6 +707,23 @@ dependencies = [ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand" +version = "0.5.1" +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)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "redox_syscall" version = "0.1.40" @@ -781,6 +806,7 @@ dependencies = [ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1328,6 +1354,7 @@ dependencies = [ "checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" "checksum chrono 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a81892f0d5a53f46fc05ef0b917305a81c13f1f13bb59ac91ff595817f0764b1" "checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536" +"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum crossbeam-deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fe8153ef04a7594ded05b427ffad46ddeaf22e63fd48d42b3e1e3bb4db07cae7" "checksum crossbeam-epoch 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2af0e75710d6181e234c8ecc79f14a97907850a541b13b0be1dd10992f2e4620" "checksum crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d636a8b3bcc1b409d7ffd3facef8f21dcb4009626adbd0c5e6c4305c07253c7b" @@ -1395,6 +1422,8 @@ dependencies = [ "checksum r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9c29bad92da76d02bc2c020452ebc3a3fe6fa74cfab91e711c43116e4fb1a3" "checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" +"checksum rand 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "482c45f965103f2433002a0c4d908599f38d1b8c1375e66e801a24c1c6cadc03" +"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" diff --git a/Cargo.toml b/Cargo.toml index 26c1ae7..78b2ab7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,71 +1,9 @@ [package] +authors = ["Magnus Hoff "] +description = "A wiki engine" +license = "GPL-3.0" name = "sausagewiki" version = "0.1.0-dev" -description = "A wiki engine" -authors = ["Magnus Hoff "] -license = "GPL-3.0" - -[profile.release] -panic = "abort" - -[dev-dependencies] -indoc = "0.2" -matches = "0.1" - -[dependencies] -bart = "0.1.4" -bart_derive = "0.1.4" -chrono = "0.4" -clap = "2.31" -diff = "0.1" -futures = "0.1" -futures-cpupool = "0.1" -hyper = "0.11" -lazy_static = "0.2" -maplit = "1" -percent-encoding = "1.0" -r2d2 = "0.8" -r2d2-diesel = "1.0.0" -regex = "0.2" -serde = "1.0.0" -serde_derive = "1.0.0" -serde_json = "1.0" -serde_urlencoded = "0.5" -slug = "0.1" -titlecase = "0.10" -tokio-io = "0.1" -tokio-proto = "0.1" -tokio-service = "0.1" - -[dependencies.libsqlite3-sys] -features = ["bundled"] -version = "0.9.1" - -[dependencies.diesel] -default-features = false -features = ["sqlite", "chrono"] -version = "1.3.0" - -[dependencies.diesel_migrations] -default-features = false -features = ["sqlite"] -version = "1.3.0" - -[dependencies.diesel_infer_schema] -default-features = false -features = ["sqlite"] -version = "1.3.0" - -[dependencies.num] -default-features = false -version = "0.1" - -[dependencies.pulldown-cmark] -git = "https://github.com/maghoff/pulldown-cmark.git" -default-features = false - -[dependencies.codegen] -path = "libs/codegen" [build-dependencies] quote = "0.3.10" @@ -81,4 +19,69 @@ default-features = false features = ["sqlite"] version = "1.3.0" +[dependencies] +bart = "0.1.4" +bart_derive = "0.1.4" +chrono = "0.4" +clap = "2.31" +diff = "0.1" +futures = "0.1" +futures-cpupool = "0.1" +hyper = "0.11" +lazy_static = "0.2" +maplit = "1" +percent-encoding = "1.0" +r2d2 = "0.8" +r2d2-diesel = "1.0.0" +rand = "0.5.1" +regex = "0.2" +serde = "1.0.0" +serde_derive = "1.0.0" +serde_json = "1.0" +serde_urlencoded = "0.5" +slug = "0.1" +titlecase = "0.10" +tokio-io = "0.1" +tokio-proto = "0.1" +tokio-service = "0.1" + +[dependencies.codegen] +path = "libs/codegen" + +[dependencies.diesel] +default-features = false +features = ["sqlite", "chrono"] +version = "1.3.0" + +[dependencies.diesel_infer_schema] +default-features = false +features = ["sqlite"] +version = "1.3.0" + +[dependencies.diesel_migrations] +default-features = false +features = ["sqlite"] +version = "1.3.0" + +[dependencies.libsqlite3-sys] +features = ["bundled"] +version = "0.9.1" + +[dependencies.num] +default-features = false +version = "0.1" + +[dependencies.pulldown-cmark] +default-features = false +git = "https://github.com/maghoff/pulldown-cmark.git" + +[dev-dependencies] +indoc = "0.2" +matches = "0.1" + +[profile] + +[profile.release] +panic = "abort" + [workspace] diff --git a/src/lib.rs b/src/lib.rs index f26a32a..26ad87d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ extern crate futures_cpupool; extern crate futures; extern crate percent_encoding; extern crate pulldown_cmark; +extern crate rand; extern crate r2d2_diesel; extern crate r2d2; extern crate serde_json; diff --git a/src/resources/about_resource.rs b/src/resources/about_resource.rs index b6e8975..6aeb0bb 100644 --- a/src/resources/about_resource.rs +++ b/src/resources/about_resource.rs @@ -85,6 +85,7 @@ impl Resource for AboutResource { .with_body(Layout { base: None, // Hmm, should perhaps accept `base` as argument title: "About Sausagewiki", + theme: "blue-gray", body: &Template { deps: &*LICENSE_INFOS }, diff --git a/src/resources/article_resource.rs b/src/resources/article_resource.rs index 5d5b4b4..bdbdb61 100644 --- a/src/resources/article_resource.rs +++ b/src/resources/article_resource.rs @@ -96,12 +96,18 @@ impl Resource for ArticleResource { .map(|x| x.expect("Data model guarantees that this exists")); let head = self.head(); + use rand::{thread_rng, Rng}; + + const themes: [&str; 19] = ["red", "pink", "purple", "deep-purple", "indigo", "blue", "light-blue", "cyan", "teal", "green", "light-green", "lime", "yellow", "amber", "orange", "deep-orange", "brown", "gray", "blue-gray"]; + let theme = thread_rng().choose(&themes).unwrap(); + Box::new(data.join(head) .and_then(move |(data, head)| { Ok(head .with_body(Layout { base: None, // Hmm, should perhaps accept `base` as argument title: &data.title, + theme, body: &Template { revision: data.revision, last_updated: Some(&last_updated( @@ -238,6 +244,7 @@ impl Resource for ArticleResource { .with_body(Layout { base: None, title: &title, + theme: "blue-gray", body: &Template { revision: base_article.revision, last_updated: Some(&last_updated( diff --git a/src/resources/article_revision_resource.rs b/src/resources/article_revision_resource.rs index 862cbac..258370c 100644 --- a/src/resources/article_revision_resource.rs +++ b/src/resources/article_revision_resource.rs @@ -95,6 +95,7 @@ impl Resource for ArticleRevisionResource { .with_body(Layout { base: Some("../../"), // Hmm, should perhaps accept `base` as argument title: &data.title, + theme: "blue-gray", body: &Template { link_current: &format!("_by_id/{}", data.article_id), timestamp_and_author: ×tamp_and_author( diff --git a/src/resources/changes_resource.rs b/src/resources/changes_resource.rs index cfd8f94..e80a7e3 100644 --- a/src/resources/changes_resource.rs +++ b/src/resources/changes_resource.rs @@ -356,6 +356,7 @@ impl Resource for ChangesResource { .with_body(Layout { base: None, // Hmm, should perhaps accept `base` as argument title: "Changes", + theme: "blue-gray", body: &Template { resource: &self, show_authors: self.show_authors, diff --git a/src/resources/diff_resource.rs b/src/resources/diff_resource.rs index 2a0bdb6..186a494 100644 --- a/src/resources/diff_resource.rs +++ b/src/resources/diff_resource.rs @@ -122,6 +122,7 @@ impl Resource for DiffResource { .with_body(Layout { base: Some("../"), // Hmm, should perhaps accept `base` as argument title: "Difference", + theme: "blue-gray", body: &Template { consecutive: self.to.revision - self.from.revision == 1, article_id: self.from.article_id as u32, diff --git a/src/resources/html_resource.rs b/src/resources/html_resource.rs index c07efef..5920b31 100644 --- a/src/resources/html_resource.rs +++ b/src/resources/html_resource.rs @@ -48,6 +48,7 @@ impl Resource for HtmlResource { .with_body(Layout { base: self.base, title: self.title, + theme: "blue-gray", body: &Template { title: self.title, html_body: self.html_body, diff --git a/src/resources/new_article_resource.rs b/src/resources/new_article_resource.rs index cceceab..c122996 100644 --- a/src/resources/new_article_resource.rs +++ b/src/resources/new_article_resource.rs @@ -83,6 +83,7 @@ impl Resource for NewArticleResource { .with_body(Layout { base: None, // Hmm, should perhaps accept `base` as argument title: &title, + theme: "blue-gray", body: &Template { revision: NEW, last_updated: None, diff --git a/src/resources/search_resource.rs b/src/resources/search_resource.rs index 32bdcc7..15267ca 100644 --- a/src/resources/search_resource.rs +++ b/src/resources/search_resource.rs @@ -202,6 +202,7 @@ impl Resource for SearchResource { .with_body(Layout { base: None, // Hmm, should perhaps accept `base` as argument title: "Search", + theme: "blue-gray", body: &Template { query: self.query.as_ref().map(|x| &**x).unwrap_or(""), hits: &data.iter() diff --git a/src/resources/sitemap_resource.rs b/src/resources/sitemap_resource.rs index 48cdffc..d03d994 100644 --- a/src/resources/sitemap_resource.rs +++ b/src/resources/sitemap_resource.rs @@ -48,6 +48,7 @@ impl Resource for SitemapResource { .with_body(Layout { base: None, // Hmm, should perhaps accept `base` as argument title: "Sitemap", + theme: "blue-gray", body: &Template { articles: &articles, }, diff --git a/src/site.rs b/src/site.rs index c1517e4..5198452 100644 --- a/src/site.rs +++ b/src/site.rs @@ -27,6 +27,7 @@ header! { (XIdentity, "X-Identity") => [String] } pub struct Layout<'a, T: 'a + fmt::Display> { pub base: Option<&'a str>, pub title: &'a str, + pub theme: &'a str, pub body: &'a T, } @@ -62,6 +63,7 @@ impl Site { .with_body(Layout { base: base, title: "Not found", + theme: "blue-gray", body: &NotFound, }.to_string()) .with_status(hyper::StatusCode::NotFound) @@ -75,6 +77,7 @@ impl Site { .with_body(Layout { base, title: "Internal server error", + theme: "blue-gray", body: &InternalServerError, }.to_string()) .with_status(hyper::StatusCode::InternalServerError) diff --git a/templates/layout.html b/templates/layout.html index d3d8d3a..e098846 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -8,7 +8,7 @@ - + {{>search_input.html}} {{{body}}} diff --git a/themes/generate.py b/themes/generate.py index 1e7ca25..ed77ba0 100644 --- a/themes/generate.py +++ b/themes/generate.py @@ -23,6 +23,8 @@ def prep(x): "text": "white" if dark_main else "black", } +themes = [prep(palette) for palette in palettes] + print( "\n".join( "\ @@ -32,6 +34,8 @@ print( --theme-input: {input};\n\ --theme-link: #01579b;\n\ }}\n".format(**x) - for x in (prep(palette) for palette in palettes) + for x in themes ) ) + +print("[" + ', '.join('"'+x['name']+'"' for x in themes) + "]")