diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-07-22 16:45:26 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-07-22 16:45:26 +0000 |
commit | a959c4aa500d3c72dfa884319aa5a6e36fe47cab (patch) | |
tree | df926ded028b2731925595b20dab286a0141539d | |
parent | d13479dd8aac43e9c5b7f447c2d4bc710c2b9bee (diff) | |
parent | 4b5a465e91a9657f5321b77f684d5b0322660920 (diff) | |
download | jt2-a959c4aa500d3c72dfa884319aa5a6e36fe47cab.tar.gz |
Merge branch 'chores' into 'main'
chore(jt.md): drop now-useless YAML metadata
See merge request larswirzenius/jt!38
-rw-r--r-- | jt.md | 34 | ||||
-rw-r--r-- | src/cmd.rs | 4 | ||||
-rw-r--r-- | src/journal.rs | 8 | ||||
-rw-r--r-- | src/template.rs | 4 |
4 files changed, 29 insertions, 21 deletions
@@ -1,17 +1,3 @@ ---- -title: "jt—a journalling tool" -author: Lars Wirzenius and Daniel Silverstone -bindings: -- subplot/jt.yaml -- lib/files.yaml -- lib/runcmd.yaml -impls: - python: - - subplot/jt.py - - lib/files.py - - lib/runcmd.py -... - # Introduction The **jt** software (short for "journalling tool") is a helper for @@ -323,6 +309,26 @@ and there is one draft in jrnl and draft 0 in jrnl links to "topics/foo.bar" ~~~ +## Allow many topics per post + +Sometimes a post relates to several topics. + +~~~scenario +given an installed jt + +when I run jt --dirname jrnl init default "My test journal" +then command is successful + +when I run jt --editor=none --dirname=jrnl new-topic topics/foo "Foo" +when I run jt --editor=none --dirname=jrnl new-topic topics/bar "Bar" + +when I run jt --editor=none --dirname=jrnl new --topic topics/foo --topic topics/bar "Abracadabra" +then command is successful +then there is one draft in jrnl +then draft 0 in jrnl links to "topics/foo" +then draft 0 in jrnl links to "topics/bar" +~~~ + # Colophon @@ -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 %} "#; |