Prompt the canonical site URL during bootstrap script to rewrite website crawlers.

This commit is contained in:
2026-08-02 02:57:43 +02:00
parent a5ee02bb0b
commit 422560ec10
5 changed files with 112 additions and 18 deletions
+45
View File
@@ -24,6 +24,11 @@ fi
XCODEPROJ="./Site.xcodeproj"
# The placeholder origin the crawler files ship with. It is an RFC 2606 reserved
# domain, so an un-bootstrapped copy can never point a crawler at a real site.
PLACEHOLDER_URL="https://site.example.com"
PLACEHOLDER_URL_PATTERN='https://site\.example\.com'
# --- Prompts ------------------------------------------------------------------
printf 'Site display name (PascalCase, e.g. Berlin) [Site]: '
@@ -35,9 +40,31 @@ printf 'Project slug (lowercase, used for owner/db/compose, e.g. loud-berlin) [%
read -r SLUG
SLUG="${SLUG:-$DEFAULT_SLUG}"
printf 'Canonical site URL (scheme + host, e.g. https://berlin.example.com) [%s]: ' "$PLACEHOLDER_URL"
read -r URL
URL="${URL:-$PLACEHOLDER_URL}"
URL="${URL%/}" # the rewrites append their own path, so drop a trailing slash
# The URL is interpolated into a sed replacement (with `|` as the delimiter) and
# into the crawler files, so reject anything that is not a plain scheme + host.
case "$URL" in
http://* | https://*) ;;
*)
echo "error: the canonical site URL must start with http:// or https:// (got \"$URL\")." >&2
exit 1
;;
esac
case "$URL" in
*[!-A-Za-z0-9:/._~]*)
echo "error: the canonical site URL contains unexpected characters (got \"$URL\")." >&2
exit 1
;;
esac
echo
echo " display name : $NAME (server name \"${NAME}Website\", ${NAME}.xcodeproj)"
echo " slug : $SLUG (container owner, database name/user, compose project)"
echo " canonical URL: $URL (robots.txt sitemap reference, sitemap.xml entry)"
echo
printf 'Apply these values? [y/N]: '
read -r CONFIRM
@@ -95,6 +122,14 @@ rewrite "$W/docker-compose.override.yml" \
rewrite "$W/Makefile" \
-e "s/),site)/),${SLUG})/g"
# Crawler files: the absolute origin they must carry. `|` is the sed delimiter,
# since both the placeholder and the replacement contain slashes.
rewrite "$W/Resources/Static/robots.txt" \
-e "s|${PLACEHOLDER_URL_PATTERN}|${URL}|g"
rewrite "$W/Resources/Static/sitemap.xml" \
-e "s|${PLACEHOLDER_URL_PATTERN}|${URL}|g"
# Service README.
rewrite "$W/README.md" \
-e "s/^# Site Website\$/# ${NAME} Website/" \
@@ -147,6 +182,7 @@ Next steps:
- $W/Sources/Library/Catalogs/Localizable.xcstrings (copy)
- $W/Sources/Library (landing / 404 pages)
- $W/Resources/Static (css, js, favicon, icons)
- $W/Resources/Static/site.webmanifest (name / short_name)
2. Set a real database password in a git-ignored $W/.env
(the committed .env.local defaults the password to the slug — do NOT ship that).
3. Point the git remote at your new repository:
@@ -157,3 +193,12 @@ Next steps:
The Persistence package still ships an ExampleRecord / ExampleRepository sample
model — replace it with your real domain models when you add persistence.
EOF
if [ "$URL" = "$PLACEHOLDER_URL" ]; then
cat <<EOF
WARNING: the canonical site URL was left as the placeholder "${PLACEHOLDER_URL}".
Set the real origin in $W/Resources/Static/robots.txt and sitemap.xml before
going live, or crawlers will be pointed at a reserved example domain.
EOF
fi