Skip to content

Commit 634092d

Browse files
committed
Validate path format in CI
1 parent 5caa789 commit 634092d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: front_matter/src/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ pub fn normalize(
109109
);
110110
}
111111

112+
// validate format of 'path'
113+
{
114+
let mut path = front_matter.path.as_str();
115+
let mut rq_fmt = "YYYY/MM/DD/slug-of-your-choice";
116+
if inside_rust {
117+
rq_fmt = "inside-rust/YYYY/MM/DD/slug-of-your-choice";
118+
if !path.starts_with("inside-rust/") {
119+
bail!("the path of inside-rust posts must start with 'inside-rust/'");
120+
}
121+
path = path.trim_start_matches("inside-rust/");
122+
}
123+
let components = path.split('/').collect::<Vec<_>>();
124+
if components.len() != 4
125+
|| components[0].len() != 4
126+
|| components[0].parse::<u32>().is_err()
127+
|| components[1].len() != 2
128+
|| components[1].parse::<u8>().is_err()
129+
|| components[2].len() != 2
130+
|| components[2].parse::<u8>().is_err()
131+
{
132+
bail!("invalid 'path' key in front matter, required format: {rq_fmt}");
133+
}
134+
}
135+
112136
if front_matter.extra.team.is_some() ^ front_matter.extra.team_url.is_some() {
113137
bail!("extra.team and extra.team_url must always come in a pair");
114138
}

0 commit comments

Comments
 (0)