Skip to content

Commit

Permalink
Codebase improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
KmolYuan committed Apr 18, 2022
1 parent 0b9ab19 commit 4098134
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
6 changes: 0 additions & 6 deletions src/project/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ impl Default for Metadata {
}

impl Metadata {
/// Disable the outline option.
pub fn disable_outline(self) -> Self {
let outline = Optional::Bool(false);
Self { outline, ..self }
}

/// Build HTML from template.
pub fn build(self, slides: Slides, mount: &str, auto_reload: bool) -> String {
let Self {
Expand Down
36 changes: 14 additions & 22 deletions src/project/slides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Slides {
T: ToString,
D: ToString,
{
let slide = ChapterSlide {
let slides = vec![ChapterSlide {
slide: Slide {
title: title.to_string(),
content: Content {
Expand All @@ -47,20 +47,15 @@ impl Slides {
..Default::default()
},
..Default::default()
};
let slides = Self {
slides: vec![slide],
};
Metadata::default()
.disable_outline()
.build(slides, "/static/", true)
}];
Metadata::default().build(Self { slides }, "/static/", true)
}
}

impl ToHtml for Slides {
fn to_html(self, ctx: &Ctx) -> String {
let Self { mut slides } = self;
if !ctx.outline.is_empty() {
if !ctx.outline.is_empty() && slides.len() > 1 {
let doc = slides
.iter()
.enumerate()
Expand Down Expand Up @@ -97,18 +92,15 @@ impl ToHtml for Slides {
}
})
.collect();
if let Some(cover) = slides.first_mut() {
cover.sub.push(Slide {
title: ctx.outline.clone(),
id: "outline".to_string(),
content: Content {
doc,
..Default::default()
},
background: Optional::Bool(true),
slides.first_mut().unwrap().sub.push(Slide {
title: ctx.outline.clone(),
id: "outline".to_string(),
content: Content {
doc,
..Default::default()
});
}
},
..Default::default()
});
}
slides.to_html(ctx)
}
Expand All @@ -130,10 +122,10 @@ pub struct ChapterSlide {
impl ToHtml for ChapterSlide {
fn to_html(self, ctx: &Ctx) -> String {
let Self { slide, sub } = self;
let title = slide_title(&slide).to_string();
if let Some(header) = &ctx.chapter_header {
header.replace(String::new());
header.borrow_mut().clear();
}
let title = slide_title(&slide).to_string();
let slide = slide.to_html(ctx);
if let Some(header) = &ctx.chapter_header {
header.replace(title);
Expand Down

0 comments on commit 4098134

Please sign in to comment.