Add per-page search metadata, link previews and a sitemap
Page requests now go through the API (routes/pages.js), which fills the built index.html in for that path before the app loads: title, description, preview image, canonical URL, and structured data (Organization, Event, BlogPosting). Shared links preview the page itself. Unlisted records are noindex; missing ones return 404. /sitemap.xml lists every public, listed page. site.json is the one place for the site's name, address, default description and preview image, and each static page's title and intro, which the pages now read too. Indexing is switched on: robots.txt allows all but /admin and /api and names the sitemap. The browser tab title follows the page. nginx setup, with a fallback to the plain page if the API is down, is in docs/seo.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
71a470b66f
commit
64cb2ec56a
21 changed files with 777 additions and 29 deletions
80
docs/seo.md
Normal file
80
docs/seo.md
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# Search and link previews
|
||||
|
||||
Each page's HTML carries its own title, description, preview image,
|
||||
canonical address and, where it fits, structured data, so a link shared
|
||||
on Facebook, iMessage, Slack, Discord or X shows that page, and search
|
||||
engines see the right title before any JavaScript runs.
|
||||
|
||||
The API does this: nginx sends page requests to it, and it fills the
|
||||
built `index.html` in for that path (`server/src/routes/pages.js`, rules
|
||||
in `server/src/pageMeta.js`). It also serves `/sitemap.xml`.
|
||||
|
||||
## Where the words come from
|
||||
|
||||
| What | Where |
|
||||
| --- | --- |
|
||||
| Site name, address, default description | `site.json`: `title`, `url`, `description` (blank uses the front page's subhead) |
|
||||
| Default preview image | `site.json`: `openGraph.image`, eg. `/uploads/<file>` from Admin → Tools → Media. Blank means pages without their own image have none. |
|
||||
| Static pages (Retreats, Community, History…) | `site.json`: `pages`. The page's heading and intro read the same entry, so they can't drift. A new static page needs an entry. |
|
||||
| Records (events, organizations, teams, awards, people, posts) | The database: the record's name, then its tagline or first paragraph; its own image (an event's card background, else its logo; a post's cover; a person's photo; an organization's logo). SVGs aren't used as previews. |
|
||||
| Whether search may list it | `site.json` `robots.index` for the whole site; per record, published and listed is indexed, published but unlisted is `noindex`, anything else is a 404. `/admin` is always `noindex`. |
|
||||
|
||||
Structured data: Organization on the home page, Event on event pages,
|
||||
BlogPosting on posts.
|
||||
|
||||
`robots.txt` is written by the build (`vite.config.ts`): with indexing
|
||||
on it allows everything but `/admin` and `/api` and names the sitemap;
|
||||
with it off it blocks everything.
|
||||
|
||||
## Production setup
|
||||
|
||||
1. The API needs to find two files. Both default to the repo layout
|
||||
(`site.json` at the root, the build in `dist/`); set them on the
|
||||
`ngu-api` unit if the deploy puts them elsewhere:
|
||||
|
||||
```ini
|
||||
[Service]
|
||||
Environment=SITE_CONFIG=/srv/ngu-api/site.json
|
||||
Environment=SITE_INDEX=/path/to/the/built/site/index.html
|
||||
```
|
||||
|
||||
`index.html` is reread when it changes, so a frontend deploy doesn't
|
||||
need an API restart.
|
||||
|
||||
2. In the nginx site, serve files that exist, send everything else to
|
||||
the API, and fall back to the plain `index.html` if the API is down,
|
||||
so the site still loads (with default previews) during a restart:
|
||||
|
||||
```nginx
|
||||
location = /sitemap.xml {
|
||||
proxy_pass http://127.0.0.1:3001;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri @page;
|
||||
}
|
||||
|
||||
location @page {
|
||||
proxy_pass http://127.0.0.1:3001;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_intercept_errors on;
|
||||
error_page 502 503 504 = @static;
|
||||
}
|
||||
|
||||
location @static {
|
||||
try_files /index.html =404;
|
||||
}
|
||||
```
|
||||
|
||||
Keep the existing `/api/` and `/uploads/` blocks; they're more
|
||||
specific and still win. Use the port the API listens on.
|
||||
|
||||
3. Check it: `curl -s https://nextgenerationofunity.org/events/<id> | grep og:title`
|
||||
should show the event's name, and Facebook's Sharing Debugger or
|
||||
`https://www.opengraph.xyz` will show the preview.
|
||||
|
||||
4. Tell Google: add the site in Google Search Console and submit
|
||||
`https://nextgenerationofunity.org/sitemap.xml`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue