Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# build it (a doc that breaks the site shows up in review); main deploys it to GitHub Pages.
# The repository variable GOATCOUNTER (a GoatCounter site code) turns on visitor counts.
# The repository variable CONTEXT7_LIBRARY (e.g. /1bit-monster/engine) turns on the docs chat widget.
# The repository variable DOCS7_SITE (the Docs7 site id, a UUID) turns on Docs7 docs analytics.
name: pages

on:
Expand Down Expand Up @@ -49,6 +50,7 @@ jobs:
env:
GOATCOUNTER: ${{ vars.GOATCOUNTER }}
CONTEXT7_LIBRARY: ${{ vars.CONTEXT7_LIBRARY }}
DOCS7_SITE: ${{ vars.DOCS7_SITE }}
run: |
python3 -m pip install --quiet markdown==3.10.3
python3 tools/site.py _site
Expand Down
17 changes: 12 additions & 5 deletions tools/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,19 @@ def render(text):


def analytics():
out = []
code = os.environ.get("GOATCOUNTER", "").strip()
if not code:
return ""
if not re.fullmatch(r"[a-z0-9-]+", code):
sys.exit(f"GOATCOUNTER must be a GoatCounter site code (letters, digits, dashes), not {code!r}")
return f'<script data-goatcounter="https://{code}.goatcounter.com/count" async src="https://gc.zgo.at/count.js"></script>'
if code:
if not re.fullmatch(r"[a-z0-9-]+", code):
sys.exit(f"GOATCOUNTER must be a GoatCounter site code (letters, digits, dashes), not {code!r}")
out.append(f'<script data-goatcounter="https://{code}.goatcounter.com/count" async src="https://gc.zgo.at/count.js"></script>')
# Docs7 (Context7's docs analytics): the site id from the Docs7 dashboard
site = os.environ.get("DOCS7_SITE", "").strip()
if site:
if not re.fullmatch(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", site):
sys.exit(f"DOCS7_SITE must be the Docs7 site id (a UUID), not {site!r}")
out.append(f'<script defer src="https://context7.com/docs7-analytics.js" data-site="{site}"></script>')
return "\n".join(out)


def chat_widget():
Expand Down
Loading