summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2020-06-04 00:01:12 -0400
committerOwen Jacobson <owen@grimoire.ca>2020-06-04 00:02:58 -0400
commit778bfdc57102816b1234d13ed022447a983942ee (patch)
treec5ef8105c96bfafeeff36ab660a412f6ebdff4dc
parent21de322d6cf221867ec9600e1a31777a195c7597 (diff)
Markdown support.
This accomplishes two things: 1. The og cards and page title no longer contain half-baked markup. Instead, they show the markdown equivalent, which is generally pretty friendly. In other words, the page title is "Have you checked `resolv.conf`?" and not "Have you checked <code>resolve.conf</code>?" 2. Phrases can now start with terms other than "Have you checked".
-rw-r--r--Cargo.lock43
-rw-r--r--Cargo.toml1
-rw-r--r--src/things-to-check.yml68
-rw-r--r--src/view.rs50
4 files changed, 118 insertions, 44 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 83cfe5e..c2a4945 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -655,6 +655,15 @@ dependencies = [
]
[[package]]
+name = "getopts"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
+dependencies = [
+ "unicode-width",
+]
+
+[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1087,6 +1096,18 @@ dependencies = [
]
[[package]]
+name = "pulldown-cmark"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3e142c3b8f49d2200605ee6ba0b1d757310e9e7a72afe78c36ee2ef67300ee00"
+dependencies = [
+ "bitflags",
+ "getopts",
+ "memchr",
+ "unicase",
+]
+
+[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1343,6 +1364,7 @@ dependencies = [
"actix-web",
"lazy_static",
"maud",
+ "pulldown-cmark",
"quickcheck",
"quickcheck_macros",
"rand",
@@ -1489,6 +1511,15 @@ dependencies = [
]
[[package]]
+name = "unicase"
+version = "2.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
+dependencies = [
+ "version_check",
+]
+
+[[package]]
name = "unicode-bidi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1513,6 +1544,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
[[package]]
+name = "unicode-width"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
+
+[[package]]
name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1530,6 +1567,12 @@ dependencies = [
]
[[package]]
+name = "version_check"
+version = "0.9.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
+
+[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 1002fa2..41870a6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,6 +8,7 @@ edition = "2018"
[dependencies]
actix-rt = "~1.0"
actix-web = "~2.0"
+pulldown-cmark = "~0.7"
rand = "~0.7"
serde = "~1.0"
serde_urlencoded = "~0.6"
diff --git a/src/things-to-check.yml b/src/things-to-check.yml
index 6147971..a352535 100644
--- a/src/things-to-check.yml
+++ b/src/things-to-check.yml
@@ -3,37 +3,37 @@
# permalink.
#
# Yes, this is HTML and no, I don't care about injection.
-- permissions
-- cabling
-- for a full disk
-- the cache
-- for a version conflict
-- for a duplex mismatch
-- the firewall rules
-- <code>resolv.conf</code>
-- <code>/etc/hosts</code>
-- DNS
-- <code>CR/LF</code>
-- setuid/setgid bits
-- the default gateway
-- for IP conflicts
-- the logs
-- the port number
-- for a zonefile dot
-- I/O dammit
-- the mounts
-- the power
-- for the wrong whitespace
-- if it reloaded into bad config
-- IP forwarding
-- the trailing slash
-- the MAC address
-- if the filesystem is out of inodes
-- the line length
-- if you're on the wrong wifi network
-- if the vpn timed out
-- if that's the wrong host
-- the security groups
-- the fucking binlogs
-- the documentation
-- the manpages
+- Have you checked permissions?
+- Have you checked cabling?
+- Have you checked for a full disk?
+- Have you checked the cache?
+- Have you checked for a version conflict?
+- Have you checked for a duplex mismatch?
+- Have you checked the firewall rules?
+- Have you checked `resolv.conf`?
+- Have you checked `/etc/hosts`?
+- Have you checked DNS?
+- Have you checked `CR/LF`?
+- Have you checked setuid/setgid bits?
+- Have you checked the default gateway?
+- Have you checked for IP conflicts?
+- Have you checked the logs?
+- Have you checked the port number?
+- Have you checked for a zonefile dot?
+- Have you checked I/O dammit?
+- Have you checked the mounts?
+- Have you checked the power?
+- Have you checked for the wrong whitespace?
+- Have you checked if it reloaded into bad config?
+- Have you checked IP forwarding?
+- Have you checked the trailing slash?
+- Have you checked the MAC address?
+- Have you checked if the filesystem is out of inodes?
+- Have you checked the line length?
+- Have you checked if you're on the wrong wifi network?
+- Have you checked if the vpn timed out?
+- Have you checked if that's the wrong host?
+- Have you checked the security groups?
+- Have you checked the fucking binlogs?
+- Have you checked the documentation?
+- Have you checked the manpages?
diff --git a/src/view.rs b/src/view.rs
index 448b27c..3417e0f 100644
--- a/src/view.rs
+++ b/src/view.rs
@@ -45,6 +45,7 @@
use actix_web::{get, error, web};
use maud::{DOCTYPE, html, Markup, PreEscaped};
+use pulldown_cmark::{Parser, Options, html};
use rand::thread_rng;
use rand::seq::SliceRandom;
use serde::{Serialize, Deserialize};
@@ -105,12 +106,12 @@ impl From<&usize> for ItemQuery {
}
}
-fn index_view(req: impl Urls, idx: &usize, thing: &String) -> Result<Markup, UrlError> {
+fn index_view(req: impl Urls, idx: &usize, thing: &Thing) -> Result<Markup, UrlError> {
Ok(html! {
(DOCTYPE)
html {
head {
- title { "Have you checked " (thing) "?" }
+ title { (thing.markdown) }
style {
(PreEscaped("
body {
@@ -140,11 +141,11 @@ fn index_view(req: impl Urls, idx: &usize, thing: &String) -> Result<Markup, Url
}
meta property="og:type" content="website";
meta property="og:title" content="Troubleshooting suggestion";
- meta property="og:description" content={ "Have you checked " (thing) "?" };
+ meta property="og:description" content={ (thing.markdown) };
}
body {
section {
- p { "Have you checked " (PreEscaped(thing)) "?" }
+ (PreEscaped(&thing.html))
p {
a href=( req.index_url(ItemQuery::default())? ) { "That wasn't it, suggest something else." }
}
@@ -185,7 +186,39 @@ async fn index(
const THINGS: &str = include_str!("things-to-check.yml");
#[derive(Clone)]
-struct Things(Vec<(usize, String)>);
+struct Thing {
+ markdown: String,
+ html: String,
+}
+
+impl From<String> for Thing {
+ fn from(markdown: String) -> Self {
+ let options = Options::empty();
+ let parser = Parser::new_ext(&markdown, options);
+
+ let mut html = String::new();
+ html::push_html(&mut html, parser);
+
+ Thing{
+ markdown,
+ html,
+ }
+ }
+}
+
+#[derive(Clone)]
+struct Things(Vec<(usize, Thing)>);
+
+fn load_things(src: &str) -> serde_yaml::Result<Things> {
+ let raw_things: Vec<String> = serde_yaml::from_str(src)?;
+
+ Ok(Things(
+ raw_things.into_iter()
+ .map(Thing::from)
+ .enumerate()
+ .collect()
+ ))
+}
/// Errors that can arise initializing the service.
#[derive(Error, Debug)]
@@ -201,14 +234,11 @@ pub enum Error {
/// The returned function will configure any actix-web App with the necessary
/// state to tell people how to troubleshoot problems.
pub fn make_service() -> Result<impl Fn(&mut web::ServiceConfig) + Clone, Error> {
- let things: Vec<String> = serde_yaml::from_str(THINGS)?;
- let things = things.into_iter()
- .enumerate()
- .collect();
- let things = Things(things);
+ let things = load_things(THINGS)?;
Ok(move |cfg: &mut web::ServiceConfig| {
cfg.data(things.clone())
+ .data((123u8,))
.service(index);
})
}