Skip to content

Commit

Permalink
Adds default file
Browse files Browse the repository at this point in the history
  • Loading branch information
xfbs committed Dec 29, 2023
1 parent 482a691 commit ca36cb2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
tera = { version = "1.19.1", default-features = false, features = ["builtins"] }
toml = "0.5.11"
uuid = { version = "1.6.1", features = ["v4"] }
uuid = { version = "1.6.1", features = ["v4", "serde"] }
3 changes: 3 additions & 0 deletions docs/src/reference/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ path = "path/to/folder"
# file. Without `!`, all matches of the glob provided are treated as whitelist matches.
ignore = ["*.png", "!*.md"]

# When set, is the default file to show.
default_file = "README.md"

# Process ignores case insensitively
ignore_case_insensitive = false

Expand Down
1 change: 1 addition & 0 deletions docs/src/tests/book.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ path = "docs"
hidden = true
git_ignore = true
ignore = ["!**/*.png"]
default_file = "src/SUMMARY.md"
```

## Subchapter
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub struct Files {
#[serde(default)]
pub ignore: Vec<String>,

/// When specified, path to the file that is opened by default.
#[serde(default)]
pub default_file: Option<Utf8PathBuf>,

/// Process ignores case insensitively
#[serde(default)]
pub ignore_case_insensitive: bool,
Expand Down Expand Up @@ -241,7 +245,6 @@ impl<'a> Instance<'a> {
}

let list = root.render()?;
info!("{list:?}");
output.push_str(&list);
output.push_str("</div>");
Ok(output)
Expand Down Expand Up @@ -292,11 +295,15 @@ impl<'a> Instance<'a> {
events.append(&mut self.right(&paths)?);
events.push(Event::Html(CowStr::Boxed("</div>".to_string().into())));

let uuids: Vec<String> = paths.values().map(|uuid| uuid.to_string()).collect();
let uuids: Vec<Uuid> = paths.values().copied().collect();
let visible = match &self.data.default_file {
Some(file) => paths.get(&self.parent().join(file)).unwrap(),
None => &uuids[0],
};

let mut context = tera::Context::new();
context.insert("uuids", &uuids);
context.insert("visible", &uuids[0]);
context.insert("visible", visible);

let script = self.context.tera.render("script", &context)?;

Expand Down

0 comments on commit ca36cb2

Please sign in to comment.