Skip to content

Validate path format in CI #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
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
24 changes: 24 additions & 0 deletions front_matter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ pub fn normalize(
);
}

// validate format of 'path'
{
let mut path = front_matter.path.as_str();
let mut rq_fmt = "YYYY/MM/DD/slug-of-your-choice";
if inside_rust {
rq_fmt = "inside-rust/YYYY/MM/DD/slug-of-your-choice";
if !path.starts_with("inside-rust/") {
bail!("the path of inside-rust posts must start with 'inside-rust/'");
}
path = path.trim_start_matches("inside-rust/");
}
let components = path.split('/').collect::<Vec<_>>();
if components.len() != 4
|| components[0].len() != 4
|| components[0].parse::<u32>().is_err()
|| components[1].len() != 2
|| components[1].parse::<u8>().is_err()
|| components[2].len() != 2
|| components[2].parse::<u8>().is_err()
{
bail!("invalid 'path' key in front matter, required format: {rq_fmt}");
}
}

if front_matter.extra.team.is_some() ^ front_matter.extra.team_url.is_some() {
bail!("extra.team and extra.team_url must always come in a pair");
}
Expand Down