Skip to content

Commit b396a1b

Browse files
committed
Add --drafts flag + rustfmt
1 parent 57691be commit b396a1b

File tree

20 files changed

+141
-72
lines changed

20 files changed

+141
-72
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Breaking
66

7-
- Pages with draft=true are now only loaded/rendered in `zola serve`
7+
- Add `--drafts` flag to `build`, `serve` and `check` to load drafts. Drafts are never loaded by default anymore
88

99
### Other
1010
- Add `--open` flag to open server URL in default browser
@@ -17,7 +17,7 @@
1717
- Taxonomies can now have the same name in multiple languages
1818
- `zola init` can now be create sites inside the current directory
1919
- Fix table of contents generation for deep heading levels
20-
- Add `lang` in all templates context except sitemap, robots etc
20+
- Add `lang` in all templates context except sitemap, robots
2121
- Add `lang` parameter to `get_taxonomy` and `get_taxonomy_url`
2222
- Rebuild whole site on changes in `themes` changes
2323
- Add one-dark syntax highlighting theme

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/config/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use theme::Theme;
1313
use utils::fs::read_file_with_error;
1414

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

1818
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1919
pub enum Mode {

components/front_matter/src/page.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct PageFrontMatter {
2424
/// The converted date into a (year, month, day) tuple
2525
#[serde(default, skip_deserializing)]
2626
pub datetime_tuple: Option<(i32, u32, u32)>,
27-
/// Whether this page is a draft and should be ignored for pagination etc
27+
/// Whether this page is a draft
2828
pub draft: bool,
2929
/// The page slug. Will be used instead of the filename if present
3030
/// Can't be an empty string if present

components/front_matter/src/section.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use errors::Result;
77

88
use super::{InsertAnchor, SortBy};
99

10-
static DEFAULT_PAGINATE_PATH: &'static str = "page";
10+
static DEFAULT_PAGINATE_PATH: &str = "page";
1111

1212
/// The front matter of every section
1313
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

components/imageproc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use regex::Regex;
2323
use errors::{Error, Result};
2424
use utils::fs as ufs;
2525

26-
static RESIZED_SUBDIR: &'static str = "processed_images";
26+
static RESIZED_SUBDIR: &str = "processed_images";
2727

2828
lazy_static! {
2929
pub static ref RESIZED_FILENAME: Regex =

components/library/src/pagination/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ impl<'a> Paginator<'a> {
117117

118118
for key in self.all_pages {
119119
let page = library.get_page_by_key(*key);
120-
if page.is_draft() {
121-
continue;
122-
}
123120
current_page.push(page.to_serialized_basic(library));
124121

125122
if current_page.len() == self.paginate_by {
@@ -283,7 +280,7 @@ mod tests {
283280
assert_eq!(paginator.pagers[0].path, "posts/");
284281

285282
assert_eq!(paginator.pagers[1].index, 2);
286-
assert_eq!(paginator.pagers[1].pages.len(), 1);
283+
assert_eq!(paginator.pagers[1].pages.len(), 2);
287284
assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/posts/page/2/");
288285
assert_eq!(paginator.pagers[1].path, "posts/page/2/");
289286
}
@@ -300,7 +297,7 @@ mod tests {
300297
assert_eq!(paginator.pagers[0].path, "");
301298

302299
assert_eq!(paginator.pagers[1].index, 2);
303-
assert_eq!(paginator.pagers[1].pages.len(), 1);
300+
assert_eq!(paginator.pagers[1].pages.len(), 2);
304301
assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/page/2/");
305302
assert_eq!(paginator.pagers[1].path, "page/2/");
306303
}
@@ -352,7 +349,7 @@ mod tests {
352349
assert_eq!(paginator.pagers[0].path, "tags/something");
353350

354351
assert_eq!(paginator.pagers[1].index, 2);
355-
assert_eq!(paginator.pagers[1].pages.len(), 1);
352+
assert_eq!(paginator.pagers[1].pages.len(), 2);
356353
assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/tags/something/page/2/");
357354
assert_eq!(paginator.pagers[1].path, "tags/something/page/2/");
358355
}

components/rendering/src/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
317317
}
318318

319319
if let Some(e) = error {
320-
return Err(e);
320+
Err(e)
321321
} else {
322322
Ok(Rendered {
323323
summary_len: if has_summary { html.find(CONTINUE_READING) } else { None },

components/rendering/src/table_of_contents.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ fn insert_into_parent(potential_parent: Option<&mut Header>, header: &Header) ->
3333
match potential_parent {
3434
None => {
3535
// No potential parent to insert into so it needs to be insert higher
36-
return false;
37-
},
36+
false
37+
}
3838
Some(parent) => {
3939
let diff = header.level - parent.level;
4040
if diff <= 0 {
4141
// Heading is same level or higher so we don't insert here
4242
return false;
43-
}
43+
}
4444
if diff == 1 {
4545
// We have a direct child of the parent
4646
parent.children.push(header.clone());
@@ -51,7 +51,7 @@ fn insert_into_parent(potential_parent: Option<&mut Header>, header: &Header) ->
5151
// No, we need to insert it here
5252
parent.children.push(header.clone());
5353
}
54-
return true;
54+
true
5555
}
5656
}
5757
}
@@ -61,23 +61,9 @@ fn insert_into_parent(potential_parent: Option<&mut Header>, header: &Header) ->
6161
pub fn make_table_of_contents(headers: Vec<Header>) -> Vec<Header> {
6262
let mut toc = vec![];
6363
for header in headers {
64-
if toc.is_empty() {
65-
// First header, nothing to compare it with
64+
// First header or we try to insert the current header in a previous one
65+
if toc.is_empty() || !insert_into_parent(toc.iter_mut().last(), &header) {
6666
toc.push(header);
67-
continue;
68-
}
69-
70-
// We try to insert the current header in a previous one
71-
match insert_into_parent(toc.iter_mut().last(), &header) {
72-
true => {
73-
// Header was successfully inserted as a child of a previous element
74-
continue;
75-
},
76-
false => {
77-
// Couldn't insert in a previous header, so it's a top-level header
78-
toc.push(header);
79-
continue;
80-
}
8167
}
8268
}
8369

components/site/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub struct Site {
6363
pub permalinks: HashMap<String, String>,
6464
/// Contains all pages and sections of the site
6565
pub library: Arc<RwLock<Library>>,
66+
/// Whether to load draft pages
67+
include_drafts: bool,
6668
}
6769

6870
impl Site {
@@ -131,13 +133,20 @@ impl Site {
131133
static_path,
132134
taxonomies: Vec::new(),
133135
permalinks: HashMap::new(),
136+
include_drafts: false,
134137
// We will allocate it properly later on
135138
library: Arc::new(RwLock::new(Library::new(0, 0, false))),
136139
};
137140

138141
Ok(site)
139142
}
140143

144+
/// Set the site to load the drafts.
145+
/// Needs to be called before loading it
146+
pub fn include_drafts(&mut self) {
147+
self.include_drafts = true;
148+
}
149+
141150
/// The index sections are ALWAYS at those paths
142151
/// There are one index section for the basic language + 1 per language
143152
fn index_section_paths(&self) -> Vec<(PathBuf, Option<String>)> {
@@ -233,8 +242,8 @@ impl Site {
233242
let mut pages_insert_anchors = HashMap::new();
234243
for page in pages {
235244
let p = page?;
236-
// Draft pages are not rendered in zola build so we just discard them
237-
if p.meta.draft && !self.config.is_in_serve_mode() {
245+
// Should draft pages be ignored?
246+
if p.meta.draft && !self.include_drafts {
238247
continue;
239248
}
240249
pages_insert_anchors.insert(
@@ -525,7 +534,7 @@ impl Site {
525534
self.tera.register_function("trans", global_fns::Trans::new(self.config.clone()));
526535
self.tera.register_function(
527536
"get_taxonomy_url",
528-
global_fns::GetTaxonomyUrl::new(&self.config.default_language,&self.taxonomies),
537+
global_fns::GetTaxonomyUrl::new(&self.config.default_language, &self.taxonomies),
529538
);
530539
}
531540

@@ -540,7 +549,11 @@ impl Site {
540549
);
541550
self.tera.register_function(
542551
"get_taxonomy",
543-
global_fns::GetTaxonomy::new(&self.config.default_language, self.taxonomies.clone(), self.library.clone()),
552+
global_fns::GetTaxonomy::new(
553+
&self.config.default_language,
554+
self.taxonomies.clone(),
555+
self.library.clone(),
556+
),
544557
);
545558
}
546559

0 commit comments

Comments
 (0)