refactor: consolidate escape functions and extract weight constants

- Create escape.rs with shared html_escape, html_escape_into, xml_escape
- Remove duplicate implementations from render.rs, highlight.rs, feed.rs, sitemap.rs
- Add DEFAULT_WEIGHT (50) and DEFAULT_WEIGHT_HIGH (99) constants to content.rs
- Replace all magic number weight defaults with named constants

No functional changes; all 67 tests pass.
This commit is contained in:
Timothy DeHerrera
2026-02-05 14:35:24 -07:00
parent 7a7dc929b1
commit 16f04eb95b
7 changed files with 84 additions and 55 deletions

View File

@@ -6,6 +6,12 @@ use serde::Serialize;
use std::fs;
use std::path::{Path, PathBuf};
/// Default weight for content items in navigation and listings.
pub const DEFAULT_WEIGHT: i64 = 50;
/// High default weight for content that should appear last (e.g., projects).
pub const DEFAULT_WEIGHT_HIGH: i64 = 99;
/// The type of content being processed.
#[derive(Debug, Clone, PartialEq)]
pub enum ContentKind {
@@ -212,7 +218,7 @@ pub fn discover_nav(content_dir: &Path) -> Result<Vec<NavItem>> {
.nav_label
.unwrap_or(content.frontmatter.title),
path: format!("/{}.html", slug),
weight: content.frontmatter.weight.unwrap_or(50),
weight: content.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT),
children: Vec::new(),
});
}
@@ -245,7 +251,7 @@ pub fn discover_nav(content_dir: &Path) -> Result<Vec<NavItem>> {
.map(|item| NavItem {
label: item.frontmatter.nav_label.unwrap_or(item.frontmatter.title),
path: format!("/{}/{}.html", dir_name, item.slug),
weight: item.frontmatter.weight.unwrap_or(50),
weight: item.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT),
children: Vec::new(),
})
.collect();
@@ -260,7 +266,7 @@ pub fn discover_nav(content_dir: &Path) -> Result<Vec<NavItem>> {
.nav_label
.unwrap_or(content.frontmatter.title),
path: format!("/{}/index.html", dir_name),
weight: content.frontmatter.weight.unwrap_or(50),
weight: content.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT),
children,
});
}
@@ -358,8 +364,8 @@ pub fn discover_sections(content_dir: &Path) -> Result<Vec<Section>> {
// Sort by weight
sections.sort_by(|a, b| {
let wa = a.index.frontmatter.weight.unwrap_or(50);
let wb = b.index.frontmatter.weight.unwrap_or(50);
let wa = a.index.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT);
let wb = b.index.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT);
wa.cmp(&wb)
});