diff --git a/CHANGELOG.md b/CHANGELOG.md index 178f897..5b3b7b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ - Fix RSS feed link and description - Renamed `Page::url` and `Section::url` to `Page::path` and `Section::path` - Pass `current_url` and `current_path` to every template +- Add id to headers to allow anchor linking +- Make relative link work with anchors +- Add option to render an anchor link automatically next to headers ## 0.0.3 (2017-04-05) - Add some colours in console diff --git a/README.md b/README.md index 61f793a..99f484e 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,11 @@ to link to. The path to the file starts from the `content` directory. For example, linking to a file located at `content/pages/about.md` would be `[my link](./pages/about.md). +### Anchors +Headers get an automatic id from their content in order to be able to add deep links. By default no links are actually created but +the `insert_anchor_links` option in `config.toml` can be set to `true` to link tags. The default template is very ugly and will need +CSS tweaks in your projet to look decent. The default template can also be easily overwritten by creating a `anchor-link.html` file in +the `templates` directory. ### Shortcodes Gutenberg uses markdown for content but sometimes you want to insert some HTML, for example for a YouTube video. diff --git a/tests/site.rs b/tests/site.rs index e4abc9a..cd2500d 100644 --- a/tests/site.rs +++ b/tests/site.rs @@ -264,3 +264,20 @@ fn test_can_build_site_with_tags() { assert!(file_contains!(public, "sitemap.xml", "https://replace-this-with-your-url.com/tags")); assert!(file_contains!(public, "sitemap.xml", "https://replace-this-with-your-url.com/tags/tag-with-space")); } + +#[test] +fn test_can_build_site_and_insert_anchor_links() { + let mut path = env::current_dir().unwrap().to_path_buf(); + path.push("test_site"); + let mut site = Site::new(&path, "config.toml").unwrap(); + site.config.insert_anchor_links = Some(true); + site.load().unwrap(); + let tmp_dir = TempDir::new("example").expect("create temp dir"); + let public = &tmp_dir.path().join("public"); + site.set_output_path(&public); + site.build().unwrap(); + + assert!(Path::new(&public).exists()); + // anchor link inserted + assert!(file_contains!(public, "posts/something-else/index.html", "