summaryrefslogtreecommitdiff
path: root/src/journal.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/journal.rs')
-rw-r--r--src/journal.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/journal.rs b/src/journal.rs
index a48a63d..270bb19 100644
--- a/src/journal.rs
+++ b/src/journal.rs
@@ -198,7 +198,18 @@ impl Journal {
let mut context = Context::new();
context.insert("title", title);
+ let dirname = self.dirname();
+ if !dirname.exists() {
+ return Err(JournalError::NoJournalDirectory(dirname.to_path_buf()));
+ }
+
let pathname = topic_path(self.dirname(), path);
+ let parent = pathname.parent().unwrap();
+ if !parent.is_dir() {
+ std::fs::create_dir_all(&parent)
+ .map_err(|err| JournalError::CreateDirectory(parent.to_path_buf(), err))?;
+ }
+
let text = self.templates.new_topic(&context)?;
std::fs::write(&pathname, text)
.map_err(|err| JournalError::WriteTopic(pathname.to_path_buf(), err))?;