@@ -4,6 +4,9 @@ | |||||
- Fix RSS feed link and description | - Fix RSS feed link and description | ||||
- Renamed `Page::url` and `Section::url` to `Page::path` and `Section::path` | - Renamed `Page::url` and `Section::url` to `Page::path` and `Section::path` | ||||
- Pass `current_url` and `current_path` to every template | - 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) | ## 0.0.3 (2017-04-05) | ||||
- Add some colours in console | - Add some colours in console | ||||
@@ -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). | 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 | ### Shortcodes | ||||
Gutenberg uses markdown for content but sometimes you want to insert some HTML, for example for a YouTube video. | Gutenberg uses markdown for content but sometimes you want to insert some HTML, for example for a YouTube video. | ||||
@@ -264,3 +264,20 @@ fn test_can_build_site_with_tags() { | |||||
assert!(file_contains!(public, "sitemap.xml", "<loc>https://replace-this-with-your-url.com/tags</loc>")); | assert!(file_contains!(public, "sitemap.xml", "<loc>https://replace-this-with-your-url.com/tags</loc>")); | ||||
assert!(file_contains!(public, "sitemap.xml", "<loc>https://replace-this-with-your-url.com/tags/tag-with-space</loc>")); | assert!(file_contains!(public, "sitemap.xml", "<loc>https://replace-this-with-your-url.com/tags/tag-with-space</loc>")); | ||||
} | } | ||||
#[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", "<h1 id=\"title\"><a class=\"anchor\" href=\"#title\"")); | |||||
} |