Serve articles with a random theme

This commit is contained in:
Magnus Hoff 2018-06-16 11:24:34 +02:00
parent 4516534b39
commit 7e6fe36ea0
15 changed files with 122 additions and 67 deletions

29
Cargo.lock generated
View file

@ -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"

View file

@ -1,71 +1,9 @@
[package]
authors = ["Magnus Hoff <maghoff@gmail.com>"]
description = "A wiki engine"
license = "GPL-3.0"
name = "sausagewiki"
version = "0.1.0-dev"
description = "A wiki engine"
authors = ["Magnus Hoff <maghoff@gmail.com>"]
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]

View file

@ -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;

View file

@ -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
},

View file

@ -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(

View file

@ -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: &timestamp_and_author(

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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()

View file

@ -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,
},

View file

@ -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)

View file

@ -8,7 +8,7 @@
<link href="_assets/style-{{style_css_checksum()}}.css" rel="stylesheet">
<meta name="generator" content="{{project_name()}} {{version()}}" />
</head>
<body class="theme-purple">
<body class="theme-{{theme}}">
{{>search_input.html}}
{{{body}}}
</body>

View file

@ -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) + "]")