Skip to content

feat: page tags, link previews and sitemap for SEO - #4318

Merged
kusssal merged 6 commits into
developfrom
feat/1410-seo-link-previews
Dec 2, 2026
Merged

kusssal merged 6 commits into
developfrom
feat/1410-seo-link-previews

Conversation

@kusssal

@kusssal kusssal commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

List of changes

  • Add per-page title, description, canonical URL, Open Graph/X tags and structured data. The backend's new /seo routes write them and the frontend's nginx includes them in index.html (SSI, 500 ms timeout, site-wide defaults on any failure)
  • Add a generated 1200×630 preview card for each governance action, DRep and forum proposal, plus sitemap.xml and robots.txt
  • Add 301 redirects from the URLs before feat(frontend): resource URLs without /connected, with legacy redirects #4310 to the new ones
  • Add the share button's link by CIP-129 id, and in-place tag updates on in-app navigation
  • Add settings: SEO_BACKEND_URL, SITE_URL, SEO_NOINDEX (frontend) and GOVTOOL_SITE_URL, GOVTOOL_SEO_URL_SCHEME (backend). Set SEO_NOINDEX=true on every site except gov.tools

Checklist

@kusssal
kusssal changed the base branch from ci/secret-and-vuln-scanning to develop November 25, 2026 07:00
@kusssal kusssal closed this Nov 25, 2026
@kusssal kusssal reopened this Nov 25, 2026
@kusssal
kusssal marked this pull request as ready for review November 25, 2026 07:07

@mesudip mesudip left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parts I checked look right:

  • the escaping of user text into HTML, attributes and JSON-LD (src/seo/text.ts, render.ts), and the input caps and linear patterns;
  • the card renderer's limits;
  • the forum client never holding up a page load;
  • do-not-list DReps kept out of the sitemap;
  • nginx dropping the gateway's headers before calling the backend.

Backend npm run verify (30 suites, 636 tests) and the frontend's tsc, lint and vitest pass. Two nginx problems need fixing. I reproduced both by running this PR's nginx.conf and docker-entrypoint.sh in the stock nginx 1.30.6 image, with the brotli directives removed because that image lacks the module.

Must fix

  1. Open redirect off gov.tools.

    • The rule is govtool/frontend/nginx.conf:33: location ~* ^/connected(/.+)$ { return 301 $1$is_args$args; }, with absolute_redirect off.
    • GET /connected/%5Cevil.example answers 301 Location: /\evil.example.
    • GET /connected/%09/evil.example answers 301 Location: /<TAB>/evil.example.
    • The URL standard treats \ as / in http(s) and strips tabs, so browsers resolve both to https://evil.example/. That makes any gov.tools link usable for phishing.
    • The other redirect rules put a fixed segment first and stay on-site.
    • Fix: either drop the server-side /connected rule (the app's getCurrentUrl already rewrites it), or constrain the capture, e.g. ^/connected(/[A-Za-z0-9_-][^\\\s]*)$. Add both payloads to scripts/check-seo-nginx.sh.
  2. SEO_NOINDEX doesn't reach every response.

    • An add_header inside a location turns off the server-level add_headers there.
    • With SEO_NOINDEX=true, the /og/ cards and /budget-proposals-2025/*.json are served without X-Robots-Tag (as is maintenance.json), so a test site's cards can be indexed.
    • govtool/frontend/AGENTS.md:103 says "everywhere", and check-seo-nginx.sh:167-168 checks only / and /robots.txt.
    • docs/nginx.conf.template:5-7 documents exactly this trap.
    • Fix: send the header in those locations too, e.g. from a variable the entrypoint sets, and test /og/.

Should fix

  1. Orphaned doc comment. In src/drep/drep.service.ts:163-172 the new methods were inserted between withStoredProfile's doc comment and the method. That comment now sits above storedSeoDRep's, and withStoredProfile has none.

  2. Decision log. This D178 clashes with #4320's D178, so whichever merges second renumbers. It is also dated 2026-11-17, below D177 (2026-11-20), in a log kept newest-last.

  3. Stacked on #4317. The first commit here is #4317's (e1ca0e2). Please say so in the description, and merge #4317 first.

Worth considering

  1. Unknown paths get the noindex defaults (src/seo/pages.ts, defaults()). #4316 adds a public /activity page, which will need a row in src/seo/routes.ts.

  2. SEO_NOINDEX defaults to indexable (SEO_NOINDEX=${SEO_NOINDEX:-} in the Swarm stack), so every test site has to remember to set it. A default of noindex, with production opting in, fails safe.

  3. About 9.2 MB of Noto Sans JP OTF goes into git and the backend image; a subset would be enough.

@mesudip mesudip mentioned this pull request Dec 2, 2026
5 tasks done
@kusssal

kusssal commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

1. Open redirect. Fixed in 53d313a. The server-side /connected rule is gone; the app's getCurrentUrl still rewrites those links. Every other rule's target starts with a fixed segment, so it stays on gov.tools. check-seo-nginx.sh now sends both payloads, plus //, %2F%2F and %09 variants against /connected, /governance_actions and /drep_directory, and requires the Location to stay on-site. It also checks that an encoded CR LF never becomes a response header.

2. SEO_NOINDEX coverage. Fixed in 53d313a. X-Robots-Tag now comes from $seo_robots_tag (noindex or empty), which the entrypoint always defines. The server block and every location with its own add_header (/og/, /budget-proposals-2025/, /maintenance.json) send it. The check asserts it on a card, a budget JSON file, maintenance.json and a legacy 301, and that it is absent without SEO_NOINDEX. AGENTS.md notes the add_header rule.

3. Doc comment. Fixed in b86b2ce.

4. Decision log. Renumbered to D180 (#4320 has D178, #4322 D179) and dated 2026-12-02, in b86b2ce.

5. Stacking. #4317 is merged, so this PR's diff is now only its own commits.

6. Unknown paths. Deliberate: an unknown path gets noindex so a mistyped or removed URL is never indexed as a copy of the home page. /activity needs a row in src/seo/routes.ts; whichever of #4316 and this PR merges second adds it.

7. SEO_NOINDEX default. Kept indexable on purpose, because the two failures aren't symmetric. A test site that forgets the flag leaves a duplicate that ranks below gov.tools. Production forgetting an opt-in would drop gov.tools out of search for weeks, which is what this PR exists to fix. If the team prefers fail-safe, it's one default in the entrypoint and the stack.

8. Noto Sans JP size. Done, see the comment below.

@kusssal
kusssal force-pushed the feat/1410-seo-link-previews branch from 5131f7f to b86b2ce Compare December 2, 2026 08:39
@kusssal

kusssal commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

8. Noto Sans JP size. Subset to Latin, Greek, Cyrillic, kana, CJK symbols and JIS X 0208's non-kanji rows and level-1 kanji: 9.2 MB down to 2.3 MB for both weights, and about 135 MB less resident memory once the fonts load. A level-2 kanji now gets the default card through the existing cmap check, never boxes. The subset replaces the fonts in the original backend commit, so the 9 MB files never reach develop's history. The branch was force-pushed for that; the commit IDs in my comment above are updated. npm run verify passes (636).

@kusssal
kusssal requested a review from mesudip December 2, 2026 09:36
@kusssal
kusssal merged commit 08638f1 into develop Dec 2, 2026
18 checks passed
@kusssal
kusssal deleted the feat/1410-seo-link-previews branch December 2, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

X, Social thumbnails for proposals Suggestion to improve SEO

2 participants