Skip to content

Commit 8a8219a

Browse files
authored
Update pages.yml
1 parent d442662 commit 8a8219a

1 file changed

Lines changed: 44 additions & 54 deletions

File tree

.github/workflows/pages.yml

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
workflow_dispatch:
77

88
permissions:
9-
contents: read
9+
contents: write
1010
pages: write
1111
id-token: write
1212

@@ -28,54 +28,66 @@ jobs:
2828
sudo apt-get update
2929
sudo apt-get install -y pandoc jq
3030
31-
# Prefer an existing docs/index.html; only generate from README if missing.
31+
- id: ensure_license
32+
name: Ensure MIT License exists (and mark if created)
33+
run: |
34+
if [ ! -f LICENSE ]; then
35+
YEAR=$(date +%Y)
36+
printf '%s\n' "MIT License" "" "Copyright (c) $YEAR Steph Buongiorno" "" "Permission is hereby granted, free of charge, to any person obtaining a copy" "of this software and associated documentation files (the \"Software\"), to deal" "in the Software without restriction, including without limitation the rights" "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" "copies of the Software, and to permit persons to whom the Software is" "furnished to do so, subject to the following conditions:" "" "The above copyright notice and this permission notice shall be included in all" "copies or substantial portions of the Software." "" "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE" "SOFTWARE." > LICENSE
37+
echo "MIT License generated."
38+
echo "created=true" >> "$GITHUB_OUTPUT"
39+
else
40+
echo "LICENSE file already exists — skipping generation."
41+
echo "created=false" >> "$GITHUB_OUTPUT"
42+
fi
43+
44+
- name: Commit LICENSE to repo (first time only)
45+
if: steps.ensure_license.outputs.created == 'true'
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
run: |
49+
git config user.name "github-actions[bot]"
50+
git config user.email "github-actions[bot]@users.noreply.github.com"
51+
git add LICENSE
52+
git commit -m "Add MIT LICENSE (auto-generated)"
53+
git push
54+
3255
- id: build_page
33-
name: Build docs/index.html (prefer existing; fallback to README)
56+
name: Build index.html at root (prefer existing; fallback to README) with highlighted code
3457
env:
3558
REPO_HTML_TITLE: ${{ github.repository }}
3659
run: |
3760
set -e
38-
mkdir -p docs
3961
GENERATED=0
4062
41-
if [ -f docs/index.html ]; then
42-
echo "Keeping existing docs/index.html (not regenerating)."
63+
if [ -f index.html ]; then
64+
echo "Keeping existing index.html (not regenerating)."
4365
elif [ -f README.md ]; then
44-
echo "Generating docs/index.html from README.md..."
45-
pandoc README.md -f markdown -t html -s -o docs/index.html --metadata title="$REPO_HTML_TITLE"
66+
echo "Generating index.html from README.md with syntax highlighting..."
67+
pandoc README.md -f markdown -t html -s --highlight-style=tango -o index.html --metadata title="$REPO_HTML_TITLE"
4668
GENERATED=1
4769
else
48-
echo "No docs/index.html or README.md found; writing minimal page."
49-
printf '%s\n' \
50-
'<!doctype html><html><head><meta charset="utf-8"><title>Site</title></head><body>' \
51-
'<h1>Site</h1>' \
52-
'<p>No README.md found. Add one and push to regenerate this page.</p>' \
53-
'</body></html>' \
54-
> docs/index.html
70+
echo "No index.html or README.md found; writing minimal page."
71+
printf '%s\n' '<!doctype html><html><head><meta charset="utf-8"><title>Site</title></head><body>' '<h1>Site</h1>' '<p>No README.md found. Add one and push to regenerate this page.</p>' '</body></html>' > index.html
5572
GENERATED=1
5673
fi
5774
58-
# Ensure Arial font is applied, even on a custom index.html
59-
if grep -qi '</head>' docs/index.html; then
60-
sed -i 's|</head>|<style>body{font-family:Arial, Helvetica, sans-serif;} h1,h2,h3,h4,h5,h6{font-family:Arial, Helvetica, sans-serif;}</style></head>|' docs/index.html
75+
# Inject GitHub-like CSS for code blocks + base font without sed (avoid escaping issues)
76+
CSS_BLOCK='<style>body{font-family:Arial,Helvetica,sans-serif} h1,h2,h3,h4,h5,h6{font-family:Arial,Helvetica,sans-serif} pre code{display:block;padding:.75em;background:#f6f8fa;border-radius:6px;font-size:90%;overflow:auto} code{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace}</style>'
77+
if grep -qi '</head>' index.html; then
78+
awk -v css="$CSS_BLOCK" 'BEGIN{IGNORECASE=1} { if (!done && match(tolower($0), /<\/head>/)) { sub(/<\/head>/, css"</head>"); done=1 } print }' index.html > index.html.tmp
79+
mv index.html.tmp index.html
6180
else
62-
# Wrap bare content with a head + Arial
6381
TMP=$(mktemp)
64-
printf '%s\n' \
65-
'<!doctype html><html><head><meta charset="utf-8">' \
66-
'<style>body{font-family:Arial, Helvetica, sans-serif;} h1,h2,h3,h4,h5,h6{font-family:Arial, Helvetica, sans-serif;}</style>' \
67-
'</head><body>' \
68-
> "$TMP"
69-
cat docs/index.html >> "$TMP"
82+
printf '%s\n' '<!doctype html><html><head><meta charset="utf-8">' "${CSS_BLOCK}" '</head><body>' > "$TMP"
83+
cat index.html >> "$TMP"
7084
printf '%s\n' '</body></html>' >> "$TMP"
71-
mv "$TMP" docs/index.html
85+
mv "$TMP" index.html
7286
fi
7387
74-
# Expose whether we generated from README/minimal (1) or kept existing (0)
7588
echo "generated=$GENERATED" >> "$GITHUB_OUTPUT"
7689
77-
# Append citation ONLY when we generated the page from README/minimal
78-
- name: Append suggested citation (written + BibTeX) + repo metadata
90+
- name: Append License, Suggested Citation, BibTeX, and repo metadata
7991
if: steps.build_page.outputs.generated == '1'
8092
env:
8193
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -89,12 +101,8 @@ jobs:
89101
LAST_UPDATE=$(git log -1 --format=%cI || date -u +%Y-%m-%dT%H:%M:%SZ)
90102
YEAR=$(date -u -d "$LAST_UPDATE" +%Y 2>/dev/null || date -u +%Y)
91103
92-
# Collect contributor logins (exclude bots/ghost)
93-
logins=$(curl -s -H "Authorization: Bearer $GH_TOKEN" \
94-
"https://api.github.com/repos/$REPO/contributors?per_page=100&anon=false" \
95-
| jq -r '.[] | select((.type // "") != "Bot") | select(.login != "ghost") | .login' | sort -fu)
104+
logins=$(curl -s -H "Authorization: Bearer $GH_TOKEN" "https://api.github.com/repos/$REPO/contributors?per_page=100&anon=false" | jq -r '.[] | select((.type // "") != "Bot") | select(.login != "ghost") | .login' | sort -fu)
96105
97-
# Map to display names (fallback to login), skip Steph to keep her first
98106
names=""
99107
for u in $logins; do
100108
name=$(curl -s -H "Authorization: Bearer $GH_TOKEN" "https://api.github.com/users/$u" | jq -r '.name // empty')
@@ -105,20 +113,17 @@ jobs:
105113
done
106114
names_sorted=$(printf "%b" "$names" | awk 'NF' | sort -fu)
107115
108-
# Suggested (written) citation
109116
citation_written="Steph Buongiorno"
110117
if [ -n "$names_sorted" ]; then
111118
citation_written="$citation_written; $(echo "$names_sorted" | paste -sd ', ' -)"
112119
fi
113120
citation_written="$citation_written. $REPO_NAME. $YEAR. Available at: $REPO_URL"
114121
115-
# Proper BibTeX authors: "A and B and C"
116122
authors_bibtex="Steph Buongiorno"
117123
if [ -n "$names_sorted" ]; then
118124
authors_bibtex="$authors_bibtex and $(echo "$names_sorted" | paste -sd ' and ' -)"
119125
fi
120126
121-
# BibTeX entry as a shell variable (YAML-safe)
122127
bibtex="@misc{$REPO_NAME-$YEAR,
123128
author = {$authors_bibtex},
124129
title = {$REPO_NAME},
@@ -127,23 +132,7 @@ jobs:
127132
note = {Last updated: $LAST_UPDATE}
128133
}"
129134
130-
# Append both to index.html
131-
printf '%s\n' \
132-
'' \
133-
'<hr>' \
134-
'<h2>Suggested Citation</h2>' \
135-
"<p>$citation_written</p>" \
136-
'' \
137-
'<h3>BibTeX</h3>' \
138-
'<pre><code>' \
139-
"$bibtex" \
140-
'</code></pre>' \
141-
'' \
142-
'<h3>Repository</h3>' \
143-
"<p><em>$REPO_NAME</em><br>" \
144-
"<a href=\"$REPO_URL\">$REPO_URL</a><br>" \
145-
"<strong>Last updated:</strong> $LAST_UPDATE</p>" \
146-
>> docs/index.html
135+
printf '%s\n' '' '<hr>' '<h2>License</h2>' '<p>This project is licensed under the <a href="LICENSE">MIT License</a>.</p>' '' '<h2>Suggested Citation</h2>' "<p>$citation_written</p>" '' '<h3>BibTeX</h3>' '<pre><code>' "$bibtex" '</code></pre>' '' '<h3>Repository</h3>' "<p><em>$REPO_NAME</em><br>" "<a href=\"$REPO_URL\">$REPO_URL</a><br>" "<strong>Last updated:</strong> $LAST_UPDATE</p>" >> index.html
147136
148137
- name: Upload site artifact
149138
uses: actions/upload-pages-artifact@v3
@@ -163,3 +152,4 @@ jobs:
163152

164153

165154

155+

0 commit comments

Comments
 (0)