Improved the bootstrap script to write the canonical site origin and also, fixed some nasty bugs.
This commit is contained in:
+26
-7
@@ -31,7 +31,7 @@ PLACEHOLDER_URL_PATTERN='https://site\.example\.com'
|
||||
|
||||
# --- Prompts ------------------------------------------------------------------
|
||||
|
||||
printf 'Site display name (PascalCase, e.g. Berlin) [Site]: '
|
||||
printf 'Site display name (PascalCase, e.g. Acme) [Site]: '
|
||||
read -r NAME
|
||||
NAME="${NAME:-Site}"
|
||||
|
||||
@@ -54,7 +54,7 @@ case "$NAME" in
|
||||
esac
|
||||
|
||||
DEFAULT_SLUG="$(printf '%s' "$NAME" | tr '[:upper:]' '[:lower:]')"
|
||||
printf 'Project slug (lowercase, used for owner/db/compose, e.g. loud-berlin) [%s]: ' "$DEFAULT_SLUG"
|
||||
printf 'Project slug (lowercase, used for owner/db/compose, e.g. acme-web) [%s]: ' "$DEFAULT_SLUG"
|
||||
read -r SLUG
|
||||
SLUG="${SLUG:-$DEFAULT_SLUG}"
|
||||
|
||||
@@ -75,7 +75,7 @@ case "$SLUG" in
|
||||
;;
|
||||
esac
|
||||
|
||||
printf 'Canonical site URL (scheme + host, e.g. https://berlin.example.com) [%s]: ' "$PLACEHOLDER_URL"
|
||||
printf 'Canonical site URL (scheme + host, e.g. https://acme.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
|
||||
@@ -99,7 +99,7 @@ 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 " canonical URL: $URL (robots.txt, sitemap.xml, String.Site.origin)"
|
||||
echo
|
||||
printf 'Apply these values? [y/N]: '
|
||||
read -r CONFIRM
|
||||
@@ -136,6 +136,13 @@ rewrite "$W/Sources/Library/Public/Extensions/String+Constants.swift" \
|
||||
-e "s/SiteWebsite/${NAME}Website/g" \
|
||||
-e "s/= \"site\"/= \"${SLUG}\"/g"
|
||||
|
||||
# Canonical origin. Left empty for the placeholder, which keeps the HTTPS
|
||||
# redirect off rather than aimed at a reserved example domain.
|
||||
if [ "$URL" != "$PLACEHOLDER_URL" ]; then
|
||||
rewrite "$W/Sources/Library/Public/Extensions/String+Constants.swift" \
|
||||
-e "s|^ public static let origin = \"\"\$| public static let origin = \"${URL}\"|"
|
||||
fi
|
||||
|
||||
# Local env example.
|
||||
rewrite "$W/.env.local" \
|
||||
-e "s/SiteWebsite/${NAME}Website/g" \
|
||||
@@ -162,6 +169,17 @@ rewrite "$W/docker-compose.override.yml" \
|
||||
rewrite "$W/Makefile" \
|
||||
-e "s/),site)/),${SLUG})/g"
|
||||
|
||||
# Web app manifest: the identity shown by an install prompt.
|
||||
rewrite "$W/Resources/Static/site.webmanifest" \
|
||||
-e "s/^ \"short_name\": \"\"/ \"short_name\": \"${NAME}\"/" \
|
||||
-e "s/^ \"name\": \"\"/ \"name\": \"${NAME}\"/"
|
||||
|
||||
# Persistence integration test: its POSTGRES_TEST_* fallbacks address the local
|
||||
# container `make db-mount` creates, which is initialised from the slug.
|
||||
rewrite "Packages/Persistence/Tests/Cases/Public/Methods/ServiceTests.swift" \
|
||||
-e "s/?? \"site\"/?? \"${SLUG}\"/g" \
|
||||
-e "s/: \"site\",\$/: \"${SLUG}\",/"
|
||||
|
||||
# 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" \
|
||||
@@ -175,7 +193,9 @@ rewrite "$W/README.md" \
|
||||
-e "s/^# Site Website\$/# ${NAME} Website/" \
|
||||
-e "s/\*\*Site\*\*/**${NAME}**/" \
|
||||
-e "s/SiteWebsite/${NAME}Website/g" \
|
||||
-e "s/\`site\`/\`${SLUG}\`/g"
|
||||
-e "s/\`site\`/\`${SLUG}\`/g" \
|
||||
-e "s/\`Site\.xcodeproj\`/\`${NAME}.xcodeproj\`/g" \
|
||||
-e "s|^\`robots.txt\` and \`sitemap.xml\` need an absolute origin.*\$|\`robots.txt\` and \`sitemap.xml\` carry the absolute origin bootstrap wrote into them: ${URL}. Update both if the canonical origin ever changes.|"
|
||||
|
||||
# Xcode project: PBXProject name + directory.
|
||||
if [ -d "$XCODEPROJ" ]; then
|
||||
@@ -218,7 +238,6 @@ rm -f Scripts/bootstrap
|
||||
rmdir Scripts 2>/dev/null || true
|
||||
rm -f Makefile # root convenience Makefile (bootstrap only)
|
||||
rm -f README.md # template usage docs
|
||||
rm -rf .gitea # Gitea template metadata
|
||||
|
||||
# --- Done ---------------------------------------------------------------------
|
||||
|
||||
@@ -231,7 +250,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)
|
||||
- $W/Resources/Static/site.webmanifest (theme colours)
|
||||
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. Analytics ships OFF, and stays off until you opt in. To enable it: check
|
||||
|
||||
Reference in New Issue
Block a user