6 KiB
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
Everything below can also be set in the admin, under Panel → Site
settings (superadmins only): the site's name, description, preview
image, favicon and home-screen icon, each static page's title and intro,
and whether search engines may list the site. A setting there wins; a
blank one falls back to site.json. The indexing switch is per
database, so the dev server can be off while production is on, from the
same build.
| 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. |
| The site's pages (Retreats, Community, History…) | Admin → Pages → Page management (site_pages). The page's heading and intro read the same row, so they can't drift. Disabled pages are noindex and out of the sitemap; hidden ones are a 404 to search engines. |
| 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
-
The API needs to find two files. Both default to the repo layout (
site.jsonat the root, the build indist/), which isn't how the server is deployed: the deploy copiesserver/into/srv/ngu-api, so neither file is next to it. Copysite.jsonthere with each deploy (eg. rsync it to/srv/ngu-api/site.json) and set both on thengu-apiunit:[Service] Environment=SITE_CONFIG=/srv/ngu-api/site.json Environment=SITE_INDEX=/path/to/the/built/site/index.htmlindex.htmlis reread when it changes, so a frontend deploy doesn't need an API restart. -
In the nginx site, serve files that exist, send everything else to the API, and fall back to the plain
index.htmlif the API is down, so the site still loads (with default previews) during a restart:# Shared by every block that sends a page to the API. # (Or repeat these lines in each block, as nginx-dev does.) # proxy_http_version 1.1; # proxy_set_header Host $host; # proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # proxy_set_header X-Forwarded-Proto $scheme; location = /sitemap.xml { proxy_pass http://127.0.0.1:3001; } # The home page needs its own block: try_files would otherwise find # the site's folder and serve index.html without asking the API. location = / { proxy_pass http://127.0.0.1:3001; proxy_intercept_errors on; error_page 500 502 503 504 = @static; } location / { try_files $uri @page; } location @page { proxy_pass http://127.0.0.1:3001; proxy_intercept_errors on; error_page 500 502 503 504 = @static; } location @static { try_files /index.html =404; } # (A block that adds headers of its own, eg. Cache-Control, must # repeat the server-level HSTS line: docs/security-headers.md.) # From the API, so Site settings' indexing switch applies; the # build's own robots.txt if the API is down. location = /robots.txt { proxy_pass http://127.0.0.1:3001; proxy_intercept_errors on; error_page 500 502 503 504 = @file; } location @file { try_files $uri =404; } # Uploads are bigger than the /api/ block's 64k limit allows. location = /api/admin/media { proxy_pass http://127.0.0.1:3001; client_max_body_size 26m; proxy_read_timeout 60s; } # The admin's saves send a record whole (every content block, # schedule entry and sub-item), well over 64k for a big page or # event: nginx answers 413 "Too large for the web server" without # this. A longer prefix than /api/, so it wins; the exact and # longer admin blocks (media, files, import, clips) still win over # it. Same proxy_set_header lines as /api/. location /api/admin/ { proxy_pass http://127.0.0.1:3001; client_max_body_size 4m; proxy_read_timeout 30s; }Keep the existing
/api/and/uploads/blocks; they're more specific and still win. Use the port the API listens on. A 404 from the API (a record that doesn't exist) goes through as it is; 500 to 504 fall back to the plain page.A dev or test server should also send
X-Robots-Tag: noindex, nofollowand its own blockingrobots.txt, since it shares the production build's settings: seenginx-devin the repo root. -
Check it:
curl -s https://nextgenerationofunity.org/events/<id> | grep og:titleshould show the event's name, and Facebook's Sharing Debugger orhttps://www.opengraph.xyzwill show the preview. -
Tell Google: add the site in Google Search Console and submit
https://nextgenerationofunity.org/sitemap.xml.