|
|
@ -1,13 +1,15 @@
|
|
|
|
use core::panic;
|
|
|
|
use core::panic;
|
|
|
|
use std::str::FromStr;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use comrak::format_html;
|
|
|
|
use serde::{Deserialize, Deserializer, Serialize};
|
|
|
|
use serde::{Deserialize, Deserializer, Serialize};
|
|
|
|
use serde_yaml::Value;
|
|
|
|
use serde_yaml::Value;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{prelude::*};
|
|
|
|
use crate::{prelude::*, utils::furigana_to_html};
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct Challenge {
|
|
|
|
pub struct Challenge {
|
|
|
|
|
|
|
|
pub text: Option<String>,
|
|
|
|
pub japanese: Option<Vec<Vec<Vec<ChallengeWord>>>>,
|
|
|
|
pub japanese: Option<Vec<Vec<Vec<ChallengeWord>>>>,
|
|
|
|
pub english: Option<Vec<String>>,
|
|
|
|
pub english: Option<Vec<String>>,
|
|
|
|
pub song: Option<Song>,
|
|
|
|
pub song: Option<Song>,
|
|
|
@ -29,10 +31,11 @@ impl Challenge {
|
|
|
|
options
|
|
|
|
options
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let arena = Arena::new();
|
|
|
|
let arena = Arena::new();
|
|
|
|
|
|
|
|
let challenge_text = fs::read_to_string(format!("content/challenges/{number}.md"))
|
|
|
|
|
|
|
|
.expect("Couldn't find challenge file");
|
|
|
|
let root = parse_document(
|
|
|
|
let root = parse_document(
|
|
|
|
&arena,
|
|
|
|
&arena,
|
|
|
|
& (fs::read_to_string(format!("content/challenges/{number}.md"))
|
|
|
|
&(challenge_text.clone()
|
|
|
|
.expect("Couldn't find challenge file")
|
|
|
|
|
|
|
|
// comrak can't find frontmatter if there's only frontmatter and no newline at end
|
|
|
|
// comrak can't find frontmatter if there's only frontmatter and no newline at end
|
|
|
|
// TODO: Open issue in comrak
|
|
|
|
// TODO: Open issue in comrak
|
|
|
|
+ "\n"),
|
|
|
|
+ "\n"),
|
|
|
@ -45,7 +48,13 @@ impl Challenge {
|
|
|
|
let lines: Vec<&str> = frontmatter.trim().lines().collect();
|
|
|
|
let lines: Vec<&str> = frontmatter.trim().lines().collect();
|
|
|
|
lines[1..lines.len() - 1].join("\n")
|
|
|
|
lines[1..lines.len() - 1].join("\n")
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let challenge: Challenge = serde_yaml::from_str(&frontmatter).unwrap();
|
|
|
|
let mut challenge: Challenge = serde_yaml::from_str(&frontmatter).unwrap();
|
|
|
|
|
|
|
|
//challenge.text = Some(challenge_text.replace(&frontmatter, "").trim().to_owned());
|
|
|
|
|
|
|
|
let mut html = vec![];
|
|
|
|
|
|
|
|
format_html(root, &ComrakOptions::default(), &mut html)
|
|
|
|
|
|
|
|
.expect("Failed to format HTML");
|
|
|
|
|
|
|
|
challenge.text = Some(furigana_to_html(&gh_emoji::Replacer::new()
|
|
|
|
|
|
|
|
.replace_all(&String::from_utf8(html).unwrap())));
|
|
|
|
challenge
|
|
|
|
challenge
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
panic!("No frontmatter!")
|
|
|
|
panic!("No frontmatter!")
|
|
|
|