Browse Source

Add year, month and day to page context with a date

index-subcmd
Vincent Prouillet 6 years ago
parent
commit
8e8cdfeb7f
6 changed files with 20 additions and 4 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -0
      Cargo.lock
  3. +1
    -0
      components/content/Cargo.toml
  4. +1
    -0
      components/content/src/lib.rs
  5. +12
    -2
      components/content/src/page.rs
  6. +4
    -2
      docs/content/documentation/templates/pages-sections.md

+ 1
- 0
CHANGELOG.md View File

@@ -10,6 +10,7 @@
- Co-located assets are now permalinks
- Words are now counted using unicode rather than whitespaces
- Aliases can now be pointing directly to specific HTML files
- Add `year`, `month` and `day` variables to pages with a date

## 0.3.4 (2018-06-22)



+ 1
- 0
Cargo.lock View File

@@ -210,6 +210,7 @@ dependencies = [
name = "content"
version = "0.1.0"
dependencies = [
"chrono 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"config 0.1.0",
"errors 0.1.0",
"front_matter 0.1.0",


+ 1
- 0
components/content/Cargo.toml View File

@@ -8,6 +8,7 @@ tera = "0.11"
serde = "1"
slug = "0.1"
rayon = "1"
chrono = "0.4"

errors = { path = "../errors" }
config = { path = "../config" }


+ 1
- 0
components/content/src/lib.rs View File

@@ -2,6 +2,7 @@ extern crate tera;
extern crate slug;
extern crate serde;
extern crate rayon;
extern crate chrono;

extern crate errors;
extern crate config;


+ 12
- 2
components/content/src/page.rs View File

@@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::result::Result as StdResult;

use chrono::Datelike;
use tera::{Tera, Context as TeraContext};
use serde::ser::{SerializeStruct, self};
use slug::slugify;
@@ -247,11 +247,21 @@ impl Default for Page {

impl ser::Serialize for Page {
fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error> where S: ser::Serializer {
let mut state = serializer.serialize_struct("page", 18)?;
let mut state = serializer.serialize_struct("page", 21)?;
state.serialize_field("content", &self.content)?;
state.serialize_field("title", &self.meta.title)?;
state.serialize_field("description", &self.meta.description)?;
state.serialize_field("date", &self.meta.date)?;
if let Some(chrono_datetime) = self.meta.date() {
let d = chrono_datetime.date();
state.serialize_field("year", &d.year())?;
state.serialize_field("month", &d.month())?;
state.serialize_field("day", &d.day())?;
} else {
state.serialize_field::<Option<usize>>("year", &None)?;
state.serialize_field::<Option<usize>>("month", &None)?;
state.serialize_field::<Option<usize>>("day", &None)?;
}
state.serialize_field("slug", &self.slug)?;
state.serialize_field("path", &self.path)?;
state.serialize_field("components", &self.components)?;


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

@@ -39,8 +39,10 @@ next: Page?;
toc: Array<Header>;
// Paths of colocated assets, relative to the content directory
assets: Array<String>;
// Paths of colocated image assets, ie. files with an extension of "jpg", "jpeg", "png", "gif", or "bmp"
images: Array<String>;
// Year/month/day is only set if the page has a date and month/day are 1-indexed
year: Number?;
month: Number?;
day: Number?;
```

## Section variables


Loading…
Cancel
Save