summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-07-22 16:45:26 +0000
committerLars Wirzenius <liw@liw.fi>2023-07-22 16:45:26 +0000
commita959c4aa500d3c72dfa884319aa5a6e36fe47cab (patch)
treedf926ded028b2731925595b20dab286a0141539d
parentd13479dd8aac43e9c5b7f447c2d4bc710c2b9bee (diff)
parent4b5a465e91a9657f5321b77f684d5b0322660920 (diff)
downloadjt2-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.md34
-rw-r--r--src/cmd.rs4
-rw-r--r--src/journal.rs8
-rw-r--r--src/template.rs4
4 files changed, 29 insertions, 21 deletions
diff --git a/jt.md b/jt.md
index a0e48a4..ca4f108 100644
--- a/jt.md
+++ b/jt.md
@@ -1,17 +1,3 @@
----
-title: "jt&mdash;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
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<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", &current_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 %}
"#;