feat: meta tag, resolve title

This commit is contained in:
Artemy Egorov 2024-08-07 15:13:16 +03:00
parent 4e320d9a44
commit f3231b52c4
8 changed files with 52 additions and 6 deletions

2
Cargo.lock generated
View file

@ -151,7 +151,7 @@ dependencies = [
[[package]] [[package]]
name = "dalet" name = "dalet"
version = "1.0.0-pre.12" version = "1.0.0-pre.13"
dependencies = [ dependencies = [
"bincode", "bincode",
"clap", "clap",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "dalet" name = "dalet"
version = "1.0.0-pre.12" version = "1.0.0-pre.13"
edition = "2021" edition = "2021"
authors = ["artegoser"] authors = ["artegoser"]
license = "MIT" license = "MIT"

View file

@ -73,10 +73,11 @@ pub enum DlTid {
Sup, Sup,
Sub, Sub,
Disc, Disc,
Bl, Block,
Carousel, Carousel,
Code, Code,
Pre, Pre,
Meta,
} }
pub trait IsNull { pub trait IsNull {

View file

@ -37,10 +37,11 @@ impl TryFrom<DlTag> for Tag {
DlTid::Sup => Sup(tag.body.try_into()?), DlTid::Sup => Sup(tag.body.try_into()?),
DlTid::Sub => Sub(tag.body.try_into()?), DlTid::Sub => Sub(tag.body.try_into()?),
DlTid::Disc => Disc(tag.body.try_into()?), DlTid::Disc => Disc(tag.body.try_into()?),
DlTid::Bl => Bl(tag.body.try_into()?, tag.argument.try_into()?), DlTid::Block => Block(tag.body.try_into()?, tag.argument.try_into()?),
DlTid::Carousel => Carousel(tag.body.try_into()?), DlTid::Carousel => Carousel(tag.body.try_into()?),
DlTid::Code => Code(tag.body.try_into()?, tag.argument.try_into()?), DlTid::Code => Code(tag.body.try_into()?, tag.argument.try_into()?),
DlTid::Pre => Pre(tag.body.try_into()?), DlTid::Pre => Pre(tag.body.try_into()?),
DlTid::Meta => Meta(tag.body.try_into()?, tag.argument.try_into()?),
}; };
Ok(result) Ok(result)

View file

@ -1,3 +1,4 @@
mod from_daletl; mod from_daletl;
mod is_null_daletl; mod is_null_daletl;
mod resolve_title;
mod to_daletl; mod to_daletl;

View file

@ -0,0 +1,37 @@
use crate::typed::{
Hl, NNBody, Page, ResolveTitle,
Tag::{self, Block, Meta, H},
};
impl ResolveTitle for Page {
fn resolve_title(&self) -> Option<&String> {
resolve_from_tags(&self.data)
}
}
fn resolve_from_tags(tags: &Vec<Tag>) -> Option<&String> {
for tag in tags {
match tag {
H(title, level) => {
if *level == Hl::One {
return Some(title);
}
}
Meta(body, key) => {
if key == "title" {
return Some(body);
}
}
Block(body, _) => match body {
NNBody::Tags(tags) => return resolve_from_tags(tags),
_ => {}
},
_ => {}
};
}
None
}

View file

@ -32,10 +32,11 @@ impl From<Tag> for DlTag {
Tag::Sup(b) => dlt_new(DlTid::Sup, b.into(), NA), Tag::Sup(b) => dlt_new(DlTid::Sup, b.into(), NA),
Tag::Sub(b) => dlt_new(DlTid::Sub, b.into(), NA), Tag::Sub(b) => dlt_new(DlTid::Sub, b.into(), NA),
Tag::Disc(b) => dlt_new(DlTid::Disc, b.into(), NA), Tag::Disc(b) => dlt_new(DlTid::Disc, b.into(), NA),
Tag::Bl(b, a) => dlt_new(DlTid::Bl, b.into(), a.into()), Tag::Block(b, a) => dlt_new(DlTid::Block, b.into(), a.into()),
Tag::Carousel(b) => dlt_new(DlTid::Carousel, b.into(), NA), Tag::Carousel(b) => dlt_new(DlTid::Carousel, b.into(), NA),
Tag::Code(b, a) => dlt_new(DlTid::Code, b.into(), a.into()), Tag::Code(b, a) => dlt_new(DlTid::Code, b.into(), a.into()),
Tag::Pre(b) => dlt_new(DlTid::Pre, b.into(), NA), Tag::Pre(b) => dlt_new(DlTid::Pre, b.into(), NA),
Tag::Meta(b, a) => dlt_new(DlTid::Meta, b.into(), a.into()),
} }
} }
} }

View file

@ -42,10 +42,11 @@ pub enum Tag {
Sup(TBody), Sup(TBody),
Sub(TBody), Sub(TBody),
Disc(NNBody), Disc(NNBody),
Bl(NNBody, AlignArg), Block(NNBody, AlignArg),
Carousel(Vec<Tag>), Carousel(Vec<Tag>),
Code(TBody, TNArg), Code(TBody, TNArg),
Pre(TBody), Pre(TBody),
Meta(TBody, TArg),
} }
#[derive(AutoFrom, Debug, Clone, PartialEq, Eq)] #[derive(AutoFrom, Debug, Clone, PartialEq, Eq)]
@ -106,3 +107,7 @@ pub enum Hl {
Five, Five,
Six, Six,
} }
pub trait ResolveTitle {
fn resolve_title(&self) -> Option<&String>;
}