Skip to content

Commit d772f33

Browse files
committed
Add check against date placeholders
The date of publication often has to be adjusted at the last minute. This can easily be forgotten. This commit introduces a new workflow: Blog authors keep a placeholder as the date (9999/12/99) until shortly before publication. Setting the date is aided with automation. Lastly, A check triggered by the merge queue event is used to block PRs from being merged where the placeholder hasn't been replaced yet.
1 parent 85f525f commit d772f33

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

.github/workflows/merge_queue.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
env:
9+
# renovate: datasource=github-tags depName=rust lookupName=rust-lang/rust
10+
RUST_VERSION: 1.86.0
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
17+
18+
- run: rustup override set ${{ env.RUST_VERSION }}
19+
- run: rustup component add clippy
20+
- run: rustup component add rustfmt
21+
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
22+
23+
- run: cargo clippy --workspace -- -D warnings
24+
- run: cargo fmt --check --all
25+
- run: cargo test --package front_matter
26+
27+
build:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
31+
32+
- run: rustup override set ${{ env.RUST_VERSION }}
33+
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
34+
35+
- name: Install Zola
36+
run: cargo install --locked --git https://github.com/senekor/zola --rev 620bf3c46a39b41db30b1e91756a995bbff84d3a
37+
- run: zola build
38+
- run: cp CNAME ./public/
39+
- run: touch public/.nojekyll
40+
41+
- uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
42+
with:
43+
path: public
44+
45+
deploy:
46+
if: ${{ github.ref == 'refs/heads/master' }}
47+
48+
needs: build
49+
50+
permissions:
51+
pages: write
52+
id-token: write
53+
54+
runs-on: ubuntu-latest
55+
steps:
56+
- id: deployment
57+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
58+
59+
environment:
60+
name: github-pages
61+
url: ${{ steps.deployment.outputs.page_url }}

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ You can store your main blog post in `content/<some-slug>/index.md`.
3333
Images go into the same directory: `content/<some-slug>/my_image.png`.
3434
Now you can reference that image with a simple relative path: `![alt text](my_image.png)`.
3535

36+
A post's date of publication is embedded in the `path` key of the front matter.
37+
Keep the placeholder (`9999/12/99`) until the post is about to be merged.
38+
You can easily do so by adding a comment containing the string `publish=today` on the PR.
39+
Don't worry, there's a merge queue check to make sure you don't forget.
40+
3641
Here is an example of the front matter format:
3742
```md
3843
+++
39-
path = "2015/03/15/some-slug"
44+
path = "9999/12/99/some-slug"
4045
title = "Title of the blog post"
4146
authors = ["Blog post author (or on behalf of which team)"]
4247
description = "(optional)"

front_matter/src/lib.rs

+43
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,47 @@ The post {post} has abnormal front matter.
212212
};
213213
}
214214
}
215+
216+
/// This test is run by the merge queue check to make sure a blog post
217+
/// isn't merged before its date is set. The date of a blog post is usually
218+
/// a placeholder (path = "9999/12/99/...") until shortly before it's
219+
/// published. Setting the date can be done manually or by commenting
220+
/// "publish=today" on the PR.
221+
#[test]
222+
#[ignore]
223+
fn date_is_set() {
224+
let repo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..");
225+
226+
let posts = fs::read_dir(repo_root.join("content"))
227+
.unwrap()
228+
.chain(fs::read_dir(repo_root.join("content/inside-rust")).unwrap())
229+
.map(|p| p.unwrap().path())
230+
.filter(|p| p.is_file() && p.file_name() != Some("_index.md".as_ref()));
231+
232+
for post in posts {
233+
let slug = post.file_stem().unwrap().to_str().unwrap();
234+
235+
let content = fs::read_to_string(&post).unwrap();
236+
let (front_matter, _) = parse(&content).unwrap();
237+
238+
if front_matter.path.starts_with("9999/12/99/") {
239+
panic!(
240+
"
241+
The post {slug} has a placeholder publication date.
242+
243+
┌──────────────────────────────────────────────────────────────────────────┐
244+
│ │
245+
│ You can set the publication date automatically by commenting │
246+
│ │
247+
│ publish=today │
248+
│ │
249+
│ on the pull request of the post. │
250+
│ (You can also edit the 'path' key in the front matter directly.) │
251+
│ │
252+
└──────────────────────────────────────────────────────────────────────────┘
253+
",
254+
);
255+
}
256+
}
257+
}
215258
}

0 commit comments

Comments
 (0)