Skip to content

Commit e834efa

Browse files
authored
Ci/add articles in yyyy/mm folder (#472)
* docs: update info on dates in contribution guide * feat: update archetypes detault file * ci: check publishing dates * feat: allow future dates for articles
1 parent d84a38c commit e834efa

File tree

3 files changed

+111
-5
lines changed

3 files changed

+111
-5
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Check publishing dates
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- 'content/blog/**'
9+
10+
env:
11+
TARGET_REPO_URL: "https://github.com/espressif/developer-portal.git"
12+
TARGET_BRANCH: "main"
13+
14+
jobs:
15+
check-publishing-dates:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout PR contents
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Get added folders and files
24+
id: added-files
25+
run: |
26+
# Add target remote and fetch its branches
27+
git remote add target "$TARGET_REPO_URL"
28+
git fetch target "$TARGET_BRANCH"
29+
30+
mkdir -p temp
31+
32+
git diff --name-only --diff-filter=A origin/${{ github.base_ref }}...HEAD > temp/added-files.txt
33+
34+
echo "List of added files:"
35+
cat temp/added-files.txt
36+
37+
while IFS= read -r line; do
38+
if [[ "$line" =~ ^content/blog/.*/index.md$ ]]; then
39+
echo "$line" >> temp/index.txt
40+
dirname "$line" >> temp/folders.txt
41+
fi
42+
done < temp/added-files.txt
43+
44+
- name: Validate year and month folder
45+
run: |
46+
CURRENT_YEAR=$(date +%Y)
47+
CURRENT_MONTH=$(date +%m)
48+
49+
while IFS= read -r folder; do
50+
if [[ "$folder" =~ ^content/blog/([0-9]{4})/([0-9]{2})/ ]]; then
51+
year="${BASH_REMATCH[1]}"
52+
month="${BASH_REMATCH[2]}"
53+
if [[ "$year" != "$CURRENT_YEAR" || "$month" != "$CURRENT_MONTH" ]]; then
54+
echo "$folder" >> temp/incorrect-yyyy-mm.txt
55+
fi
56+
else
57+
echo "$folder" >> temp/no-yyyy-mm.txt
58+
fi
59+
done < temp/folders.txt
60+
61+
- name: Make sure folders are under current YYYY/MM
62+
run: |
63+
error_found=0
64+
65+
CURRENT_YEAR=$(date +%Y)
66+
CURRENT_MONTH=$(date +%m)
67+
68+
if [[ -s temp/no-yyyy-mm.txt ]]; then
69+
echo "Move your article folder(s) to 'content/blog/${CURRENT_YEAR}/${CURRENT_MONTH}/':"
70+
cat temp/no-yyyy-mm.txt
71+
error_found=1
72+
fi
73+
74+
if [[ -s temp/incorrect-yyyy-mm.txt ]]; then
75+
echo "Move your article folder(s) to 'content/blog/${CURRENT_YEAR}/${CURRENT_MONTH}/':"
76+
cat temp/incorrect-yyyy-mm.txt
77+
error_found=1
78+
fi
79+
80+
exit $error_found
81+
82+
- name: Check index.md dates
83+
if: always()
84+
run: |
85+
error_found=0
86+
87+
today=$(date +%Y-%m-%d)
88+
89+
while IFS= read -r mdfile; do
90+
if [[ -f "$mdfile" ]]; then
91+
post_date=$(awk '/^date:/ {gsub(/["'\''"]/,"",$2); print $2}' "$mdfile")
92+
93+
if [[ ! "$post_date" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
94+
echo "In '$mdfile' YAML header, make sure the date is in YYYY-MM-DD format."
95+
error_found=1
96+
elif [[ "$post_date" < "$today" ]]; then
97+
echo "Once your article in '$mdfile' is approved, make sure the date in its YAML header is not in the past (found: $post_date, today: $today)."
98+
error_found=1
99+
fi
100+
fi
101+
done < temp/index.txt
102+
103+
exit $error_found

archetypes/default.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
title: "{{ replace .Name "-" " " | title }}"
3-
date: {{ .Date }}
3+
date: "{{ now.Format "2006-01-02" }}"
44
---

content/pages/contribution-guide/writing-content/index.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ See also the official [docs](https://gohugo.io/getting-started/quick-start/#add-
2424

2525
- To create a new article, determine the path and run
2626
```sh
27-
hugo new content <path/index.md>
28-
# Example
29-
hugo new content blog/contribution-guide/index.md
27+
# Blog article
28+
hugo new content blog/YYYY/MM/<article-folder-name>/index.md
29+
# Blog article example
30+
hugo new content blog/2025/04/ulp-lp-core-get-started/index.md
31+
# Non-blog articles (workshops, events etc.)
32+
hugo new content <path>/index.md
3033
```
31-
This assumes that you want to organize the content as a leaf bundle (the usual way). You can also use the [branch bundle](https://gohugo.io/content-management/page-bundles/#comparison).
34+
This assumes that you want to organize the content as a leaf bundle (a single article). For multi-article entries (workshops, etc.), use the [branch bundle](https://gohugo.io/content-management/page-bundles/#comparison).
3235
- To view the changes, in your project folder run
3336
```sh
3437
hugo server

0 commit comments

Comments
 (0)