feat: markdown implementation
#18
1 changed files with 9 additions and 4 deletions
|
@ -22,7 +22,7 @@ enum FrontMatter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FrontMatter<'_> {
|
impl FrontMatter<'_> {
|
||||||
fn parse(&self) -> Metadata {
|
fn parse(&self) -> FileMetadata {
|
||||||
match self {
|
match self {
|
||||||
Self::Yaml(val) => serde_yaml::from_str(val).unwrap_or_default(),
|
Self::Yaml(val) => serde_yaml::from_str(val).unwrap_or_default(),
|
||||||
Self::Toml(_val) => todo!(),
|
Self::Toml(_val) => todo!(),
|
||||||
|
@ -32,8 +32,13 @@ impl FrontMatter<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Deserialize)]
|
#[derive(Default, Deserialize)]
|
||||||
pub struct Metadata {
|
pub struct FileMetadata {
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
|
pub link: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Metadata {
|
||||||
|
pub info: FileMetadata,
|
||||||
pub mermaid: bool,
|
pub mermaid: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +70,7 @@ pub fn read_md(filename: &str) -> (Metadata, String) {
|
||||||
markdown::mdast::Node::Yaml(v) => FrontMatter::Yaml(&v.value).parse(),
|
markdown::mdast::Node::Yaml(v) => FrontMatter::Yaml(&v.value).parse(),
|
||||||
markdown::mdast::Node::Toml(v) => FrontMatter::Toml(&v.value).parse(),
|
markdown::mdast::Node::Toml(v) => FrontMatter::Toml(&v.value).parse(),
|
||||||
markdown::mdast::Node::MdxjsEsm(v) => FrontMatter::Json(&v.value).parse(),
|
markdown::mdast::Node::MdxjsEsm(v) => FrontMatter::Json(&v.value).parse(),
|
||||||
_ => Metadata::default(),
|
_ => FileMetadata::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Convert to HTML
|
// Convert to HTML
|
||||||
|
@ -92,8 +97,8 @@ pub fn read_md(filename: &str) -> (Metadata, String) {
|
||||||
|
|
||||||
(
|
(
|
||||||
Metadata {
|
Metadata {
|
||||||
|
info: metadata,
|
||||||
mermaid: presence_mermaid,
|
mermaid: presence_mermaid,
|
||||||
..metadata
|
|
||||||
},
|
},
|
||||||
html,
|
html,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue