Browse Source

Fix some index related bugs

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
404240ef82
4 changed files with 24 additions and 6 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +16
    -1
      components/config/src/lib.rs
  3. +6
    -2
      components/site/src/lib.rs
  4. +0
    -3
      components/site/test_site/content/_index.md

+ 2
- 0
CHANGELOG.md View File

@@ -4,6 +4,8 @@

- Fix shortcodes without arguments being ignored
- Fix shortcodes with markdown chars (_, *, etc) in name and args being ignored
- Fix subsections of index not being filled without a `_index.md`
- Fix permalink generation for index page


## 0.2.1 (2017-10-17)


+ 16
- 1
components/config/src/lib.rs View File

@@ -108,7 +108,7 @@ impl Config {

/// Makes a url, taking into account that the base url might have a trailing slash
pub fn make_permalink(&self, path: &str) -> String {
let trailing_bit = if path.ends_with('/') { "" } else { "/" };
let trailing_bit = if path.ends_with('/') || path.is_empty() { "" } else { "/" };

// Index section with a base url that has a trailing slash
if self.base_url.ends_with('/') && path == "/" {
@@ -243,6 +243,21 @@ hello = "world"
assert_eq!(config.unwrap().extra.unwrap().get("hello").unwrap().as_str().unwrap(), "world");
}

#[test]
fn can_make_url_index_page_with_non_trailing_slash_url() {
let mut config = Config::default();
config.base_url = "http://vincent.is".to_string();
assert_eq!(config.make_permalink(""), "http://vincent.is/");
}


#[test]
fn can_make_url_index_page_with_railing_slash_url() {
let mut config = Config::default();
config.base_url = "http://vincent.is/".to_string();
assert_eq!(config.make_permalink(""), "http://vincent.is/");
}

#[test]
fn can_make_url_with_non_trailing_slash_base_url() {
let mut config = Config::default();


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

@@ -207,7 +207,7 @@ impl Site {
if !self.sections.contains_key(&index_path) {
let mut index_section = Section::default();
index_section.permalink = self.config.make_permalink("");
// TODO: need to insert into permalinks too
index_section.file.parent = self.base_path.join("content");
self.sections.insert(index_path, index_section);
}

@@ -736,8 +736,12 @@ impl Site {
Ok(())
}

/// Used only on reload
pub fn render_index(&self) -> Result<()> {
self.render_section(&self.sections[&self.base_path.join("content").join("_index.md")], false)
self.render_section(
&self.sections[&self.base_path.join("content").join("_index.md")],
false
)
}

/// Renders all sections


+ 0
- 3
components/site/test_site/content/_index.md View File

@@ -1,3 +0,0 @@
+++
title = "Index"
+++

Loading…
Cancel
Save