Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions crates/zorto-core/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,9 @@ pub fn load_content(content_dir: &Path, base_url: &str) -> anyhow::Result<Loaded
///
/// - `README.md` files become sections (like `_index.md`)
/// - Other `.md` files become pages
/// - Title is extracted from the first `# Heading`
/// - Description is extracted from the first paragraph after the heading
/// - TOML frontmatter is honored when present
/// - Title is extracted from frontmatter, then the first `# Heading`
/// - Description is extracted from frontmatter, then the first paragraph after the heading
/// - Files listed in `config.exclude` are skipped
pub fn load_content_dir(
dir: &Path,
Expand Down Expand Up @@ -491,12 +492,18 @@ pub fn load_content_dir(
.to_string_lossy()
.to_string();

let (extracted_title, description) = extract_title_description(&raw);
// Use extracted H1 title, or derive from filename for non-README files
let title = extracted_title.unwrap_or_else(|| title_from_filename(&stem));
let (mut fm, parsed_body) =
parse_frontmatter(&raw).map_err(|e| e.context(format!("in {}", path.display())))?;
let (extracted_title, description) = extract_title_description(&parsed_body);
if fm.title.is_none() {
fm.title = Some(extracted_title.unwrap_or_else(|| title_from_filename(&stem)));
}
if fm.description.is_none() {
fm.description = description;
}

// Strip the title heading from body content so it doesn't render twice
let body = strip_title_heading(&raw);
let body = strip_title_heading(&parsed_body);

// Optionally rewrite .md links to clean URLs
let body = if config.rewrite_links {
Expand All @@ -522,13 +529,12 @@ pub fn load_content_dir(
}
};

let fm = Frontmatter {
title: Some(title),
description,
template: Some(config.section_template.clone()),
sort_by: config.sort_by,
..Default::default()
};
if fm.template.is_none() {
fm.template = Some(config.section_template.clone());
}
if fm.sort_by.is_none() {
fm.sort_by = config.sort_by;
}
let section = build_section(fm, body, &rel_path, base_url);
sections.insert(rel_path, section);
} else {
Expand All @@ -543,12 +549,9 @@ pub fn load_content_dir(
format!("{}/{parent}/{stem}.md", config.url_prefix)
};

let fm = Frontmatter {
title: Some(title),
description,
template: Some(config.template.clone()),
..Default::default()
};
if fm.template.is_none() {
fm.template = Some(config.template.clone());
}
let page = build_page(fm, body, &rel_path, base_url);
pages.insert(rel_path, page);
}
Expand Down
4 changes: 4 additions & 0 deletions docs/getting-started/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
+++
sort_by = "weight"
+++

# Getting started

This tutorial walks you through building a complete site with Zorto, from installation to production build.
Expand Down
4 changes: 4 additions & 0 deletions docs/getting-started/first-site.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
+++
weight = 30
+++

# Next steps

Now that you have a working site, here are some directions to explore.
Expand Down
4 changes: 4 additions & 0 deletions docs/getting-started/installation.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
+++
weight = 10
+++

# Installation

Zorto runs on macOS and Linux. Windows support is available via WSL.
Expand Down
4 changes: 4 additions & 0 deletions docs/getting-started/quick-start.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
+++
weight = 20
+++

# Your first site

By the end of this tutorial you will have a working site with:
Expand Down
Loading