start mara code
This commit is contained in:
parent
bf50cbffdc
commit
aec662ca10
|
@ -66,12 +66,6 @@ dependencies = [
|
|||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.1"
|
||||
|
@ -263,6 +257,32 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-eyre"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22ba9b5e817f1bc1f2219b5a3474b69f838321b2a2ba8860d6a71c3bfe3d0fc1"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"color-spantrace",
|
||||
"eyre",
|
||||
"indenter",
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-spantrace"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a99aa4aa18448eef4c7d3f86d2720d2d8cad5c860fe9ff9b279293efdc8f5be"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"tracing-core",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "comrak"
|
||||
version = "0.8.2"
|
||||
|
@ -433,6 +453,16 @@ dependencies = [
|
|||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "eyre"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0f9683839e579a53258d377fcc0073ca0bf2042ac5e6c60a598069e64403a6d"
|
||||
dependencies = [
|
||||
"indenter",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fake-simd"
|
||||
version = "0.1.2"
|
||||
|
@ -758,6 +788,12 @@ dependencies = [
|
|||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indenter"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0bd112d44d9d870a6819eb505d04dd92b5e4d94bb8c304924a0872ae7016fb5"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.5.0"
|
||||
|
@ -1139,6 +1175,12 @@ dependencies = [
|
|||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a1250cdd103eef6bd542b5ae82989f931fc00a41a27f60377338241594410f3"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.11.0"
|
||||
|
@ -1810,6 +1852,15 @@ dependencies = [
|
|||
"opaque-debug 0.3.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shell-words"
|
||||
version = "1.0.0"
|
||||
|
@ -2033,9 +2084,21 @@ checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9"
|
|||
dependencies = [
|
||||
"cfg-if",
|
||||
"log",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.11"
|
||||
|
@ -2045,6 +2108,16 @@ dependencies = [
|
|||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-error"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24"
|
||||
dependencies = [
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-futures"
|
||||
version = "0.2.4"
|
||||
|
@ -2055,6 +2128,16 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4f5dd7095c2481b7b3cbed71c8de53085fb3542bc3c2b4c73cba43e8f11c7ba"
|
||||
dependencies = [
|
||||
"sharded-slab",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.3"
|
||||
|
@ -2414,8 +2497,8 @@ checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
|
|||
name = "xesite"
|
||||
version = "2.0.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"color-eyre",
|
||||
"comrak",
|
||||
"envy",
|
||||
"glob",
|
||||
|
@ -2437,6 +2520,7 @@ dependencies = [
|
|||
"sitemap",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"url",
|
||||
"warp",
|
||||
"xml-rs",
|
||||
]
|
||||
|
|
|
@ -9,7 +9,7 @@ repository = "https://github.com/Xe/site"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
color-eyre = "0.5"
|
||||
chrono = "0.4"
|
||||
comrak = "0.8"
|
||||
envy = "0.4"
|
||||
|
@ -30,6 +30,7 @@ thiserror = "1"
|
|||
tokio = { version = "0.2", features = ["macros"] }
|
||||
warp = "0.2"
|
||||
xml-rs = "0.8"
|
||||
url = "2"
|
||||
|
||||
# workspace dependencies
|
||||
go_vanity = { path = "./lib/go_vanity" }
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
title: Mara Test
|
||||
date: 2020-09-18
|
||||
---
|
||||
|
||||
# Mara Test
|
||||
|
||||
[But if you do this thing, what about that other
|
||||
thing?](conversation://Mara/hmm)
|
||||
|
||||
[If you like using this, be sure to check out this other thing:
|
||||
https://h.christine.website](conversation://Mara/hacker)
|
||||
|
||||
[But, how does that make sense if you refrobnicated the bifrucated flopnax back
|
||||
there?](conversation://Mara/wat)
|
|
@ -33,6 +33,6 @@ mkShell {
|
|||
|
||||
SITE_PREFIX = "devel.";
|
||||
CLACK_SET = "Ashlynn,Terry Davis,Dennis Ritchie";
|
||||
RUST_LOG = "info";
|
||||
RUST_LOG = "debug";
|
||||
GITHUB_SHA = "devel";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
use color_eyre::eyre::{Result, WrapErr};
|
||||
use comrak::nodes::{Ast, AstNode, NodeValue};
|
||||
use comrak::{format_html, parse_document, Arena, ComrakOptions};
|
||||
use std::cell::RefCell;
|
||||
use url::Url;
|
||||
|
||||
pub fn render(inp: &str) -> Result<String> {
|
||||
let mut options = ComrakOptions::default();
|
||||
|
||||
options.extension.autolink = true;
|
||||
options.extension.table = true;
|
||||
options.extension.description_lists = true;
|
||||
options.extension.superscript = true;
|
||||
options.extension.strikethrough = true;
|
||||
options.extension.footnotes = true;
|
||||
|
||||
options.render.unsafe_ = true;
|
||||
|
||||
let arena = Arena::new();
|
||||
let root = parse_document(&arena, inp, &options);
|
||||
|
||||
iter_nodes(root, &|node| {
|
||||
let mut data = node.data.borrow_mut();
|
||||
match &mut data.value {
|
||||
&mut NodeValue::Link(ref mut link) => {
|
||||
let base = Url::parse("https://christine.website/")?;
|
||||
let u = base.join(std::str::from_utf8(&link.url.clone())?)?;
|
||||
if u.scheme() != "conversation" {
|
||||
return Ok(());
|
||||
}
|
||||
let parent = node.parent().unwrap();
|
||||
node.detach();
|
||||
let mut message = vec![];
|
||||
format_html(node.first_child().unwrap(), &options, &mut message)?;
|
||||
let message = std::str::from_utf8(&message)?;
|
||||
let mood = without_first(u.path());
|
||||
let name = u.host_str().unwrap_or("Mara");
|
||||
|
||||
let mut html = vec![];
|
||||
crate::templates::mara(&mut html, mood, name, message)?;
|
||||
|
||||
let new_node =
|
||||
arena.alloc(AstNode::new(RefCell::new(Ast::new(NodeValue::HtmlInline(html)))));
|
||||
parent.append(new_node);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
_ => Ok(()),
|
||||
}
|
||||
})?;
|
||||
|
||||
let mut html = vec![];
|
||||
format_html(root, &options, &mut html).unwrap();
|
||||
|
||||
String::from_utf8(html).wrap_err("post is somehow invalid UTF-8")
|
||||
}
|
||||
|
||||
fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F) -> Result<()>
|
||||
where
|
||||
F: Fn(&'a AstNode<'a>) -> Result<()>,
|
||||
{
|
||||
f(node)?;
|
||||
for c in node.children() {
|
||||
iter_nodes(c, f)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn without_first(string: &str) -> &str {
|
||||
string
|
||||
.char_indices()
|
||||
.nth(1)
|
||||
.and_then(|(i, _)| string.get(i..))
|
||||
.unwrap_or("")
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
use crate::{post::Post, signalboost::Person};
|
||||
use anyhow::Result;
|
||||
use comrak::{markdown_to_html, ComrakOptions};
|
||||
use color_eyre::eyre::Result;
|
||||
use serde::Deserialize;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub mod markdown;
|
||||
|
||||
#[derive(Clone, Deserialize)]
|
||||
pub struct Config {
|
||||
#[serde(rename = "clackSet")]
|
||||
|
@ -14,21 +15,6 @@ pub struct Config {
|
|||
resume_fname: PathBuf,
|
||||
}
|
||||
|
||||
pub fn markdown(inp: &str) -> String {
|
||||
let mut options = ComrakOptions::default();
|
||||
|
||||
options.extension.autolink = true;
|
||||
options.extension.table = true;
|
||||
options.extension.description_lists = true;
|
||||
options.extension.superscript = true;
|
||||
options.extension.strikethrough = true;
|
||||
options.extension.footnotes = true;
|
||||
|
||||
options.render.unsafe_ = true;
|
||||
|
||||
markdown_to_html(inp, &options)
|
||||
}
|
||||
|
||||
async fn patrons() -> Result<Option<patreon::Users>> {
|
||||
use patreon::*;
|
||||
let creds: Credentials = envy::prefixed("PATREON_").from_env().unwrap();
|
||||
|
@ -72,7 +58,7 @@ pub async fn init(cfg: PathBuf) -> Result<State> {
|
|||
let cfg: Config = serde_dhall::from_file(cfg).parse()?;
|
||||
let sb = cfg.signalboost.clone();
|
||||
let resume = fs::read_to_string(cfg.resume_fname.clone())?;
|
||||
let resume: String = markdown(&resume);
|
||||
let resume: String = markdown::render(&resume)?;
|
||||
let blog = crate::post::load("blog")?;
|
||||
let gallery = crate::post::load("gallery")?;
|
||||
let talks = crate::post::load("talks")?;
|
|
@ -1,4 +1,4 @@
|
|||
use anyhow::Result;
|
||||
use color_eyre::eyre::Result;
|
||||
use hyper::{header::CONTENT_TYPE, Body, Response};
|
||||
use prometheus::{Encoder, TextEncoder};
|
||||
use std::sync::Arc;
|
||||
|
@ -21,6 +21,7 @@ fn with_state(
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
let _ = kankyo::init();
|
||||
pretty_env_logger::init();
|
||||
log::info!("starting up commit {}", env!("GITHUB_SHA"));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/// This code was borrowed from @fasterthanlime.
|
||||
|
||||
use anyhow::{Result};
|
||||
use color_eyre::eyre::{Result};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Eq, PartialEq, Deserialize, Default, Debug, Serialize, Clone)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use chrono::prelude::*;
|
||||
use color_eyre::eyre::{eyre, Result, WrapErr};
|
||||
use glob::glob;
|
||||
use std::{cmp::Ordering, fs};
|
||||
|
||||
|
@ -75,8 +75,10 @@ pub fn load(dir: &str) -> Result<Vec<Post>> {
|
|||
|
||||
for path in glob(&format!("{}/*.markdown", dir))?.filter_map(Result::ok) {
|
||||
log::debug!("loading {:?}", path);
|
||||
let body = fs::read_to_string(path.clone()).expect("things to work");
|
||||
let (fm, content_offset) = frontmatter::Data::parse(body.clone().as_str()).expect("stuff to work");
|
||||
let body =
|
||||
fs::read_to_string(path.clone()).wrap_err_with(|| format!("can't read {:?}", path))?;
|
||||
let (fm, content_offset) = frontmatter::Data::parse(body.clone().as_str())
|
||||
.wrap_err_with(|| format!("can't parse frontmatter of {:?}", path))?;
|
||||
let markup = &body[content_offset..];
|
||||
let date = NaiveDate::parse_from_str(&fm.clone().date, "%Y-%m-%d")?;
|
||||
|
||||
|
@ -84,7 +86,8 @@ pub fn load(dir: &str) -> Result<Vec<Post>> {
|
|||
front_matter: fm,
|
||||
link: format!("{}/{}", dir, path.file_stem().unwrap().to_str().unwrap()),
|
||||
body: markup.to_string(),
|
||||
body_html: crate::app::markdown(&markup),
|
||||
body_html: crate::app::markdown::render(&markup)
|
||||
.wrap_err_with(|| format!("can't parse markdown for {:?}", path))?,
|
||||
date: {
|
||||
DateTime::<Utc>::from_utc(
|
||||
NaiveDateTime::new(date, NaiveTime::from_hms(0, 0, 0)),
|
||||
|
@ -97,7 +100,7 @@ pub fn load(dir: &str) -> Result<Vec<Post>> {
|
|||
}
|
||||
|
||||
if result.len() == 0 {
|
||||
Err(anyhow!("no posts loaded"))
|
||||
Err(eyre!("no posts loaded"))
|
||||
} else {
|
||||
result.sort();
|
||||
result.reverse();
|
||||
|
@ -108,7 +111,7 @@ pub fn load(dir: &str) -> Result<Vec<Post>> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use anyhow::Result;
|
||||
use color_eyre::eyre::Result;
|
||||
|
||||
#[test]
|
||||
fn blog() {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
@(mood: &str, character: &str, message: &str)
|
||||
<div class="grid conversation">
|
||||
<div class="cell -2of12">
|
||||
<div class="content">
|
||||
<picture>
|
||||
<source srcset="https://cdn.christine.website/file/christine-static/stickers/@character.to_lowercase()/@(mood).webp" height="75%" width="75%" type="image/webp">
|
||||
<img src="https://cdn.christine.website/file/christine-static/stickers/@character.to_lowercase()/@(mood).png" height="75%" width="75%" alt="@message">
|
||||
</picture>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell -10of12">
|
||||
<div class="content"><p><b>@character</b><br></p><blockquote>@message</blockquote></div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue