Browse Source

Create a content mod

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
07f11755d6
9 changed files with 29 additions and 27 deletions
  1. +4
    -4
      src/config.rs
  2. +10
    -0
      src/content/mod.rs
  3. +8
    -9
      src/content/page.rs
  4. +2
    -4
      src/content/pagination.rs
  5. +1
    -1
      src/content/section.rs
  6. +0
    -0
      src/content/utils.rs
  7. +2
    -5
      src/lib.rs
  8. +1
    -3
      src/site.rs
  9. +1
    -1
      src/templates/global_fns.rs

+ 4
- 4
src/config.rs View File

@@ -134,7 +134,7 @@ mod tests {
use super::{Config};

#[test]
fn test_can_import_valid_config() {
fn can_import_valid_config() {
let config = r#"
title = "My site"
base_url = "https://replace-this-with-your-url.com"
@@ -145,7 +145,7 @@ base_url = "https://replace-this-with-your-url.com"
}

#[test]
fn test_errors_when_invalid_type() {
fn errors_when_invalid_type() {
let config = r#"
title = 1
base_url = "https://replace-this-with-your-url.com"
@@ -156,7 +156,7 @@ base_url = "https://replace-this-with-your-url.com"
}

#[test]
fn test_errors_when_missing_required_field() {
fn errors_when_missing_required_field() {
// base_url is required
let config = r#"
title = ""
@@ -167,7 +167,7 @@ title = ""
}

#[test]
fn test_can_add_extra_values() {
fn can_add_extra_values() {
let config = r#"
title = "My site"
base_url = "https://replace-this-with-your-url.com"


+ 10
- 0
src/content/mod.rs View File

@@ -0,0 +1,10 @@
// TODO: move section/page and maybe pagination in this mod
// Not sure where pagination stands if I add a render mod

mod page;
mod pagination;
mod section;

pub use self::page::{Page, sort_pages, populate_previous_and_next_pages};
pub use self::section::{Section};
pub use self::pagination::{Paginator, Pager};

src/page.rs → src/content/page.rs View File

@@ -16,7 +16,6 @@ use markdown::markdown_to_html;
use utils::{read_file, find_content_components};



/// Looks into the current folder for the path and see if there's anything that is not a .md
/// file. Those will be copied next to the rendered .html file
fn find_related_assets(path: &Path) -> Vec<PathBuf> {
@@ -329,10 +328,10 @@ pub fn populate_previous_and_next_pages(input: &[Page]) -> Vec<Page> {

#[cfg(test)]
mod tests {
use tempdir::TempDir;

use std::fs::File;

use tempdir::TempDir;

use front_matter::{PageFrontMatter, SortBy};
use super::{Page, find_related_assets, sort_pages, populate_previous_and_next_pages};

@@ -349,7 +348,7 @@ mod tests {
}

#[test]
fn test_find_related_assets() {
fn can_find_related_assets() {
let tmp_dir = TempDir::new("example").expect("create temp dir");
File::create(tmp_dir.path().join("index.md")).unwrap();
File::create(tmp_dir.path().join("example.js")).unwrap();
@@ -365,7 +364,7 @@ mod tests {
}

#[test]
fn test_can_sort_dates() {
fn can_sort_by_dates() {
let input = vec![
create_page_with_date("2018-01-01"),
create_page_with_date("2017-01-01"),
@@ -379,7 +378,7 @@ mod tests {
}

#[test]
fn test_can_sort_order() {
fn can_sort_by_order() {
let input = vec![
create_page_with_order(2),
create_page_with_order(3),
@@ -393,7 +392,7 @@ mod tests {
}

#[test]
fn test_can_sort_none() {
fn can_sort_by_none() {
let input = vec![
create_page_with_order(2),
create_page_with_order(3),
@@ -407,7 +406,7 @@ mod tests {
}

#[test]
fn test_ignore_page_with_missing_field() {
fn ignore_page_with_missing_field() {
let input = vec![
create_page_with_order(2),
create_page_with_order(3),
@@ -419,7 +418,7 @@ mod tests {
}

#[test]
fn test_populate_previous_and_next_pages() {
fn can_populate_previous_and_next_pages() {
let input = vec![
create_page_with_order(3),
create_page_with_order(2),

src/pagination.rs → src/content/pagination.rs View File

@@ -2,8 +2,7 @@ use std::collections::HashMap;
use tera::{Context, to_value, Value};

use errors::{Result, ResultExt};
use page::Page;
use section::Section;
use content::{Page, Section};
use site::Site;


@@ -155,8 +154,7 @@ mod tests {
use tera::{to_value};

use front_matter::SectionFrontMatter;
use page::Page;
use section::Section;
use content::{Page, Section};

use super::{Paginator};


src/section.rs → src/content/section.rs View File

@@ -10,7 +10,7 @@ use front_matter::{SectionFrontMatter, split_section_content};
use errors::{Result, ResultExt};
use utils::{read_file, find_content_components};
use markdown::markdown_to_html;
use page::{Page};
use content::Page;


#[derive(Clone, Debug, PartialEq)]

+ 0
- 0
src/content/utils.rs View File


+ 2
- 5
src/lib.rs View File

@@ -22,19 +22,16 @@ extern crate tempdir;
mod utils;
mod config;
pub mod errors;
mod page;
mod front_matter;
mod content;
mod site;
mod markdown;
mod section;
mod pagination;
// Filters, Global Fns and default instance of Tera
mod templates;

pub use site::{Site};
pub use config::{Config, get_config};
pub use front_matter::{PageFrontMatter, SectionFrontMatter, split_page_content, split_section_content, SortBy};
pub use page::{Page, populate_previous_and_next_pages};
pub use section::{Section};
pub use content::{Page, Section, sort_pages};
pub use utils::{create_file};
pub use markdown::markdown_to_html;

+ 1
- 3
src/site.rs View File

@@ -10,10 +10,8 @@ use walkdir::WalkDir;

use errors::{Result, ResultExt};
use config::{Config, get_config};
use page::{Page, populate_previous_and_next_pages, sort_pages};
use pagination::Paginator;
use utils::{create_file, create_directory};
use section::{Section};
use content::{Page, Section, Paginator, populate_previous_and_next_pages, sort_pages};
use front_matter::{SortBy};
use templates::{GUTENBERG_TERA, global_fns, render_redirect_template};



+ 1
- 1
src/templates/global_fns.rs View File

@@ -3,7 +3,7 @@ use std::path::{PathBuf};

use tera::{GlobalFn, Value, from_value, to_value, Result};

use page::Page;
use content::Page;


pub fn make_get_page(all_pages: &HashMap<PathBuf, Page>) -> GlobalFn {


Loading…
Cancel
Save