-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·37 lines (34 loc) · 957 Bytes
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
for file in ./astro/src/content/blog/*/index.md; do
temp_file=$(mktemp)
awk '
BEGIN {in_frontmatter=0; frontmatter_end=0; has_description=0; has_pubDatetime=0}
/^---$/ {
if (in_frontmatter) {
in_frontmatter=0;
frontmatter_end=1;
if (!has_description) print "description: \"\"";
if (!has_pubDatetime) print "pubDatetime:", strftime("%Y-%m-%d", systime());
} else {
in_frontmatter=1;
}
print;
next;
}
in_frontmatter {
if ($1 == "date:") {
print "pubDatetime:", $2;
has_pubDatetime=1;
} else if ($1 == "description:") {
print;
has_description=1;
} else {
print;
}
next;
}
frontmatter_end || /^---$/ {frontmatter_end=0; print; next}
{print}
' "$file" > "$temp_file"
mv "$temp_file" "$file"
done