diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2020-06-04 00:01:12 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2020-06-04 00:02:58 -0400 |
| commit | 778bfdc57102816b1234d13ed022447a983942ee (patch) | |
| tree | c5ef8105c96bfafeeff36ab660a412f6ebdff4dc /src | |
| parent | 21de322d6cf221867ec9600e1a31777a195c7597 (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".
Diffstat (limited to 'src')
| -rw-r--r-- | src/things-to-check.yml | 68 | ||||
| -rw-r--r-- | src/view.rs | 50 |
2 files changed, 74 insertions, 44 deletions
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); }) } |
