Author SHA1 Message Date
andwati 694f65faad Add stale branch cleanup workflow 2026-11-18 14:37:04 +03:00
andwatiandGitHub c7177720f9 Merge pull request #9 from andwati/fix/ga-measurement-id
Restore GA measurement ID
2026-10-07 11:35:35 +03:00
andwati 12f84af823 Restore the original GA measurement ID
PR #7 merged before the restore commit landed, leaving main on the wrong ID.
2026-10-07 11:34:09 +03:00
andwatiandGitHub dc0b223025 Merge pull request #8 from andwati/fix/cloudflare-csp
Allow Cloudflare Web Analytics in the CSP
2026-10-07 11:30:19 +03:00
andwati d931b47af2 Allow Cloudflare Web Analytics in the CSP
Cloudflare auto-injects beacon.min.js, which the CSP was blocking.
2026-10-07 11:29:43 +03:00
andwatiandGitHub dd6cc9b223 Merge pull request #7 from andwati/feat/google-analytics
Fix GA tagging and redirect legacy URLs
2026-10-07 11:23:18 +03:00
andwati e0f0ae7c7f Fix GA measurement ID and CSP, redirect legacy Hugo URLs
Use the GA4 measurement ID Search Console expects and allow Google Tag Manager/Analytics in the CSP so gtag is not blocked. Add 301s from the old /posts, /writings, /tags, /archive, /about and /index.xml URLs to their current routes to clear the Search Console 404s.
2026-10-07 11:20:31 +03:00
andwatiandGitHub 203ead6ef5 Merge pull request #6 from andwati/feat/google-analytics
Add Google Analytics
2026-09-30 14:29:41 +03:00
andwati 2c19e7ed1a Tidy gtag snippet indentation 2026-09-30 14:19:21 +03:00
andwati a06a93019f Only load analytics in production 2026-09-30 14:19:13 +03:00
andwati 77cc86ddf9 Add Google Analytics via next/script 2026-09-30 14:17:41 +03:00
andwatiandGitHub 2960dc622f Merge pull request #5 from andwati/feat/nextjs-site
Replace Astro/Strapi site with Next.js static export
2026-09-30 13:55:52 +03:00
3 changed files with 161 additions and 2 deletions
+85
View File
@@ -0,0 +1,85 @@
name: Delete stale branches
on:
schedule:
- cron: "0 3 * * 1"
workflow_dispatch:
inputs:
days:
description: Days without commits before a branch is stale
default: "60"
dry_run:
description: List stale branches without deleting them
type: boolean
default: false
permissions:
contents: write
pull-requests: read
env:
PROTECTED_BRANCHES: main staging prod master
STALE_DAYS: ${{ inputs.days || '60' }}
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run || 'false' }}
jobs:
delete-stale-branches:
name: Delete stale branches
runs-on: ubuntu-latest
steps:
- name: Ensure gh and jq are installed
env:
GH_VERSION: "2.63.2"
JQ_VERSION: "1.7.1"
run: |
set -euo pipefail
case "$(uname -m)" in
x86_64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
*) echo "unsupported architecture: $(uname -m)"; exit 1 ;;
esac
bin="$RUNNER_TEMP/bin"
mkdir -p "$bin"
if ! command -v jq >/dev/null 2>&1; then
curl -fsSL -o "$bin/jq" "https://github.com/jqlang/jq/releases/download/jq-${JQ_VERSION}/jq-linux-${arch}"
chmod +x "$bin/jq"
fi
if ! command -v gh >/dev/null 2>&1; then
curl -fsSL "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_${arch}.tar.gz" | tar -xz -C "$RUNNER_TEMP"
cp "$RUNNER_TEMP/gh_${GH_VERSION}_linux_${arch}/bin/gh" "$bin/gh"
fi
echo "$bin" >> "$GITHUB_PATH"
PATH="$bin:$PATH"
gh --version | head -1
jq --version
- name: Delete branches with no recent activity
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
default_branch=$(gh api "repos/$REPO" --jq .default_branch)
cutoff=$(date -u -d "$STALE_DAYS days ago" +%s)
open_heads=$(gh pr list --repo "$REPO" --state open --limit 1000 --json headRefName --jq '.[].headRefName')
gh api --paginate "repos/$REPO/branches?per_page=100" --jq '.[] | select(.protected | not) | .name' |
while read -r branch; do
if [ "$branch" = "$default_branch" ] || [[ " $PROTECTED_BRANCHES " == *" $branch "* ]]; then
continue
fi
if grep -qxF -- "$branch" <<< "$open_heads"; then
continue
fi
encoded=$(jq -rn --arg b "$branch" '$b | @uri')
committed=$(gh api "repos/$REPO/commits/$encoded" --jq .commit.committer.date)
if [ "$(date -u -d "$committed" +%s)" -ge "$cutoff" ]; then
continue
fi
if [ "$DRY_RUN" = "true" ]; then
echo "would delete $branch (last commit $committed)"
else
echo "deleting $branch (last commit $committed)"
gh api -X DELETE "repos/$REPO/git/refs/heads/$encoded"
fi
done
+18 -1
View File
@@ -58,6 +58,9 @@ const websiteLd = {
author: { "@type": "Person", name: site.name },
};
const isProd = process.env.NODE_ENV === "production";
const gaId = "G-9XLTKZF07C";
const umamiScript = process.env.PUBLIC_UMAMI_SCRIPT_URL;
const umamiId = process.env.PUBLIC_UMAMI_WEBSITE_ID;
@@ -81,7 +84,21 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
<body>
<JsonLd data={websiteLd} />
<Layout>{children}</Layout>
{umamiScript && umamiId && (
{isProd && (
<>
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gaId}');`}
</Script>
</>
)}
{isProd && umamiScript && umamiId && (
<Script defer src={umamiScript} data-website-id={umamiId} />
)}
</body>
+58 -1
View File
@@ -7,10 +7,67 @@ ignore-hidden-files = false
[advanced]
# Legacy Hugo URLs (/posts, /writings, /tags, ...) -> current routes. First match wins,
# so the trailing-slash variants Google crawled come before the bare ones.
[[advanced.redirects]]
source = "/posts/page/{*}/"
destination = "/writing"
kind = 301
[[advanced.redirects]]
source = "/posts/page/{*}"
destination = "/writing"
kind = 301
[[advanced.redirects]]
source = "/{posts,writings,tags,archive}/"
destination = "/writing"
kind = 301
[[advanced.redirects]]
source = "/{posts,writings}/{*}/"
destination = "/writing/$2"
kind = 301
[[advanced.redirects]]
source = "/{posts,writings}/{*}"
destination = "/writing/$2"
kind = 301
[[advanced.redirects]]
source = "/{posts,writings,tags,archive}"
destination = "/writing"
kind = 301
[[advanced.redirects]]
source = "/tags/{*}/"
destination = "/writing"
kind = 301
[[advanced.redirects]]
source = "/tags/{*}"
destination = "/writing"
kind = 301
[[advanced.redirects]]
source = "/about/"
destination = "/"
kind = 301
[[advanced.redirects]]
source = "/about"
destination = "/"
kind = 301
[[advanced.redirects]]
source = "/index.xml"
destination = "/rss.xml"
kind = 301
[[advanced.headers]]
source = "**"
[advanced.headers.headers]
Content-Security-Policy = "default-src 'self'; script-src 'self' 'unsafe-inline' https://utteranc.es https://analytics.andwati.com; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' https://analytics.andwati.com; frame-src https://www.youtube-nocookie.com https://utteranc.es; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests"
Content-Security-Policy = "default-src 'self'; script-src 'self' 'unsafe-inline' https://utteranc.es https://analytics.andwati.com https://www.googletagmanager.com https://static.cloudflareinsights.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://www.google-analytics.com https://www.googletagmanager.com; font-src 'self'; connect-src 'self' https://cloudflareinsights.com https://analytics.andwati.com https://www.google-analytics.com https://*.google-analytics.com https://*.analytics.google.com https://www.googletagmanager.com; frame-src https://www.youtube-nocookie.com https://utteranc.es; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests"
X-Frame-Options = "DENY"
X-Content-Type-Options = "nosniff"
Referrer-Policy = "strict-origin-when-cross-origin"