Skip to content

Commit

Permalink
feat: add event, location, and date frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Jul 30, 2024
1 parent fd2a9d9 commit 002cd13
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 35 deletions.
16 changes: 9 additions & 7 deletions docs/src/guides/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ the right (but hey, you're free to do so!).
The following elements support alignment:
* Code blocks.
* Slide titles.
* The title, subtitle, and author elements in the intro slide.
* The title, subtitle, event, location, date, and the author elements in the intro slide.
* Tables.

#### Left/right alignment
Expand Down Expand Up @@ -190,22 +190,24 @@ default:

### Intro slide

The introductory slide will be rendered if you specify a title, subtitle, or author in the presentation's front matter.
This lets you have a less markdown-looking introductory slide that stands out so that it doesn't end up looking too
monotonous:
The introductory slide will be rendered if you specify a title, subtitle, event, location, date, or author in the presentation's front matter.
This lets you have a less markdown-looking introductory slide that stands out so that it doesn't end up looking too monotonous:

```yaml
---
title: Presenting from my terminal
sub_title: Like it's 1990
event: TerminalCon 2021
location: Las Vegas, NV
date: 2021-09-01
author: John Doe
---
```

The theme can specify:
* For the title and subtitle, the alignment and colors.
* For the author, the alignment, colors, and positioning (`page_bottom` and `below_title`). The first one will push it
to the bottom of the screen while the second one will put it right below the title (or subtitle if there is one)
* For the title, subtitle, event, location, and the date: the alignment and colors.
* For the author: the alignment, colors, and positioning (`page_bottom` and `below_title`). The first one will push it
to the bottom of the screen while the second one will put it right below the title (or other front matter).

For example:

Expand Down
3 changes: 3 additions & 0 deletions examples/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ An introduction slide can be defined by using a front matter at the beginning of
---
title: My presentation title
sub_title: An optional subtitle
event: The event the presentation is for
location: The location of the presentation
date: The date of the presentation
author: Your name which will appear somewhere in the bottom
---
```
Expand Down
25 changes: 25 additions & 0 deletions src/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,18 @@ pub(crate) struct PresentationMetadata {
#[serde(default)]
pub(crate) sub_title: Option<String>,

/// The presentation event.
#[serde(default)]
pub(crate) event: Option<String>,

/// The presentation location.
#[serde(default)]
pub(crate) location: Option<String>,

/// The presentation date.
#[serde(default)]
pub(crate) date: Option<String>,

/// The presentation author.
#[serde(default)]
pub(crate) author: Option<String>,
Expand All @@ -510,6 +522,19 @@ pub(crate) struct PresentationMetadata {
pub(crate) options: Option<OptionsConfig>,
}

impl PresentationMetadata {
/// Check if this presentation has frontmatter.
pub(crate) fn has_frontmatter(&self) -> bool {
self.title.is_some()
|| self.sub_title.is_some()
|| self.event.is_some()
|| self.location.is_some()
|| self.date.is_some()
|| self.author.is_some()
|| !self.authors.is_empty()
}
}

/// A presentation's theme metadata.
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct PresentationThemeMetadata {
Expand Down
66 changes: 44 additions & 22 deletions src/processing/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,7 @@ impl<'a> PresentationBuilder<'a> {
}
self.footer_context.borrow_mut().author = metadata.author.clone().unwrap_or_default();
self.set_theme(&metadata.theme)?;
if metadata.title.is_some()
|| metadata.sub_title.is_some()
|| metadata.author.is_some()
|| !metadata.authors.is_empty()
{
if metadata.has_frontmatter() {
self.push_slide_prelude();
self.push_intro_slide(metadata);
}
Expand Down Expand Up @@ -336,15 +332,14 @@ impl<'a> PresentationBuilder<'a> {
}

fn push_intro_slide(&mut self, metadata: PresentationMetadata) {
let styles = &self.theme.intro_slide;
let title = Text::new(
metadata.title.unwrap_or_default().clone(),
TextStyle::default().bold().colors(styles.title.colors.clone()),
);
let sub_title = metadata
.sub_title
.as_ref()
.map(|text| Text::new(text.clone(), TextStyle::default().colors(styles.subtitle.colors.clone())));
let styles = self.theme.intro_slide.clone();
let create_text =
|text: Option<String>, style: TextStyle| -> Option<Text> { text.map(|text| Text::new(text, style)) };
let title = create_text(metadata.title, TextStyle::default().bold().colors(styles.title.colors));
let sub_title = create_text(metadata.sub_title, TextStyle::default().colors(styles.subtitle.colors));
let event = create_text(metadata.event, TextStyle::default().colors(styles.event.colors));
let location = create_text(metadata.location, TextStyle::default().colors(styles.location.colors));
let date = create_text(metadata.date, TextStyle::default().colors(styles.date.colors));
let authors: Vec<_> = metadata
.author
.into_iter()
Expand All @@ -355,11 +350,24 @@ impl<'a> PresentationBuilder<'a> {
self.slide_state.ignore_footer = true;
}
self.chunk_operations.push(RenderOperation::JumpToVerticalCenter);
self.push_text(TextBlock::from(title), ElementType::PresentationTitle);
self.push_line_break();
if let Some(text) = sub_title {
self.push_text(TextBlock::from(text), ElementType::PresentationSubTitle);
if let Some(title) = title {
self.push_line(title, ElementType::PresentationTitle);
}
if let Some(sub_title) = sub_title {
self.push_line(sub_title, ElementType::PresentationSubTitle);
}
if event.is_some() || location.is_some() || date.is_some() {
self.push_line_break();
self.push_line_break();
if let Some(event) = event {
self.push_line(event, ElementType::PresentationEvent);
}
if let Some(location) = location {
self.push_line(location, ElementType::PresentationLocation);
}
if let Some(date) = date {
self.push_line(date, ElementType::PresentationDate);
}
}
if !authors.is_empty() {
match self.theme.intro_slide.author.positioning {
Expand All @@ -373,8 +381,7 @@ impl<'a> PresentationBuilder<'a> {
}
};
for author in authors {
self.push_text(TextBlock::from(author), ElementType::PresentationAuthor);
self.push_line_break();
self.push_line(author, ElementType::PresentationAuthor);
}
}
self.slide_state.title = Some(TextBlock::from("[Introduction]"));
Expand Down Expand Up @@ -671,6 +678,11 @@ impl<'a> PresentationBuilder<'a> {
self.chunk_operations.push(RenderOperation::SetColors(self.theme.default_style.colors.clone()));
}

fn push_line(&mut self, text: Text, element_type: ElementType) {
self.push_text(TextBlock::from(text), element_type);
self.push_line_break();
}

fn push_text(&mut self, text: TextBlock, element_type: ElementType) {
let alignment = self.theme.alignment(&element_type);
self.push_aligned_text(text, alignment);
Expand Down Expand Up @@ -1084,6 +1096,15 @@ struct StrictPresentationMetadata {
#[serde(default)]
sub_title: Option<String>,

#[serde(default)]
event: Option<String>,

#[serde(default)]
location: Option<String>,

#[serde(default)]
date: Option<String>,

#[serde(default)]
author: Option<String>,

Expand All @@ -1099,8 +1120,9 @@ struct StrictPresentationMetadata {

impl From<StrictPresentationMetadata> for PresentationMetadata {
fn from(strict: StrictPresentationMetadata) -> Self {
let StrictPresentationMetadata { title, sub_title, author, authors, theme, options } = strict;
Self { title, sub_title, author, authors, theme, options }
let StrictPresentationMetadata { title, sub_title, event, location, date, author, authors, theme, options } =
strict;
Self { title, sub_title, event, location, date, author, authors, theme, options }
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ impl PresentationTheme {
Code => &self.code.alignment,
PresentationTitle => &self.intro_slide.title.alignment,
PresentationSubTitle => &self.intro_slide.subtitle.alignment,
PresentationEvent => &self.intro_slide.event.alignment,
PresentationLocation => &self.intro_slide.location.alignment,
PresentationDate => &self.intro_slide.date.alignment,
PresentationAuthor => &self.intro_slide.author.alignment,
Table => &self.table,
BlockQuote => &self.block_quote.alignment,
Expand Down Expand Up @@ -336,6 +339,18 @@ pub(crate) struct IntroSlideStyle {
#[serde(default)]
pub(crate) subtitle: BasicStyle,

/// The style of the event line.
#[serde(default)]
pub(crate) event: BasicStyle,

/// The style of the location line.
#[serde(default)]
pub(crate) location: BasicStyle,

/// The style of the date line.
#[serde(default)]
pub(crate) date: BasicStyle,

/// The style of the author line.
#[serde(default)]
pub(crate) author: AuthorStyle,
Expand Down Expand Up @@ -580,6 +595,9 @@ pub(crate) enum ElementType {
Code,
PresentationTitle,
PresentationSubTitle,
PresentationEvent,
PresentationLocation,
PresentationDate,
PresentationAuthor,
Table,
BlockQuote,
Expand Down
13 changes: 13 additions & 0 deletions themes/catppuccin-frappe.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
default:
margin:
percent: 8
Expand Down Expand Up @@ -48,6 +49,18 @@ intro_slide:
alignment: center
colors:
foreground: "85c1dc"
event:
alignment: center
colors:
foreground: "a6d189"
location:
alignment: center
colors:
foreground: "85c1dc"
date:
alignment: center
colors:
foreground: "e5c890"
author:
alignment: center
colors:
Expand Down
13 changes: 13 additions & 0 deletions themes/catppuccin-latte.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
default:
margin:
percent: 8
Expand Down Expand Up @@ -48,6 +49,18 @@ intro_slide:
alignment: center
colors:
foreground: "209fb5"
event:
alignment: center
colors:
foreground: "40a02b"
location:
alignment: center
colors:
foreground: "209fb5"
date:
alignment: center
colors:
foreground: "df8e1d"
author:
alignment: center
colors:
Expand Down
13 changes: 13 additions & 0 deletions themes/catppuccin-macchiato.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
default:
margin:
percent: 8
Expand Down Expand Up @@ -48,6 +49,18 @@ intro_slide:
alignment: center
colors:
foreground: "7dc4e4"
event:
alignment: center
colors:
foreground: "a6da95"
location:
alignment: center
colors:
foreground: "7dc4e4"
date:
alignment: center
colors:
foreground: "eed49f"
author:
alignment: center
colors:
Expand Down
13 changes: 13 additions & 0 deletions themes/catppuccin-mocha.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
default:
margin:
percent: 8
Expand Down Expand Up @@ -48,6 +49,18 @@ intro_slide:
alignment: center
colors:
foreground: "74c7ec"
event:
alignment: center
colors:
foreground: "a6e3a1"
location:
alignment: center
colors:
foreground: "74c7ec"
date:
alignment: center
colors:
foreground: "f9e2af"
author:
alignment: center
colors:
Expand Down
15 changes: 14 additions & 1 deletion themes/dark.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
default:
margin:
percent: 8
Expand Down Expand Up @@ -49,6 +50,18 @@ intro_slide:
alignment: center
colors:
foreground: "a5d7e8"
event:
alignment: center
colors:
foreground: "b4ccff"
location:
alignment: center
colors:
foreground: "a5d7e8"
date:
alignment: center
colors:
foreground: "ee9322"
author:
alignment: center
colors:
Expand Down Expand Up @@ -93,7 +106,7 @@ typst:
foreground: "f0f0f0"
background: "292e42"

footer:
footer:
style: progress_bar
colors:
foreground: "7aa2f7"
Expand Down
Loading

0 comments on commit 002cd13

Please sign in to comment.