diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b453ed..6d90361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,16 @@ # Changelog -## 0.8.1 (unreleased) +## 0.9.0 (unreleased) +### Breaking + +- Pages with draft=true are now only loaded/rendered in `zola serve` + +### Other - Add `--open` flag to open server URL in default browser - Fix sitemaps namespace - Update livereload - Add `hard_link_static` config option to hard link things in the static directory instead of copying -- Pages with draft=true are not longer rendered in `zola build` - Add warning for old style internal links since they would still function silently - Add some counts to `zola check` diff --git a/Cargo.lock b/Cargo.lock index 4e0ef68..1a49892 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3202,7 +3202,7 @@ dependencies = [ [[package]] name = "zola" -version = "0.8.1" +version = "0.9.0" dependencies = [ "actix-files 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "actix-web 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 1b1f9ba..871ae75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zola" -version = "0.8.1" +version = "0.9.0" authors = ["Vincent Prouillet "] license = "MIT" readme = "README.md" diff --git a/components/library/src/library.rs b/components/library/src/library.rs index 9cd7555..e29f1b8 100644 --- a/components/library/src/library.rs +++ b/components/library/src/library.rs @@ -236,18 +236,7 @@ impl Library { for (key, (sorted, cannot_be_sorted, sort_by)) in updates { // Find sibling between sorted pages first - let with_siblings = find_siblings( - sorted - .iter() - .map(|k| { - if let Some(page) = self.pages.get(*k) { - (k, page.is_draft()) - } else { - unreachable!("Sorting got an unknown page") - } - }) - .collect(), - ); + let with_siblings = find_siblings(&sorted); for (k2, val1, val2) in with_siblings { if let Some(page) = self.pages.get_mut(k2) { diff --git a/components/library/src/sorting.rs b/components/library/src/sorting.rs index bd8b98a..2df1ade 100644 --- a/components/library/src/sorting.rs +++ b/components/library/src/sorting.rs @@ -57,53 +57,21 @@ pub fn sort_pages_by_weight(pages: Vec<(&Key, Option, &str)>) -> (Vec) -> Vec<(Key, Option, Option)> { +pub fn find_siblings(sorted: &[Key]) -> Vec<(Key, Option, Option)> { let mut res = Vec::with_capacity(sorted.len()); let length = sorted.len(); - for (i, (key, is_draft)) in sorted.iter().enumerate() { - if *is_draft { - res.push((**key, None, None)); - continue; - } - let mut with_siblings = (**key, None, None); + for (i, key) in sorted.iter().enumerate() { + let mut with_siblings = (*key, None, None); if i > 0 { - let mut j = i; - loop { - if j == 0 { - break; - } - - j -= 1; - - if sorted[j].1 { - continue; - } - // lighter / later - with_siblings.1 = Some(*sorted[j].0); - break; - } + // lighter / later + with_siblings.1 = Some(sorted[i - 1]); } if i < length - 1 { - let mut j = i; - loop { - if j == length - 1 { - break; - } - - j += 1; - - if sorted[j].1 { - continue; - } - - // heavier/earlier - with_siblings.2 = Some(*sorted[j].0); - break; - } + // heavier/earlier + with_siblings.2 = Some(sorted[i + 1]); } res.push(with_siblings); } @@ -208,10 +176,9 @@ mod tests { let page3 = create_page_with_weight(3); let key3 = dense.insert(page3.clone()); - let input = - vec![(&key1, page1.is_draft()), (&key2, page2.is_draft()), (&key3, page3.is_draft())]; + let input = vec![key1, key2, key3]; - let pages = find_siblings(input); + let pages = find_siblings(&input); assert_eq!(pages[0].1, None); assert_eq!(pages[0].2, Some(key2)); diff --git a/components/rendering/tests/markdown.rs b/components/rendering/tests/markdown.rs index 37ec910..9c1e2d5 100644 --- a/components/rendering/tests/markdown.rs +++ b/components/rendering/tests/markdown.rs @@ -820,7 +820,6 @@ fn doesnt_try_to_highlight_content_from_shortcode() { // assert_eq!(res.body, expected); //} - // https://github.com/getzola/zola/issues/747 #[test] fn leaves_custom_url_scheme_untouched() { diff --git a/components/search/src/lib.rs b/components/search/src/lib.rs index be935ec..846e42e 100644 --- a/components/search/src/lib.rs +++ b/components/search/src/lib.rs @@ -72,7 +72,7 @@ fn add_section_to_index(index: &mut Index, section: &Section, library: &Library) for key in §ion.pages { let page = library.get_page_by_key(*key); - if !page.meta.in_search_index || page.meta.draft { + if !page.meta.in_search_index { continue; } diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 65011a3..3a0829a 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -230,7 +230,7 @@ impl Site { for page in pages { let p = page?; // Draft pages are not rendered in zola build so we just discard them - if p.meta.draft && self.config.is_in_build_mode() { + if p.meta.draft && !self.config.is_in_serve_mode() { continue; } pages_insert_anchors.insert( @@ -323,7 +323,11 @@ impl Site { .collect(); if self.config.is_in_check_mode() { - println!("> Checked {} internal link(s) with an anchor: {} error(s) found.", all_links.len(), errors.len()); + println!( + "> Checked {} internal link(s) with an anchor: {} error(s) found.", + all_links.len(), + errors.len() + ); } if errors.is_empty() { @@ -392,7 +396,11 @@ impl Site { .collect() }); - println!("> Checked {} external link(s): {} error(s) found.", all_links.len(), errors.len()); + println!( + "> Checked {} external link(s): {} error(s) found.", + all_links.len(), + errors.len() + ); if errors.is_empty() { return Ok(()); @@ -624,7 +632,7 @@ impl Site { copy_directory( &self.base_path.join("themes").join(theme).join("static"), &self.output_path, - false + false, )?; } // We're fine with missing static folders @@ -901,7 +909,7 @@ impl Site { ) } - /// Renders all taxonomies with at least one non-draft post + /// Renders all taxonomies pub fn render_taxonomies(&self) -> Result<()> { for taxonomy in &self.taxonomies { self.render_taxonomy(taxonomy)?; @@ -1018,10 +1026,7 @@ impl Site { ensure_directory_exists(&self.output_path)?; let mut context = Context::new(); - let mut pages = all_pages - .into_iter() - .filter(|p| p.meta.date.is_some() && !p.is_draft()) - .collect::>(); + let mut pages = all_pages.into_iter().filter(|p| p.meta.date.is_some()).collect::>(); // Don't generate a RSS feed if none of the pages has a date if pages.is_empty() { diff --git a/components/site/src/sitemap.rs b/components/site/src/sitemap.rs index 505c30a..72152f7 100644 --- a/components/site/src/sitemap.rs +++ b/components/site/src/sitemap.rs @@ -62,7 +62,6 @@ pub fn find_entries<'a>( let pages = library .pages_values() .iter() - .filter(|p| !p.is_draft()) .map(|p| { let date = match p.meta.date { Some(ref d) => Some(d.to_string()), diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index 7435146..bb5f8d4 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -42,7 +42,7 @@ fn can_parse_site() { let posts_section = library.get_section(&posts_path.join("_index.md")).unwrap(); assert_eq!(posts_section.subsections.len(), 2); - assert_eq!(posts_section.pages.len(), 9); // 10 with 1 draft == 9 + assert_eq!(posts_section.pages.len(), 9); // 10 with 1 draft == 9 assert_eq!( posts_section.ancestors, vec![*library.get_section_key(&index_section.file.path).unwrap()] diff --git a/docs/content/documentation/content/page.md b/docs/content/documentation/content/page.md index c1ab276..87a4a19 100644 --- a/docs/content/documentation/content/page.md +++ b/docs/content/documentation/content/page.md @@ -55,7 +55,7 @@ date = # will not be rendered. weight = 0 -# A draft page will not be present in prev/next pagination +# A draft page is only rendered in `zola serve`, they are ignored in `zola build` and `zola check` draft = false # If filled, it will use that slug instead of the filename to make up the URL diff --git a/docs/content/documentation/content/taxonomies.md b/docs/content/documentation/content/taxonomies.md index 8b79cf0..606abcf 100644 --- a/docs/content/documentation/content/taxonomies.md +++ b/docs/content/documentation/content/taxonomies.md @@ -28,8 +28,7 @@ categories = ["programming"] +++ ``` -The taxonomy pages will only be created if at least one non-draft page is found and -are available at the following paths: +The taxonomy pages are available at the following paths: ```plain $BASE_URL/$NAME/ diff --git a/docs/content/documentation/templates/rss.md b/docs/content/documentation/templates/rss.md index 6212f79..8d1513c 100644 --- a/docs/content/documentation/templates/rss.md +++ b/docs/content/documentation/templates/rss.md @@ -8,7 +8,7 @@ generate an `rss.xml` page for the site, which will live at `base_url/rss.xml`. generate the `rss.xml` page, Zola will look for a `rss.xml` file in the `templates` directory or, if one does not exist, will use the use the built-in rss template. -**Only pages with a date and that are not draft will be available.** +**Only pages with a date will be available.** The RSS template gets two variables in addition of the config: diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index f49eca9..9768547 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -62,7 +62,7 @@ struct ErrorFilePaths { } fn not_found( - res: dev::ServiceResponse + res: dev::ServiceResponse, ) -> std::result::Result, actix_web::Error> { let buf: Vec = { let error_files: &ErrorFilePaths = res.request().app_data().unwrap(); @@ -74,15 +74,10 @@ fn not_found( }; let new_resp = HttpResponse::build(http::StatusCode::NOT_FOUND) - .header( - http::header::CONTENT_TYPE, - http::header::HeaderValue::from_static("text/html"), - ) + .header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static("text/html")) .body(buf); - Ok(ErrorHandlerResponse::Response( - res.into_response(new_resp.into_body()), - )) + Ok(ErrorHandlerResponse::Response(res.into_response(new_resp.into_body()))) } fn livereload_handler() -> HttpResponse { @@ -192,23 +187,15 @@ pub fn serve( let broadcaster = if !watch_only { thread::spawn(move || { let s = HttpServer::new(move || { - let error_handlers = ErrorHandlers::new() - .handler(http::StatusCode::NOT_FOUND, not_found); + let error_handlers = + ErrorHandlers::new().handler(http::StatusCode::NOT_FOUND, not_found); App::new() - .data(ErrorFilePaths { - not_found: static_root.join("404.html"), - }) + .data(ErrorFilePaths { not_found: static_root.join("404.html") }) .wrap(error_handlers) - .route( - "/livereload.js", - web::get().to(livereload_handler) - ) + .route("/livereload.js", web::get().to(livereload_handler)) // Start a webserver that serves the `output_dir` directory - .service( - fs::Files::new("/", &static_root) - .index_file("index.html"), - ) + .service(fs::Files::new("/", &static_root).index_file("index.html")) }) .bind(&address) .expect("Can't start the webserver") @@ -272,7 +259,7 @@ pub fn serve( println!("Press Ctrl+C to stop\n"); // Delete the output folder on ctrl+C ctrlc::set_handler(move || { - let _ =remove_dir_all(&output_path); + let _ = remove_dir_all(&output_path); ::std::process::exit(0); }) .expect("Error setting Ctrl-C handler"); @@ -326,7 +313,12 @@ pub fn serve( } else { rebuild_done_handling( &broadcaster, - copy_file(&path, &site.output_path, &site.static_path, site.config.hard_link_static), + copy_file( + &path, + &site.output_path, + &site.static_path, + site.config.hard_link_static, + ), &partial_path.to_string_lossy(), ); } diff --git a/src/main.rs b/src/main.rs index 36eac2c..1af99df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,7 +74,7 @@ fn main() { ::std::process::exit(1); } - if !watch_only && !port_is_available(port) { + if !watch_only && !port_is_available(port) { port = if let Some(p) = get_available_port(1111) { p } else {