-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgogo
More file actions
executable file
·109 lines (91 loc) · 2.77 KB
/
gogo
File metadata and controls
executable file
·109 lines (91 loc) · 2.77 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/zsh -eu
mydir=${0:a:h}
# Does some minor manipulations to get HuGo to work nicely w/ the desired repo directory layout.
# Used in local dev on a mac; and in GitHub Actions
cd $mydir
function restore-source-files() {
( set +e; mv data/comments . && rmdir data )
for MD in $(find . -mindepth 2 -type f -name 'index.md' |cut -f2- -d/ |grep -Ev ^public/); do
HTM=$(echo $MD |perl -pe 's/\.md$/.html/')
mv $HTM.tmp $HTM
rm $MD
done
}
UNAMEY=$(uname)
if [ "$UNAMEY" = Darwin ]; then
# in dev mode
trap restore-source-files EXIT
else
# GitHub Actions
# Setup theme
set -x
pwd
wget -q https://github.com/traceypooh/hugo-future-imperfect-slim/archive/refs/heads/master.zip
unzip -q master.zip
mv hugo-future-imperfect-slim-master theme
set +x
fi
# sigh :p
mkdir -p data
mv comments data
NPAGES=0
NPOSTS=0
for HTM in $(find . -mindepth 2 -type f -name 'index.html' |cut -f2- -d/ |grep -Ev ^public/); do
if ( ! grep -qE '^---' $HTM ); then
# echo "skipping $HTM w/o frontmatter"
continue
fi
MD=$(echo $HTM |perl -pe 's/\.html$/.md/')
cp $HTM $MD
mv $HTM $HTM.tmp
ALIASED=
set +e
if ( grep -qE '^type: page$' $MD ); then
((NPAGES++))
else
((NPOSTS++))
DATE=$(grep -Eo '^date: [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]' $MD |cut -f2 -d ' ')
if [ "$DATE" = "" ]; then
echo "$HTM has no 'date:'"
exit 1
fi
if ( grep -qE '^aliases:' $MD ); then
ALIASED=1
fi
if ( grep -qE '^type: post$' $MD ); then
if [[ $MD == 20* ]]; then
# post with filename staring with '20'(YY-MM-..)
# TTL is dirname with lead YYYY-MM- removed
YYYY=$(echo $DATE |cut -d- -f1)
MM=$(echo $DATE |cut -d- -f2)
DD=$(echo $DATE |cut -d- -f3)
TTL=$(echo $MD |rev |cut -f2- -d/ |rev |cut -f3- -d-)
ALIAS1="/$YYYY/$MM/$DD/$TTL/"
ALIAS2="/$YYYY/$MM/$TTL/"
ALIASES="aliases: ['$ALIAS1', '$ALIAS2']"
if [ $ALIASED ]; then
# check the front matter for the 2 aliases we always want to be present
# (there should be 1+ more, too)
tail +2 $MD |fgrep -B100 -m1 -- --- | grep -q $ALIAS1 || \
echo ERROR: $HTM is missing alias: $ALIAS1
tail +2 $MD |fgrep -B100 -m1 -- --- | grep -q $ALIAS2 || \
echo ERROR: $HTM is missing alias: $ALIAS2
else
perl -i -pe 's#^(date: .*)#$1\n'$ALIASES'#' $MD
fi
fi
else
echo "Adding 'type: post' to $MD"
perl -i -pe 's#^(date: .*)#$1\ntype: post#' $MD
fi
fi
set -e
done
echo Number Posts: $NPOSTS
echo Number Pages: $NPAGES
( set -eux; hugo )
# cheap check if GitHub Actions or dev mode on mac
if [ "$UNAMEY" = Darwin ]; then
restore-source-files
( set -eux; caddy file-server -r public --listen :1313 )
fi