Prevent generating folder & index.html for a specific page
This commit is contained in:
parent
c5991fc814
commit
cb2a4b0ee8
@ -8,6 +8,7 @@
|
||||
- Fix resizing for images with EXIF orientation
|
||||
- Add MIME type to get_image_metadata
|
||||
- Fix hot loading for config.toml in some cases
|
||||
- Add `render = false` capability to pages
|
||||
|
||||
## 0.18.0 (2023-12-18)
|
||||
|
||||
|
@ -39,6 +39,10 @@ pub struct PageFrontMatter {
|
||||
pub datetime_tuple: Option<(i32, u8, u8)>,
|
||||
/// Whether this page is a draft
|
||||
pub draft: bool,
|
||||
/// Prevent generation of a folder for current page
|
||||
/// Defaults to `true`
|
||||
#[serde(skip_serializing)]
|
||||
pub render: bool,
|
||||
/// The page slug. Will be used instead of the filename if present
|
||||
/// Can't be an empty string if present
|
||||
pub slug: Option<String>,
|
||||
@ -151,6 +155,7 @@ impl Default for PageFrontMatter {
|
||||
datetime: None,
|
||||
datetime_tuple: None,
|
||||
draft: false,
|
||||
render: true,
|
||||
slug: None,
|
||||
path: None,
|
||||
taxonomies: HashMap::new(),
|
||||
|
@ -82,9 +82,11 @@ impl Library {
|
||||
|
||||
pub fn insert_page(&mut self, page: Page) {
|
||||
let file_path = page.file.path.clone();
|
||||
let mut entries = vec![page.path.clone()];
|
||||
entries.extend(page.meta.aliases.to_vec());
|
||||
self.insert_reverse_aliases(&file_path, entries);
|
||||
if page.meta.render {
|
||||
let mut entries = vec![page.path.clone()];
|
||||
entries.extend(page.meta.aliases.to_vec());
|
||||
self.insert_reverse_aliases(&file_path, entries);
|
||||
}
|
||||
|
||||
for (taxa_name, terms) in &page.meta.taxonomies {
|
||||
for term in terms {
|
||||
|
@ -115,6 +115,10 @@ impl Page {
|
||||
page.word_count = Some(word_count);
|
||||
page.reading_time = Some(reading_time);
|
||||
|
||||
if !page.meta.render {
|
||||
return Ok(page);
|
||||
}
|
||||
|
||||
let mut slug_from_dated_filename = None;
|
||||
|
||||
let file_path_for_slug = if page.file.name == "index" {
|
||||
@ -923,4 +927,25 @@ Bonjour le monde"#
|
||||
assert_eq!(page.slug, "hello");
|
||||
assert_eq!(page.permalink, "http://a-website.com/bonjour/");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn page_without_physical_path() {
|
||||
let config = Config::default();
|
||||
let content = r#"
|
||||
+++
|
||||
render = false
|
||||
+++
|
||||
Hello world
|
||||
"#
|
||||
.to_string();
|
||||
|
||||
let res = Page::parse(Path::new("hello.md"), &content, &config, &PathBuf::new());
|
||||
assert!(res.is_ok());
|
||||
let page = res.unwrap();
|
||||
println!("{:#?}", page);
|
||||
assert_eq!(page.slug, "");
|
||||
assert_eq!(page.path, "");
|
||||
assert_eq!(page.permalink, "");
|
||||
assert_eq!(page.raw_content, "Hello world\n".to_string());
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +130,9 @@ impl<'a> Paginator<'a> {
|
||||
|
||||
for p in &*self.all_pages {
|
||||
let page = &library.pages[p];
|
||||
if !page.meta.render {
|
||||
continue;
|
||||
}
|
||||
current_page.push(SerializingPage::new(page, Some(library), false));
|
||||
|
||||
if current_page.len() == self.paginate_by {
|
||||
|
@ -64,6 +64,9 @@ pub fn find_entries<'a>(
|
||||
let mut entries = HashSet::new();
|
||||
|
||||
for p in library.pages.values() {
|
||||
if !p.meta.render {
|
||||
continue;
|
||||
}
|
||||
let mut entry = SitemapEntry::new(
|
||||
Cow::Borrowed(&p.permalink),
|
||||
if p.meta.updated.is_some() { &p.meta.updated } else { &p.meta.date },
|
||||
|
@ -21,7 +21,7 @@ fn can_parse_site() {
|
||||
let library = site.library.read().unwrap();
|
||||
|
||||
// Correct number of pages (sections do not count as pages, draft are ignored)
|
||||
assert_eq!(library.pages.len(), 35);
|
||||
assert_eq!(library.pages.len(), 36);
|
||||
let posts_path = path.join("content").join("posts");
|
||||
|
||||
// Make sure the page with a url doesn't have any sections
|
||||
@ -44,7 +44,7 @@ fn can_parse_site() {
|
||||
|
||||
let posts_section = library.sections.get(&posts_path.join("_index.md")).unwrap();
|
||||
assert_eq!(posts_section.subsections.len(), 2);
|
||||
assert_eq!(posts_section.pages.len(), 10); // 11 with 1 draft == 10
|
||||
assert_eq!(posts_section.pages.len(), 11); // 12 with 1 draft == 11
|
||||
assert_eq!(posts_section.ancestors, vec![index_section.file.relative.clone()]);
|
||||
|
||||
// Make sure we remove all the pwd + content from the sections
|
||||
@ -136,6 +136,9 @@ fn can_build_site_without_live_reload() {
|
||||
assert!(file_exists!(public, "posts/with-assets/index.html"));
|
||||
assert!(file_exists!(public, "posts/no-section/simple/index.html"));
|
||||
|
||||
// "render = false" should not generate an index.html
|
||||
assert!(!file_exists!(public, "posts/render/index.html"));
|
||||
|
||||
// Sections
|
||||
assert!(file_exists!(public, "posts/index.html"));
|
||||
assert!(file_exists!(public, "posts/tutorials/index.html"));
|
||||
|
@ -112,6 +112,9 @@ weight = 0
|
||||
# A draft page is only loaded if the `--drafts` flag is passed to `zola build`, `zola serve` or `zola check`.
|
||||
draft = false
|
||||
|
||||
# When set to "false" Zola will not create a separate folder with index.html inside for this page.
|
||||
render = false
|
||||
|
||||
# If set, this slug will be used instead of the filename to make the URL.
|
||||
# The section path will still be used.
|
||||
slug = ""
|
||||
|
8
test_site/content/posts/render.md
Normal file
8
test_site/content/posts/render.md
Normal file
@ -0,0 +1,8 @@
|
||||
+++
|
||||
title = "Page with content but without generated folder"
|
||||
description = ""
|
||||
date = 2017-04-01
|
||||
render = false
|
||||
+++
|
||||
|
||||
Don't generate a folder for this page
|
Loading…
Reference in New Issue
Block a user