diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-07-22 19:41:05 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-07-22 19:41:05 +0300 |
commit | 4b5a465e91a9657f5321b77f684d5b0322660920 (patch) | |
tree | df926ded028b2731925595b20dab286a0141539d /src | |
parent | e62bc1b23c83f437b254427c75e90c7b6ab49e93 (diff) | |
download | jt2-4b5a465e91a9657f5321b77f684d5b0322660920.tar.gz |
feat: allow any number of topics for a post
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd.rs | 4 | ||||
-rw-r--r-- | src/journal.rs | 8 | ||||
-rw-r--r-- | src/template.rs | 4 |
3 files changed, 9 insertions, 7 deletions
@@ -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<PathBuf>, + #[clap(long, help = "Add links to topic pages")] + topic: Vec<PathBuf>, } 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<PathBuf>, + 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 %} "#; |