summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2022-10-22 08:59:48 +0000
committerDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2022-10-22 08:59:48 +0000
commit81e985cc026d67e3d506d485b3bf013bfd82987e (patch)
tree13cbc60820d24ec6f797d839f3e40ea92d67ed91
parent18dedca71451dab31f43a0725277308471d32dfe (diff)
parentfd854872ce86f9ae5d07ec59e598fe85a8607d5c (diff)
downloadsubplot-81e985cc026d67e3d506d485b3bf013bfd82987e.tar.gz
Merge branch 'liw/relative' into 'main'
fix running docgen on a subplot in a different directory See merge request subplot/subplot!293
-rw-r--r--src/bin/subplot.rs8
-rw-r--r--src/error.rs8
-rw-r--r--src/metadata.rs7
3 files changed, 21 insertions, 2 deletions
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs
index 907e616..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);
@@ -308,7 +309,10 @@ impl Docgen {
}
fn mtime(filename: &Path) -> Result<(u64, u32)> {
- let mtime = fs::metadata(filename)?.modified()?;
+ let mtime = fs::metadata(filename)
+ .map_err(|e| SubplotError::InputFileUnreadable(filename.into(), e))?
+ .modified()
+ .map_err(|e| SubplotError::InputFileMtime(filename.into(), e))?;
let mtime = mtime.duration_since(UNIX_EPOCH)?;
Ok((mtime.as_secs(), mtime.subsec_nanos()))
}
diff --git a/src/error.rs b/src/error.rs
index 53eccad..a729bf0 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -321,6 +321,14 @@ pub enum SubplotError {
/// String formatting failed.
#[error("Failed in string formattiing: {0}")]
StringFormat(std::fmt::Error),
+
+ /// Input file could not be read.
+ #[error("Failed to read input file {0}")]
+ InputFileUnreadable(PathBuf, #[source] std::io::Error),
+
+ /// Input file mtime lookup.
+ #[error("Failed to get modification time of {0}")]
+ InputFileMtime(PathBuf, #[source] std::io::Error),
}
impl SubplotError {
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<String>,
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