Skip to content

Commit 1619adf

Browse files
authored
Update pages.yml
1 parent 85eb66f commit 1619adf

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

.github/workflows/pages.yml

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
sudo apt-get update
2929
sudo apt-get install -y pandoc jq curl
3030
31-
- id: ensure_license
31+
- id: ensure_license
3232
name: Ensure MIT License exists (and mark if created)
3333
run: |
3434
if [ ! -f LICENSE ]; then
@@ -60,12 +60,7 @@ jobs:
6060
set -e
6161
GENERATED=0
6262
63-
OWNER="${GITHUB_REPOSITORY%/*}"
64-
REPO_NAME="${GITHUB_REPOSITORY#*/}"
65-
HOMELINK="https://democracy-lab.github.io/"
66-
REPO_URL="https://github.com/$OWNER/$REPO_NAME"
67-
68-
# Minimal Pandoc template
63+
# Minimal Pandoc template (no default CSS)
6964
cat > pandoc_template.html <<'TPL'
7065
<!doctype html>
7166
<html>
@@ -97,53 +92,77 @@ jobs:
9792
GENERATED=1
9893
else
9994
echo "No index.html or README.md found; writing minimal page."
100-
printf '%s\n' \
101-
'<!doctype html><html><head><meta charset="utf-8"><title>Site</title></head><body>' \
102-
'<h1>Site</h1>' \
103-
'<p>No README.md found. Add one and push to regenerate this page.</p>' \
104-
'</body></html>' > index.html
95+
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
10596
GENERATED=1
10697
fi
10798
99+
HOMELINK="https://democracy-lab.github.io/"
100+
101+
# Styles: grid layout + "full-height" painted sidebar column
108102
CSS='<style>
109103
html, body { width:100%; max-width:none; margin:0; padding:0; font-family: Arial, Helvetica, sans-serif; color:#222; }
110104
h1, h2, h3, h4, h5, h6 { font-family: Arial, Helvetica, sans-serif; }
111105
pre code { display:block; padding:.75em; background:#f6f8fa; border-radius:6px; font-size:90%; overflow:auto; }
112106
code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
113-
.page { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; background: linear-gradient(to right, #f4f4f4 0, #f4f4f4 220px, transparent 220px); }
114-
.sidebar { padding: 20px; position: sticky; top: 0; height: 100vh; overflow: auto; }
107+
108+
/* Page uses CSS Grid; paint the left column so the sidebar appears full-height */
109+
.page {
110+
display: grid;
111+
grid-template-columns: 220px 1fr;
112+
min-height: 100vh;
113+
background: linear-gradient(to right, #f4f4f4 0, #f4f4f4 220px, transparent 220px);
114+
}
115+
116+
.sidebar {
117+
padding: 20px;
118+
position: sticky;
119+
top: 0;
120+
height: 100vh; /* sidebar content scrolls independently if long */
121+
overflow: auto;
122+
}
115123
.sidebar a { display:block; margin-bottom:10px; color:#0366d6; text-decoration:none; font-weight:600; }
116124
.sidebar a:hover { text-decoration:underline; }
125+
117126
.content { width: 100%; }
118127
.container { width:100%; max-width: 1400px; margin: 0 auto; padding: 48px; }
128+
129+
/* Extras block spacing */
119130
.extras { margin-top: 48px; }
120131
.extras h2, .extras h3 { margin-top: 1.2em; }
132+
121133
@media (max-width: 1000px) {
122134
.page { display:block; background:none; }
123135
.sidebar { position: static; height:auto; overflow:visible; padding:16px; background:#f4f4f4; }
124136
.container { max-width:100%; margin:0; padding:24px; }
125137
}
126138
</style>'
127139
128-
# Inject CSS into <head>
140+
# Inject CSS into <head> (or wrap if missing)
129141
if grep -qi '</head>' index.html; then
130142
awk -v css="$CSS" 'BEGIN{IGNORECASE=1} { if (!done && match(tolower($0), /<\/head>/)) { sub(/<\/head>/, css"</head>"); done=1 } print }' index.html > index.html.tmp
131143
mv index.html.tmp index.html
144+
else
145+
TMP=$(mktemp)
146+
printf '%s\n' '<!doctype html><html><head><meta charset="utf-8">' "$CSS" '</head><body>' > "$TMP"
147+
sed '1,/<body[^>]*>/d' index.html >> "$TMP" || true
148+
printf '%s\n' '</body></html>' >> "$TMP"
149+
mv "$TMP" index.html
132150
fi
133151
134-
# Wrap with sidebar + container
152+
# Wrap body with grid + sidebar + content container (idempotent)
135153
if grep -qi '<div class="page"' index.html; then
136154
echo "Wrapper already present; skipping."
137155
else
138-
awk -v home="$HOMELINK" -v repo="$REPO_URL" 'BEGIN{IGNORECASE=1}
156+
awk -v home="$HOMELINK" 'BEGIN{IGNORECASE=1}
139157
{
140158
if (!done && match(tolower($0), /<body[^>]*>/)) {
141-
sub(/<body[^>]*>/, "&\n<div class=\"page\"><aside class=\"sidebar\"><a href=\"" home "\" aria-label=\"Go to home\">← Home</a>\n<a href=\"" repo "\" aria-label=\"View source on GitHub\">View Repository</a></aside>\n<main class=\"content\"><div class=\"container\">");
159+
sub(/<body[^>]*>/, "&\n<div class=\"page\"><aside class=\"sidebar\"><a href=\"" home "\" aria-label=\"Go to home\">← Home</a></aside>\n<main class=\"content\"><div class=\"container\">");
142160
done=1
143161
}
144162
print
145163
}' index.html > index.html.tmp && mv index.html.tmp index.html
146164
165+
# Close container/main/page before </body>
147166
awk 'BEGIN{IGNORECASE=1} { sub(/<\/body>/, "</div></main></div></body>"); print }' index.html > index.html.tmp && mv index.html.tmp index.html
148167
fi
149168
@@ -197,6 +216,7 @@ jobs:
197216
note = {Last updated: $LAST_UPDATE}
198217
}"
199218
219+
# Build the extras HTML block
200220
EXTRAS=$(cat <<'HTML'
201221
<section class="extras">
202222
<hr>
@@ -218,11 +238,12 @@ jobs:
218238
)
219239
220240
EXTRAS=${EXTRAS/__CITATION_WRITTEN__/$citation_written}
221-
EXTRAS=${EXTRAS/__BIBTEX__/$(printf "%s" "$bibtex" | sed 's/[&/\\]/\\&/g')}
241+
EXTRAS=${EXTRAS/__BIBTEX__/$(printf "%s" "$bibtex" | sed 's/[&/\]/\\&/g')}
222242
EXTRAS=${EXTRAS/__REPO_NAME__/$REPO_NAME}
223243
EXTRAS=${EXTRAS/__REPO_URL__/$REPO_URL}
224244
EXTRAS=${EXTRAS/__LAST_UPDATE__/$LAST_UPDATE}
225245
246+
# Inject JUST BEFORE the wrapper closes: </div></main></div></body>
226247
awk -v block="$EXTRAS" 'BEGIN{IGNORECASE=1}
227248
{
228249
line=$0
@@ -249,4 +270,3 @@ jobs:
249270
uses: actions/deploy-pages@v4
250271

251272

252-

0 commit comments

Comments
 (0)