diff --git a/.github/workflows/test-tos-gate.yml b/.github/workflows/test-tos-gate.yml new file mode 100644 index 00000000..aba8584d --- /dev/null +++ b/.github/workflows/test-tos-gate.yml @@ -0,0 +1,38 @@ +--- +name: ToS gate tests + +on: + push: + branches: + - master + - main + paths: + - main.py + - docs/javascripts/tos-gate.js + - overrides/main.html + - mkdocs.yml + - docs/** + - tests/test_tos_gate.py + - requirements.txt + pull_request: + paths: + - main.py + - docs/javascripts/tos-gate.js + - overrides/main.html + - mkdocs.yml + - docs/** + - tests/test_tos_gate.py + - requirements.txt + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install dependencies + run: pip install -r requirements.txt + - name: Run ToS gate tests + run: pytest tests/test_tos_gate.py -v diff --git a/README.md b/README.md index f56245ed..df23c9ea 100644 --- a/README.md +++ b/README.md @@ -121,37 +121,73 @@ instead. To embed an video simply type the following in markdown: ### Embedding ToS checkbox -A ToS acceptance checkbox can be added to any release page to gate binary -downloads behind a user acknowledgement. The feature is opt-in per page. +A ToS acceptance checkbox can be added to any page to gate binary downloads +and/or prose content behind a user acknowledgement. The feature is opt-in per +page. -**1. Add the checkbox macro** above the content you want to protect: +#### Gating download buttons + +Use the `tos_gated_downloads` macro and pass a unique `section_id` together +with the list of files. Use the **group format** to preserve subsection +headings matching the original release layout: ```md -{{ tos_checkbox("unique-section-id") }} +{{ tos_gated_downloads("vendor-board-vXYZ-binaries", [ + {"group": "Raw firmware image", "note": "(vendor_board_vX.Y.Z.rom)", "items": [ + {"label": "sha256", "url": "https://dl.3mdeb.com/.../file.rom.sha256"}, + {"label": "sha256.sig", "url": "https://dl.3mdeb.com/.../file.rom.sha256.sig"} + ]}, + {"group": "SBOM CycloneDX", "items": [ + {"label": "sbom.json", "url": "https://dl.3mdeb.com/.../file.sbom.json"}, + {"label": "sha256", "url": "https://dl.3mdeb.com/.../file.sbom.json.sha256"}, + {"label": "sha256.sig", "url": "https://dl.3mdeb.com/.../file.sbom.json.sha256.sig"} + ]} +]) }} ``` -**2. Wrap the protected content** in an HTML div with a matching `id`: +Download links are **not** emitted into the HTML source - they are +base64-encoded in a `data-payload` attribute and injected by `tos-gate.js` only +after the user checks the box. This keeps URLs out of page source and prevents +them from being indexed. + +Download buttons with groups example: +[`docs/variants/gigabyte_mz33-ar1/releases.md`][tos-example] + +#### Optional argument (`tos_url`) + +Overrides the default Terms of Service link: ```md -