Skip to content

Add check against date placeholders #1580

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
61 changes: 61 additions & 0 deletions .github/workflows/merge_queue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CI
on:
push:
branches:
- master
pull_request:

env:
# renovate: datasource=github-tags depName=rust lookupName=rust-lang/rust
RUST_VERSION: 1.86.0

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- run: rustup override set ${{ env.RUST_VERSION }}
- run: rustup component add clippy
- run: rustup component add rustfmt
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8

- run: cargo clippy --workspace -- -D warnings
- run: cargo fmt --check --all
- run: cargo test --package front_matter

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- run: rustup override set ${{ env.RUST_VERSION }}
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8

- name: Install Zola
run: cargo install --locked --git https://github.com/senekor/zola --rev 620bf3c46a39b41db30b1e91756a995bbff84d3a
- run: zola build
- run: cp CNAME ./public/
- run: touch public/.nojekyll

- uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
with:
path: public

deploy:
if: ${{ github.ref == 'refs/heads/master' }}

needs: build

permissions:
pages: write
id-token: write

runs-on: ubuntu-latest
steps:
- id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ You can store your main blog post in `content/<some-slug>/index.md`.
Images go into the same directory: `content/<some-slug>/my_image.png`.
Now you can reference that image with a simple relative path: `![alt text](my_image.png)`.

A post's date of publication is embedded in the `path` key of the front matter.
Keep the placeholder (`9999/12/99`) until the post is about to be merged.
You can easily do so by adding a comment containing the string `publish=today` on the PR.
Don't worry, there's a merge queue check to make sure you don't forget.

Here is an example of the front matter format:
```md
+++
path = "2015/03/15/some-slug"
path = "9999/12/99/some-slug"
title = "Title of the blog post"
authors = ["Blog post author (or on behalf of which team)"]
description = "(optional)"
Expand Down
43 changes: 43 additions & 0 deletions front_matter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,47 @@ The post {post} has abnormal front matter.
};
}
}

/// This test is run by the merge queue check to make sure a blog post
/// isn't merged before its date is set. The date of a blog post is usually
/// a placeholder (path = "9999/12/99/...") until shortly before it's
/// published. Setting the date can be done manually or by commenting
/// "publish=today" on the PR.
#[test]
#[ignore]
fn date_is_set() {
let repo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..");

let posts = fs::read_dir(repo_root.join("content"))
.unwrap()
.chain(fs::read_dir(repo_root.join("content/inside-rust")).unwrap())
.map(|p| p.unwrap().path())
.filter(|p| p.is_file() && p.file_name() != Some("_index.md".as_ref()));

for post in posts {
let slug = post.file_stem().unwrap().to_str().unwrap();

let content = fs::read_to_string(&post).unwrap();
let (front_matter, _) = parse(&content).unwrap();

if front_matter.path.starts_with("9999/12/99/") {
panic!(
"
The post {slug} has a placeholder publication date.

┌──────────────────────────────────────────────────────────────────────────┐
│ │
│ You can set the publication date automatically by commenting │
│ │
│ publish=today │
│ │
│ on the pull request of the post. │
│ (You can also edit the 'path' key in the front matter directly.) │
│ │
└──────────────────────────────────────────────────────────────────────────┘
",
);
}
}
}
}