Browse Source

Add page and section components

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
791fbe685b
4 changed files with 29 additions and 4 deletions
  1. +1
    -1
      CHANGELOG.md
  2. +13
    -1
      components/content/src/page.rs
  3. +11
    -2
      components/content/src/section.rs
  4. +4
    -0
      docs/content/documentation/templates/pages-sections.md

+ 1
- 1
CHANGELOG.md View File

@@ -10,7 +10,7 @@
- Add Nim syntax highlighting - Add Nim syntax highlighting
- Allow static folder to be missing - Allow static folder to be missing
- Fix shortcodes args being only passed as strings - Fix shortcodes args being only passed as strings
- Add `page.components` and `section.components` that are equivalent to `path.split('/')`


## 0.2.1 (2017-10-17) ## 0.2.1 (2017-10-17)




+ 13
- 1
components/content/src/page.rs View File

@@ -36,6 +36,8 @@ pub struct Page {
pub slug: String, pub slug: String,
/// The URL path of the page /// The URL path of the page
pub path: String, pub path: String,
/// The components of the path of the page
pub components: Vec<String>,
/// The full URL for that page /// The full URL for that page
pub permalink: String, pub permalink: String,
/// The summary for the article, defaults to None /// The summary for the article, defaults to None
@@ -63,6 +65,7 @@ impl Page {
content: "".to_string(), content: "".to_string(),
slug: "".to_string(), slug: "".to_string(),
path: "".to_string(), path: "".to_string(),
components: vec![],
permalink: "".to_string(), permalink: "".to_string(),
summary: None, summary: None,
previous: None, previous: None,
@@ -112,6 +115,10 @@ impl Page {
page.path = format!("{}/", page.path); page.path = format!("{}/", page.path);
} }


page.components = page.path.split('/')
.map(|p| p.to_string())
.filter(|p| !p.is_empty())
.collect::<Vec<_>>();
page.permalink = config.make_permalink(&page.path); page.permalink = config.make_permalink(&page.path);


Ok(page) Ok(page)
@@ -184,6 +191,7 @@ impl Default for Page {
content: "".to_string(), content: "".to_string(),
slug: "".to_string(), slug: "".to_string(),
path: "".to_string(), path: "".to_string(),
components: vec![],
permalink: "".to_string(), permalink: "".to_string(),
summary: None, summary: None,
previous: None, previous: None,
@@ -195,13 +203,14 @@ impl Default for Page {


impl ser::Serialize for Page { impl ser::Serialize for Page {
fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error> where S: ser::Serializer { fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error> where S: ser::Serializer {
let mut state = serializer.serialize_struct("page", 16)?;
let mut state = serializer.serialize_struct("page", 17)?;
state.serialize_field("content", &self.content)?; state.serialize_field("content", &self.content)?;
state.serialize_field("title", &self.meta.title)?; state.serialize_field("title", &self.meta.title)?;
state.serialize_field("description", &self.meta.description)?; state.serialize_field("description", &self.meta.description)?;
state.serialize_field("date", &self.meta.date)?; state.serialize_field("date", &self.meta.date)?;
state.serialize_field("slug", &self.slug)?; state.serialize_field("slug", &self.slug)?;
state.serialize_field("path", &self.path)?; state.serialize_field("path", &self.path)?;
state.serialize_field("components", &self.components)?;
state.serialize_field("permalink", &self.permalink)?; state.serialize_field("permalink", &self.permalink)?;
state.serialize_field("summary", &self.summary)?; state.serialize_field("summary", &self.summary)?;
state.serialize_field("tags", &self.meta.tags)?; state.serialize_field("tags", &self.meta.tags)?;
@@ -265,6 +274,7 @@ Hello world"#;
assert!(res.is_ok()); assert!(res.is_ok());
let page = res.unwrap(); let page = res.unwrap();
assert_eq!(page.path, "posts/intro/hello-world/"); assert_eq!(page.path, "posts/intro/hello-world/");
assert_eq!(page.components, vec!["posts", "intro", "hello-world"]);
assert_eq!(page.permalink, "http://hello.com/posts/intro/hello-world/"); assert_eq!(page.permalink, "http://hello.com/posts/intro/hello-world/");
} }


@@ -280,6 +290,7 @@ Hello world"#;
assert!(res.is_ok()); assert!(res.is_ok());
let page = res.unwrap(); let page = res.unwrap();
assert_eq!(page.path, "hello-world/"); assert_eq!(page.path, "hello-world/");
assert_eq!(page.components, vec!["hello-world"]);
assert_eq!(page.permalink, config.make_permalink("hello-world")); assert_eq!(page.permalink, config.make_permalink("hello-world"));
} }


@@ -295,6 +306,7 @@ Hello world"#;
assert!(res.is_ok()); assert!(res.is_ok());
let page = res.unwrap(); let page = res.unwrap();
assert_eq!(page.path, "hello-world/"); assert_eq!(page.path, "hello-world/");
assert_eq!(page.components, vec!["hello-world"]);
assert_eq!(page.permalink, config.make_permalink("hello-world")); assert_eq!(page.permalink, config.make_permalink("hello-world"));
} }




+ 11
- 2
components/content/src/section.rs View File

@@ -25,6 +25,8 @@ pub struct Section {
pub meta: SectionFrontMatter, pub meta: SectionFrontMatter,
/// The URL path of the page /// The URL path of the page
pub path: String, pub path: String,
/// The components for the path of that page
pub components: Vec<String>,
/// The full URL for that page /// The full URL for that page
pub permalink: String, pub permalink: String,
/// The actual content of the page, in markdown /// The actual content of the page, in markdown
@@ -47,8 +49,9 @@ impl Section {


Section { Section {
file: FileInfo::new_section(file_path), file: FileInfo::new_section(file_path),
meta: meta,
meta,
path: "".to_string(), path: "".to_string(),
components: vec![],
permalink: "".to_string(), permalink: "".to_string(),
raw_content: "".to_string(), raw_content: "".to_string(),
content: "".to_string(), content: "".to_string(),
@@ -64,6 +67,10 @@ impl Section {
let mut section = Section::new(file_path, meta); let mut section = Section::new(file_path, meta);
section.raw_content = content.clone(); section.raw_content = content.clone();
section.path = format!("{}/", section.file.components.join("/")); section.path = format!("{}/", section.file.components.join("/"));
section.components = section.path.split('/')
.map(|p| p.to_string())
.filter(|p| !p.is_empty())
.collect::<Vec<_>>();
section.permalink = config.make_permalink(&section.path); section.permalink = config.make_permalink(&section.path);
Ok(section) Ok(section)
} }
@@ -140,13 +147,14 @@ impl Section {


impl ser::Serialize for Section { impl ser::Serialize for Section {
fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error> where S: ser::Serializer { fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error> where S: ser::Serializer {
let mut state = serializer.serialize_struct("section", 12)?;
let mut state = serializer.serialize_struct("section", 13)?;
state.serialize_field("content", &self.content)?; state.serialize_field("content", &self.content)?;
state.serialize_field("permalink", &self.permalink)?; state.serialize_field("permalink", &self.permalink)?;
state.serialize_field("title", &self.meta.title)?; state.serialize_field("title", &self.meta.title)?;
state.serialize_field("description", &self.meta.description)?; state.serialize_field("description", &self.meta.description)?;
state.serialize_field("extra", &self.meta.extra)?; state.serialize_field("extra", &self.meta.extra)?;
state.serialize_field("path", &self.path)?; state.serialize_field("path", &self.path)?;
state.serialize_field("components", &self.components)?;
state.serialize_field("permalink", &self.permalink)?; state.serialize_field("permalink", &self.permalink)?;
state.serialize_field("pages", &self.pages)?; state.serialize_field("pages", &self.pages)?;
state.serialize_field("subsections", &self.subsections)?; state.serialize_field("subsections", &self.subsections)?;
@@ -165,6 +173,7 @@ impl Default for Section {
file: FileInfo::default(), file: FileInfo::default(),
meta: SectionFrontMatter::default(), meta: SectionFrontMatter::default(),
path: "".to_string(), path: "".to_string(),
components: vec![],
permalink: "".to_string(), permalink: "".to_string(),
raw_content: "".to_string(), raw_content: "".to_string(),
content: "".to_string(), content: "".to_string(),


+ 4
- 0
docs/content/documentation/templates/pages-sections.md View File

@@ -20,6 +20,8 @@ description: String?;
date: String?; date: String?;
slug: String; slug: String;
path: String; path: String;
// the path, split on '/'
components: Array<String>;
permalink: String; permalink: String;
summary: String?; summary: String?;
tags: Array<String>; tags: Array<String>;
@@ -51,6 +53,8 @@ description: String?;
date: String?; date: String?;
slug: String; slug: String;
path: String; path: String;
// the path, split on '/'
components: Array<String>;
permalink: String; permalink: String;
extra: HashMap<String, Any>; extra: HashMap<String, Any>;
// Pages directly in this section, sorted if asked // Pages directly in this section, sorted if asked


Loading…
Cancel
Save