Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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 docs/features/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ The following links point to pages that do not exist:
### Limitations

* Only interal links within a Doctave project are checked
* Anchor tags are not verified
* Anchor tags are not verified
19 changes: 14 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,19 @@ impl Document {
&self.markdown.as_html
}

fn title(&self) -> &str {
self.frontmatter
.get("title")
.map(|t| t.as_ref())
.unwrap_or_else(|| self.path.file_stem().unwrap().to_str().unwrap())
fn title(&self) -> String {
if let Some(title) = self.frontmatter.get("title") {
return title.to_string();
}

capitalize(self.path.file_stem().unwrap().to_str().unwrap())
}
}

fn capitalize(s: &str) -> String {
let mut c = s.chars();
match c.next() {
None => String::new(),
Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
}
}
53 changes: 53 additions & 0 deletions src/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,59 @@ mod test {
)
}

#[test]
fn auto_title() {
let auto_titled_page = |path: &str, base_path: Option<&str>| -> Document {
let frontmatter = BTreeMap::new();

Document::new(
Path::new(path),
"Not important".to_string(),
frontmatter,
base_path.unwrap_or("/"),
)
};

let config = config(None);
let root = Directory {
path: config.docs_dir().to_path_buf(),
docs: vec![
page("README.md", "Getting Started", None),
auto_titled_page("one.md", None),
],
dirs: vec![Directory {
path: config.docs_dir().join("child"),
docs: vec![
page("child/README.md", "Nested Root", None),
auto_titled_page("child/three.md", None),
],
dirs: vec![],
}],
};

let navigation = Navigation::new(&config);

assert_eq!(
navigation.build_for(&root),
vec![
Link {
path: String::from("/child"),
title: String::from("Nested Root"),
children: vec![Link {
path: String::from("/child/three"),
title: String::from("Three"),
children: vec![]
}]
},
Link {
path: String::from("/one"),
title: String::from("One"),
children: vec![]
},
]
)
}

#[test]
fn sorting_alphanumerically() {
let config = config(None);
Expand Down
6 changes: 1 addition & 5 deletions src/site_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,7 @@ impl<'a, T: SiteBackend> SiteGenerator<'a, T> {
for doc in &root.docs {
index.add_doc(
&doc.id.to_string(),
&[
&doc.title(),
&doc.uri_path().as_str(),
doc.markdown_section(),
],
&[&doc.title(), &doc.uri_path(), doc.markdown_section()],
);
}
for dir in &root.dirs {
Expand Down