Skip to main content

stage_content_with_site_defaults

Function stage_content_with_site_defaults 

Source
pub fn stage_content_with_site_defaults(
    content_dir: &Path,
    build_dir: &Path,
    template_var_keys: &[String],
    base_url: Option<&str>,
    locales: &[String],
) -> Result<PathBuf, Error>
Expand description

Like stage_content_with_template_defaults but also derives a permalink: for staged .md files that don’t declare one.

Injection targets every staged .md file whose frontmatter carries neither permalink nor url (spec A2/B1, plan §2 item 1.2, issue #586). The derived value comes from crate::urls::derive_permalink applied to base_url and the file’s content-relative path — i.e. {base_url}/{relative_output_path} under the compiler’s foo.md → foo/index.html output convention, published as a pretty directory URL ({base_url}/foo/). This guarantees staticdatagen / rss-gen always see a channel/item link and can never abort the build with “channel.link is missing”.

Passing base_url: None (or an empty/whitespace-only base URL) disables permalink injection and behaves exactly like stage_content_with_template_defaults — an rss-gen-valid permalink must be an absolute URL, so there is nothing useful to derive without a base.

Author-specified front matter always wins: files that already declare permalink or url pass through verbatim.

§Errors

Returns io::Error when the staging directory cannot be created or a source file cannot be read or written.

§Examples

use ssg::content_stager::stage_content_with_site_defaults;
use std::fs;

let tmp = tempfile::tempdir().unwrap();
let src = tmp.path().join("content");
let build = tmp.path().join("build");
fs::create_dir_all(&src).unwrap();
fs::write(src.join("post.md"), "---\ntitle: A\n---\nbody").unwrap();

let staged = stage_content_with_site_defaults(
    &src, &build, &[], Some("https://example.com"), &[],
).unwrap();
let out = fs::read_to_string(staged.join("post.md")).unwrap();
assert!(out.contains("permalink: \"https://example.com/post/\""));