1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-11-23 21:02:09 +00:00

Create both index.html and index.xhtml files

Combines well with content-negotiation based on the "Accept" header.
This commit is contained in:
Rohan Kumar 2022-05-30 16:09:40 -07:00
parent 1aed7a66d4
commit 90aeb2d23a
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479
4 changed files with 76 additions and 44 deletions

View file

@ -52,10 +52,10 @@ hint: hugo .hintrc-local
.PHONY: lint-local
lint-local: lint-css lint-html
# dev server
# dev server, includes future and draft posts
.PHONY: serve
serve:
hugo serve --disableLiveReload $(HUGO_FLAGS)
hugo serve --disableLiveReload $(HUGO_FLAGS) -FwDb http://localhost:1313/
.PHONY: hint-devserver
hint-devserver: .hintrc-devserver
@ -69,19 +69,16 @@ check-links: hugo
.PHONY: test
test: lint-css hint-devserver check-links
gz:
find $(OUTPUT_DIR) -type f -name '*.html' -o -name '*.css' -o -name '*.xml' -o -name '*.webmanifest' -o -name '*.*.svg' \
| grep -v gemini \
| xargs ect -$(ECT_LEVEL) -gzip
gzip:
sh scripts/compress.sh $(OUTPUT_DIR) gzip $(ECT_LEVEL)
brotli:
find $(OUTPUT_DIR) -type f -name '*.html' -o -name '*.css' -o -name '*.xml' -o -name '*.webmanifest' -o -name '*.*.svg' \
| grep -v gemini \
| xargs brotli -q 11 --
sh scripts/compress.sh $(OUTPUT_DIR) brotli
compress: gzip brotli
.PHONY: gzip brotli compress
compress: gz brotli
.PHONY: compress gz brotli
.PHONY: xhtmlize
xhtmlize:
sh scripts/xhtmlize.sh $(OUTPUT_DIR)
# save webmentions to a file, don't send yet
mentions.json: hugo
@ -98,44 +95,47 @@ deploy-html:
.PHONY: deploy-gemini
deploy-gemini:
rsync $(RSYNCFLAGS) --exclude '*.html' --exclude '*.xml' --exclude '*.gz' --exclude '*.br' --exclude-from .rsyncignore $(OUTPUT_DIR)/gemini/ $(OUTPUT_DIR)/about $(OUTPUT_DIR)/posts $(OUTPUT_DIR)/publickey.* $(GEMINI_RSYNC_DEST)/ --delete
rsync $(RSYNCFLAGS) --exclude '*.html' --exclude '*.xml' --exclude '*.xhtml' --exclude '*.gz' --exclude '*.br' --exclude-from .rsyncignore $(OUTPUT_DIR)/gemini/ $(OUTPUT_DIR)/about $(OUTPUT_DIR)/posts $(OUTPUT_DIR)/publickey.* $(GEMINI_RSYNC_DEST)/ --delete
.PHONY: deploy
deploy: deploy-html deploy-gemini
## stuff for the staging server
.PHONY: test-staging
test-staging: deploy-html
yq e '.ci .collect .url | .[]' .lighthouserc.yml | xargs npx hint -f codeframe
npx lhci autorun
.PHONY: all
all: test deploy
.PHONY: deploy-envs
deploy-envs:
@$(MAKE) NO_STATIC=1 HUGO_FLAGS='--gc' USER=seirdy@envs.net WWW_ROOT=/home/seirdy/public_html GEMINI_ROOT=/home/seirdy/public_gemini HUGO_BASEURL='https://envs.net/~seirdy/' OUTPUT_DIR=public_envs hugo
@$(MAKE) NO_STATIC=1 HUGO_FLAGS='--gc' USER=seirdy@envs.net WWW_ROOT=/home/seirdy/public_html GEMINI_ROOT=/home/seirdy/public_gemini HUGO_BASEURL='https://envs.net/~seirdy/' OUTPUT_DIR=public_envs lint-local deploy
.PHONY: deploy-prod
deploy-prod:
.PHONY: .prepare-deploy
.prepare-deploy:
@$(MAKE) clean
@$(MAKE) hugo
@$(MAKE) compress
@$(MAKE) xhtmlize
# deploy steps need to happen one at a time
.PHONY: deploy-prod
deploy-prod: .prepare-deploy
@$(MAKE) deploy
# linting and compression can happen in parallel
.PHONY: deploy-staging
deploy-staging:
@$(MAKE) HUGO_FLAGS='--gc' DOMAIN=staging.seirdy.one USER=deploy@seirdy.one OUTPUT_DIR=public_staging clean
@$(MAKE) HUGO_FLAGS='--gc' DOMAIN=staging.seirdy.one USER=deploy@seirdy.one OUTPUT_DIR=public_staging hugo
@$(MAKE) HUGO_FLAGS='--gc' DOMAIN=staging.seirdy.one USER=deploy@seirdy.one OUTPUT_DIR=public_staging compress
@$(MAKE) HUGO_FLAGS='--gc' DOMAIN=staging.seirdy.one USER=deploy@seirdy.one OUTPUT_DIR=public_staging deploy
.PHONY: deploy-onion
deploy-onion:
@$(MAKE) WWW_ROOT=/var/www/seirdy.onion HUGO_BASEURL='http://wgq3bd2kqoybhstp77i3wrzbfnsyd27wt34psaja4grqiezqircorkyd.onion/' OUTPUT_DIR=public_onion clean
@$(MAKE) WWW_ROOT=/var/www/seirdy.onion HUGO_BASEURL='http://wgq3bd2kqoybhstp77i3wrzbfnsyd27wt34psaja4grqiezqircorkyd.onion/' OUTPUT_DIR=public_onion hugo
@$(MAKE) WWW_ROOT=/var/www/seirdy.onion HUGO_BASEURL='http://wgq3bd2kqoybhstp77i3wrzbfnsyd27wt34psaja4grqiezqircorkyd.onion/' OUTPUT_DIR=public_onion compress
@$(MAKE) WWW_ROOT=/var/www/seirdy.onion HUGO_BASEURL='http://wgq3bd2kqoybhstp77i3wrzbfnsyd27wt34psaja4grqiezqircorkyd.onion/' OUTPUT_DIR=public_onion deploy-html
@$(MAKE) WWW_ROOT=/var/www/seirdy.onion HUGO_BASEURL='http://wgq3bd2kqoybhstp77i3wrzbfnsyd27wt34psaja4grqiezqircorkyd.onion/' OUTPUT_DIR=public_onion deploy-prod
# we only deploy html to the staging site
.PHONY: deploy-staging
deploy-staging:
@$(MAKE) HUGO_FLAGS='--gc' DOMAIN=staging.seirdy.one USER=deploy@seirdy.one OUTPUT_DIR=public_staging .prepare-deploy
@$(MAKE) HUGO_FLAGS='--gc' DOMAIN=staging.seirdy.one USER=deploy@seirdy.one OUTPUT_DIR=public_staging deploy-html
# we can lint and compress in parallel if cores are available
.PHONY: .lint-and-prepare-deploy
.lint-and-prepare-deploy:
@$(MAKE) clean
@$(MAKE) hugo
@$(MAKE) lint-local compress
@$(MAKE) xhtmlize
.PHONY: lint-and-deploy-staging
lint-and-deploy-staging:
@$(MAKE) HUGO_FLAGS='--gc' DOMAIN=staging.seirdy.one USER=deploy@seirdy.one OUTPUT_DIR=public_staging .lint-and-prepare-deploy
@$(MAKE) HUGO_FLAGS='--gc' DOMAIN=staging.seirdy.one USER=deploy@seirdy.one OUTPUT_DIR=public_staging deploy-html
.PHONY: deploy-envs
deploy-envs:
@$(MAKE) NO_STATIC=1 HUGO_FLAGS='--gc' USER=seirdy@envs.net WWW_ROOT=/home/seirdy/public_html GEMINI_ROOT=/home/seirdy/public_gemini HUGO_BASEURL='https://envs.net/~seirdy/' OUTPUT_DIR=public_envs .lint-and-prepare-deploy
@$(MAKE) NO_STATIC=1 HUGO_FLAGS='--gc' USER=seirdy@envs.net WWW_ROOT=/home/seirdy/public_html GEMINI_ROOT=/home/seirdy/public_gemini HUGO_BASEURL='https://envs.net/~seirdy/' OUTPUT_DIR=public_envs deploy

View file

@ -25,7 +25,7 @@
</li>
{{ range .Site.Menus.main -}}
{{ $isCurrent := false }}
<li itemProp="hasPart" itemscope="" itemtype="https://schema.org/SiteNavigationElement">
<li itemprop="hasPart" itemscope="" itemtype="https://schema.org/SiteNavigationElement">
<a href="{{ .URL }}" itemprop="url" {{- if or (eq $currentPage.RelPermalink .URL) ($currentPage.HasMenuCurrent "main" .) -}}{{- $isCurrent = true }} aria-current="page"{{- end -}}>
{{- if or $isCurrent (eq $currentPage.Section .Title) -}}
<strong itemprop="name">{{- .Name -}}</strong>

20
scripts/compress.sh Normal file
View file

@ -0,0 +1,20 @@
#!/bin/sh
# takes three args:
# 1. output dir
# 2. "gzip" or "brotli"
# 3. ECT zopfli compression level
set -e -u
output_dir="$1"
format="$2"
alias find_compressible='find "$output_dir" -type f \( -name "*.html" -o -name "*.xml" -o -name "*.webmanifest" -o -name "*.*.svg" \)'
if [ "$format" = "gzip" ]; then
compress_level="$3"
find_compressible -exec ect -quiet -"$compress_level" -gzip {} \;
elif [ "$2" = "brotli" ]; then
find_compressible -exec brotli -Z -- {} \;
fi

12
scripts/xhtmlize.sh Normal file
View file

@ -0,0 +1,12 @@
#!/bin/sh
# takes an arg for the output dir.
# copies every .html file to an equivalent .xhtml file.
# does the same for compressed html files.
# this means that every index.html file has an equivalent index.xhtml file.
# content negotiation allows an agent to pick html or xhtml.
# too lazy to DRY this shit
find "$1" -type f -name '*.html' -exec sh -c 'cp "$0" "${0%*.html}.xhtml"' {} \;
find "$1" -type f -name '*.html.gz' -exec sh -c 'cp "$0" "${0%*.html.gz}.xhtml.gz"' {} \;
find "$1" -type f -name '*.html.br' -exec sh -c 'cp "$0" "${0%*.html.br}.xhtml.br"' {} \;
# done