From 4b5a465e91a9657f5321b77f684d5b0322660920 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Jul 2023 19:41:05 +0300 Subject: feat: allow any number of topics for a post Sponsored-by: author --- src/cmd.rs | 4 ++-- src/journal.rs | 8 +++++--- src/template.rs | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/cmd.rs b/src/cmd.rs index 07f985f..9c96af1 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -54,8 +54,8 @@ pub struct New { #[clap(help = "Title of new draft")] title: String, - #[clap(long, help = "Add link to a topic page")] - topic: Option, + #[clap(long, help = "Add links to topic pages")] + topic: Vec, } impl New { diff --git a/src/journal.rs b/src/journal.rs index f6f3e61..ee239de 100644 --- a/src/journal.rs +++ b/src/journal.rs @@ -71,7 +71,7 @@ impl Journal { pub fn new_draft( &self, title: &str, - topic: &Option, + topics: &[PathBuf], editor: &str, ) -> Result<(), JournalError> { let drafts = self.drafts(); @@ -83,13 +83,15 @@ impl Journal { let mut context = Context::new(); context.insert("title", title); context.insert("date", ¤t_timestamp()); - if let Some(ref topic) = topic { + let mut full_topics = vec![]; + for topic in topics.iter() { let pathname = topic_path(self.dirname(), topic); if !pathname.exists() { return Err(JournalError::NoSuchTopic(topic.to_path_buf())); } - context.insert("topic", &topic.display().to_string()); + full_topics.push(topic.display().to_string()); } + context.insert("topics", &full_topics); let pathname = self.pick_file_id(&drafts)?; let text = self.templates.new_draft(&context)?; diff --git a/src/template.rs b/src/template.rs index 4f9b0b6..f001a34 100644 --- a/src/template.rs +++ b/src/template.rs @@ -4,9 +4,9 @@ use tera::{Context, Tera}; const NEW_ENTRY: &str = r#"[[!meta title="{{ title }}"]] [[!meta date="{{ date }}"]] -{% if topic %} +{% for topic in topics %} [[!meta link="{{ topic }}"]] -{% endif %} +{% endfor %} "#; -- cgit v1.2.1