From fd854872ce86f9ae5d07ec59e598fe85a8607d5c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 20 Oct 2022 18:32:30 +0300 Subject: fix: look up markdown file relative to basedir of subplot This allows running docgen on a subplot that isn't in the current directory. Sponsored-by: author --- src/bin/subplot.rs | 3 ++- src/metadata.rs | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs index a85ad62..8ede58d 100644 --- a/src/bin/subplot.rs +++ b/src/bin/subplot.rs @@ -278,7 +278,8 @@ impl Docgen { } else if let Some(date) = doc.meta().date() { date.to_string() } else { - Self::mtime_formatted(Self::mtime(doc.meta().markdown_filename())?) + let filename = doc.meta().basedir().join(doc.meta().markdown_filename()); + Self::mtime_formatted(Self::mtime(&filename)?) }; pandoc.add_option(pandoc::PandocOption::Meta("date".to_string(), Some(date))); pandoc.add_option(pandoc::PandocOption::TableOfContents); diff --git a/src/metadata.rs b/src/metadata.rs index dee0b50..261017a 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -12,6 +12,7 @@ use log::trace; /// Metadata of a document, as needed by Subplot. #[derive(Debug)] pub struct Metadata { + basedir: PathBuf, title: String, date: Option, markdown_filename: PathBuf, @@ -74,6 +75,7 @@ impl Metadata { trace!("Loaded all metadata successfully"); Ok(Metadata { + basedir: basedir.as_ref().to_path_buf(), title, date, markdown_filename: meta.markdown().into(), @@ -95,6 +97,11 @@ impl Metadata { self.date.as_deref() } + /// Return base dir for all relative filenames. + pub fn basedir(&self) -> &Path { + &self.basedir + } + /// Return filename of the markdown file. pub fn markdown_filename(&self) -> &Path { &self.markdown_filename -- cgit v1.2.1