Skip to content

Commit

Permalink
Merge pull request #368 from Keats/next
Browse files Browse the repository at this point in the history
Next version
  • Loading branch information
Keats authored Sep 3, 2018
2 parents c422543 + a6adbab commit 014ce87
Show file tree
Hide file tree
Showing 45 changed files with 1,137 additions and 738 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@
[submodule "sublime_syntaxes/Sublime-CMakeLists"]
path = sublime_syntaxes/Sublime-CMakeLists
url = https://github.com/zyxar/Sublime-CMakeLists
[submodule "sublime_syntaxes/Swift-for-f-ing-sublime"]
path = sublime_syntaxes/Swift-for-f-ing-sublime
url = [email protected]:colinta/Swift-for-f-ing-sublime.git
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.4.2 (unreleased)

- Add assets to section indexes
- Allow users to add custom highlighting syntaxes
- Add Swift, MiniZinc syntaxes and update others
- Handle post summaries better: no more cutting references

## 0.4.1 (2018-08-06)

- Fix live reload of a section content change getting no pages data
Expand Down
957 changes: 471 additions & 486 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gutenberg"
version = "0.4.1"
version = "0.4.2"
authors = ["Vincent Prouillet <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ $ git submodule update --remote --merge
And finally from the root of the components/highlighting crate run the following command:

```bash
$ cargo run --example generate_sublime synpack ../../sublime_syntaxes ../../sublime_syntaxes/newlines.packdump ../../sublime_syntaxes/nonewlines.packdump
$ cargo run --example generate_sublime synpack ../../sublime_syntaxes ../../sublime_syntaxes/newlines.packdump
```

#### Adding a theme
Expand Down
68 changes: 49 additions & 19 deletions components/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,29 @@ extern crate serde_derive;
extern crate toml;
#[macro_use]
extern crate errors;
extern crate highlighting;
extern crate chrono;
extern crate globset;
extern crate highlighting;

use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
use std::path::{Path, PathBuf};

use toml::Value as Toml;
use chrono::Utc;
use globset::{Glob, GlobSet, GlobSetBuilder};
use toml::Value as Toml;

use errors::{Result, ResultExt};
use highlighting::THEME_SET;


mod theme;

use theme::Theme;

// We want a default base url for tests
static DEFAULT_BASE_URL: &'static str = "http://a-website.com";


#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct Taxonomy {
Expand Down Expand Up @@ -101,27 +99,29 @@ pub struct Config {
/// Had to remove the PartialEq derive because GlobSet does not implement it. No impact
/// because it's unused anyway (who wants to sort Configs?).
pub ignored_content: Vec<String>,
#[serde(skip_serializing, skip_deserializing)] // not a typo, 2 are needed
#[serde(skip_serializing, skip_deserializing)] // not a typo, 2 are needed
pub ignored_content_globset: Option<GlobSet>,

/// Whether to check all external links for validity
pub check_external_links: bool,

/// A list of directories to search for additional `.sublime-syntax` files in.
pub extra_syntaxes: Vec<String>,

/// All user params set in [extra] in the config
pub extra: HashMap<String, Toml>,

/// Set automatically when instantiating the config. Used for cachebusting
pub build_timestamp: Option<i64>,
}


impl Config {
/// Parses a string containing TOML to our Config struct
/// Any extra parameter will end up in the extra field
pub fn parse(content: &str) -> Result<Config> {
let mut config: Config = match toml::from_str(content) {
Ok(c) => c,
Err(e) => bail!(e)
Err(e) => bail!(e),
};

if config.base_url.is_empty() || config.base_url == DEFAULT_BASE_URL {
Expand All @@ -134,7 +134,6 @@ impl Config {

config.build_timestamp = Some(Utc::now().timestamp());


if !config.ignored_content.is_empty() {
// Convert the file glob strings into a compiled glob set matcher. We want to do this once,
// at program initialization, rather than for every page, for example. We arrange for the
Expand All @@ -145,11 +144,19 @@ impl Config {
for pat in &config.ignored_content {
let glob = match Glob::new(pat) {
Ok(g) => g,
Err(e) => bail!("Invalid ignored_content glob pattern: {}, error = {}", pat, e)
Err(e) => bail!(
"Invalid ignored_content glob pattern: {}, error = {}",
pat,
e
),
};
glob_set_builder.add(glob);
}
config.ignored_content_globset = Some(glob_set_builder.build().expect("Bad ignored_content in config file."));
config.ignored_content_globset = Some(
glob_set_builder
.build()
.expect("Bad ignored_content in config file."),
);
}

Ok(config)
Expand All @@ -161,15 +168,24 @@ impl Config {
let path = path.as_ref();
let file_name = path.file_name().unwrap();
File::open(path)
.chain_err(|| format!("No `{:?}` file found. Are you in the right directory?", file_name))?
.chain_err(|| {
format!(
"No `{:?}` file found. Are you in the right directory?",
file_name
)
})?
.read_to_string(&mut content)?;

Config::parse(&content)
}

/// 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('/') || path.is_empty() { "" } 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 == "/" {
Expand All @@ -195,12 +211,16 @@ impl Config {
let original = self.extra.clone();
// 2. inject theme extra values
for (key, val) in &theme.extra {
self.extra.entry(key.to_string()).or_insert_with(|| val.clone());
self.extra
.entry(key.to_string())
.or_insert_with(|| val.clone());
}

// 3. overwrite with original config
for (key, val) in &original {
self.extra.entry(key.to_string()).or_insert_with(|| val.clone());
self.extra
.entry(key.to_string())
.or_insert_with(|| val.clone());
}

Ok(())
Expand Down Expand Up @@ -233,13 +253,13 @@ impl Default for Config {
ignored_content: Vec::new(),
ignored_content_globset: None,
translations: HashMap::new(),
extra_syntaxes: Vec::new(),
extra: HashMap::new(),
build_timestamp: Some(1),
}
}
}


/// Get and parse the config.
/// If it doesn't succeed, exit
pub fn get_config(path: &Path, filename: &str) -> Config {
Expand All @@ -253,7 +273,6 @@ pub fn get_config(path: &Path, filename: &str) -> Config {
}
}


#[cfg(test)]
mod tests {
use super::{Config, Theme};
Expand Down Expand Up @@ -303,7 +322,16 @@ hello = "world"

let config = Config::parse(config);
assert!(config.is_ok());
assert_eq!(config.unwrap().extra.get("hello").unwrap().as_str().unwrap(), "world");
assert_eq!(
config
.unwrap()
.extra
.get("hello")
.unwrap()
.as_str()
.unwrap(),
"world"
);
}

#[test]
Expand All @@ -313,7 +341,6 @@ hello = "world"
assert_eq!(config.make_permalink(""), "http://vincent.is/");
}


#[test]
fn can_make_url_index_page_with_railing_slash_url() {
let mut config = Config::default();
Expand All @@ -339,7 +366,10 @@ hello = "world"
fn can_make_url_with_localhost() {
let mut config = Config::default();
config.base_url = "http://127.0.0.1:1111".to_string();
assert_eq!(config.make_permalink("/tags/rust"), "http://127.0.0.1:1111/tags/rust/");
assert_eq!(
config.make_permalink("/tags/rust"),
"http://127.0.0.1:1111/tags/rust/"
);
}

#[test]
Expand Down
36 changes: 17 additions & 19 deletions components/content/benches/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ extern crate front_matter;
extern crate config;

use std::collections::HashMap;
use std::path::Path;

use config::Config;
use tera::Tera;
use front_matter::{SortBy, InsertAnchor};
use content::{Page, sort_pages, populate_siblings};


fn create_pages(number: usize, sort_by: SortBy) -> Vec<Page> {
fn create_pages(number: usize) -> Vec<Page> {
let mut pages = vec![];
let config = Config::default();
let tera = Tera::default();
let mut tera = Tera::default();
tera.add_raw_template("shortcodes/youtube.html", "hello");
let permalinks = HashMap::new();

for i in 0..number {
let mut page = Page::default();
match sort_by {
SortBy::Weight => { page.meta.weight = Some(i); }
SortBy::Order => { page.meta.order = Some(i); }
_ => (),
};
page.meta.weight = Some(i);
page.raw_content = r#"
# Modus cognitius profanam ne duae virtutis mundi
Expand Down Expand Up @@ -98,7 +96,7 @@ if __name__ == "__main__":
gen_site("basic-blog", [""], 250, paginate=True)
```
"#.to_string();
page.render_markdown(&permalinks, &tera, &config, InsertAnchor::None).unwrap();
page.render_markdown(&permalinks, &tera, &config, &Path::new(""), InsertAnchor::None).unwrap();
pages.push(page);
}

Expand All @@ -111,34 +109,34 @@ if __name__ == "__main__":

#[bench]
fn bench_baseline_cloning(b: &mut test::Bencher) {
let pages = create_pages(250, SortBy::Order);
let pages = create_pages(250);
b.iter(|| pages.clone());
}

#[bench]
fn bench_sorting_none(b: &mut test::Bencher) {
let pages = create_pages(250, SortBy::Order);
b.iter(|| sort_pages(pages.clone(), SortBy::None));
let pages = create_pages(250);
b.iter(|| sort_pages(pages.clone(), SortBy::Weight));
}

#[bench]
fn bench_sorting_order(b: &mut test::Bencher) {
let pages = create_pages(250, SortBy::Order);
b.iter(|| sort_pages(pages.clone(), SortBy::Order));
let pages = create_pages(250);
b.iter(|| sort_pages(pages.clone(), SortBy::Weight));
}

#[bench]
fn bench_populate_siblings(b: &mut test::Bencher) {
let pages = create_pages(250, SortBy::Order);
let (sorted_pages, _) = sort_pages(pages, SortBy::Order);
b.iter(|| populate_siblings(&sorted_pages.clone()));
let pages = create_pages(250);
let (sorted_pages, _) = sort_pages(pages, SortBy::Weight);
b.iter(|| populate_siblings(&sorted_pages.clone(), SortBy::Weight));
}

#[bench]
fn bench_page_render_html(b: &mut test::Bencher) {
let pages = create_pages(10, SortBy::Order);
let (mut sorted_pages, _) = sort_pages(pages, SortBy::Order);
sorted_pages = populate_siblings(&sorted_pages);
let pages = create_pages(10);
let (mut sorted_pages, _) = sort_pages(pages, SortBy::Weight);
sorted_pages = populate_siblings(&sorted_pages, SortBy::Weight);

let config = Config::default();
let mut tera = Tera::default();
Expand Down
Loading

0 comments on commit 014ce87

Please sign in to comment.