Browse Source

Add a redirect_to parameter to section front matter

Close #103
index-subcmd
Vincent Prouillet 7 years ago
parent
commit
2beb0621ca
6 changed files with 29 additions and 1 deletions
  1. +5
    -1
      CHANGELOG.md
  2. +7
    -0
      README.md
  3. +6
    -0
      components/front_matter/src/section.rs
  4. +6
    -0
      components/site/src/lib.rs
  5. +1
    -0
      components/site/test_site/content/posts/tutorials/devops/_index.md
  6. +4
    -0
      components/site/tests/site.rs

+ 5
- 1
CHANGELOG.md View File

@@ -1,10 +1,14 @@
# Changelog

## 0.1.2 (unreleased)

- Add `redirect_to` to section front matter to redirect when landing on section
root page

## 0.1.1 (2017-07-16)

- Fix RSS feed not behaving (https://github.com/Keats/gutenberg/issues/101)


## 0.1.0 (2017-07-14)

- Parallelize all the things


+ 7
- 0
README.md View File

@@ -159,6 +159,13 @@ You can also paginate section, including the index by setting the `paginate_by`
This represents the number of pages for each pager of the paginator.
You will need to access pages through the `paginator` object. (TODO: document that).

You can redirect a root section page to another url by using the `redirect_to` parameter of the front-matter followed
by a path:

```
redirect_to = "docs/docker"
```

### Table of contents

Each page/section will generate a table of content based on the title. It is accessible through `section.toc` and


+ 6
- 0
components/front_matter/src/section.rs View File

@@ -38,6 +38,11 @@ pub struct SectionFrontMatter {
/// to be used directly, like a posts section in a personal site
#[serde(skip_serializing)]
pub render: Option<bool>,
/// Whether to redirect when landing on that section. Defaults to `None`.
/// Useful for the same reason as `render` but when you don't want a 404 when
/// landing on the root section page
#[serde(skip_serializing)]
pub redirect_to: Option<String>,
/// Any extra parameter present in the front matter
pub extra: Option<HashMap<String, Value>>,
}
@@ -96,6 +101,7 @@ impl Default for SectionFrontMatter {
paginate_by: None,
paginate_path: Some(DEFAULT_PAGINATE_PATH.to_string()),
render: Some(true),
redirect_to: None,
insert_anchor: Some(InsertAnchor::None),
extra: None,
}


+ 6
- 0
components/site/src/lib.rs View File

@@ -647,6 +647,12 @@ impl Site {
return Ok(());
}

if let Some(ref redirect_to) = section.meta.redirect_to {
let permalink = self.config.make_permalink(redirect_to);
create_file(&output_path.join("index.html"), &render_redirect_template(&permalink, &self.tera)?)?;
return Ok(());
}

if section.meta.is_paginated() {
self.render_paginated(&output_path, section)?;
} else {


+ 1
- 0
components/site/test_site/content/posts/tutorials/devops/_index.md View File

@@ -1,4 +1,5 @@
+++
title = "DevOps"
sort_by = "order"
redirect_to = "posts/tutorials/devops/docker"
+++

+ 4
- 0
components/site/tests/site.rs View File

@@ -122,6 +122,10 @@ fn can_build_site_without_live_reload() {
assert!(file_exists!(public, "an-old-url/old-page/index.html"));
assert!(file_contains!(public, "an-old-url/old-page/index.html", "something-else"));

// redirect_to works
assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
assert!(file_contains!(public, "posts/tutorials/devops/index.html", "docker"));

// No tags or categories
assert_eq!(file_exists!(public, "categories/index.html"), false);
assert_eq!(file_exists!(public, "tags/index.html"), false);


Loading…
Cancel
Save