Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optional table of contents #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.

11 changes: 11 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ navigation:
children: "*"
```


### table of contents

Tells Doctave to show or not the table of contents in the right side of the main content.

This is an optional setting.

```yaml
table_contents: true
```

## All commands

All commands support the following option.
Expand Down
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct DoctaveYaml {
navigation: Option<Vec<Navigation>>,
base_path: Option<String>,
docs_dir: Option<String>,
table_contents: Option<bool>,
}

impl DoctaveYaml {
Expand Down Expand Up @@ -257,6 +258,7 @@ pub struct Config {
navigation: Option<Vec<NavRule>>,
port: u32,
build_mode: BuildMode,
table_contents: bool,
}

impl Config {
Expand Down Expand Up @@ -295,6 +297,7 @@ impl Config {
navigation: doctave_yaml.navigation.map(|n| NavRule::from_yaml_input(n)),
port: doctave_yaml.port.unwrap_or_else(|| 4001),
build_mode: BuildMode::Dev,
table_contents: doctave_yaml.table_contents.unwrap_or(true),
};

Ok(config)
Expand Down Expand Up @@ -381,6 +384,10 @@ impl Config {
pub fn logo(&self) -> Option<&str> {
self.logo.as_deref()
}

pub fn table_contents_enabled(&self) -> bool {
self.table_contents
}
}

pub fn project_root() -> Option<PathBuf> {
Expand Down
2 changes: 2 additions & 0 deletions src/site_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ impl<'a, T: SiteBackend> SiteGenerator<'a, T> {
timestamp: &self.timestamp,
page_title,
head_include,
table_contents: self.config.table_contents_enabled(),
};

let mut out = Vec::new();
Expand Down Expand Up @@ -338,4 +339,5 @@ pub struct TemplateData<'a> {
pub project_title: String,
pub build_mode: String,
pub timestamp: &'a str,
pub table_contents: bool,
}
4 changes: 3 additions & 1 deletion templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ <h2 class='project-name'>
{{{ content }}}
</div>
<div class='sidebar-right'>
{{#if table_contents }}
<div class='page-nav' id='page-nav'>
<p class='page-nav-header'>On this page</p>
<ul>
Expand All @@ -83,6 +84,7 @@ <h2 class='project-name'>
{{/each}}
</ul>
</div>
{{/if}}
</div>
<div class='wave-container'>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320">
Expand Down Expand Up @@ -129,4 +131,4 @@ <h2 class='project-name'>
{{/if}}
</body>

</html>
</html>
24 changes: 24 additions & 0 deletions tests/build_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,30 @@ integration_test!(page_nav, |area| {
area.assert_contains(&index, " <a href='#end'>End</a>");
});

integration_test!(no_table_contents, |area| {
area.mkdir(Path::new("docs"));
area.write_file(
Path::new("doctave.yaml"),
indoc! {"
---
title: Custom colors
table_contents: false
"}
.as_bytes(),
);

area.write_file(
Path::new("docs").join("README.md"),
b"# Hi\n## Foo\n### Bar",
);

let result = area.cmd(&["build"]);
assert_success(&result);

let index = Path::new("site").join("index.html");
area.refute_contains(&index, "On this page");
});

integration_test!(missing_directory_index, |area| {
area.create_config();
area.mkdir(Path::new("docs").join("nested"));
Expand Down