Skip to content

News section and a live highlights section on the landing page - #372

Merged
neuromechanist merged 26 commits into
stagingfrom
feature/issue-371-news
Sep 29, 2026
Merged

neuromechanist merged 26 commits into
stagingfrom
feature/issue-371-news

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Refs #371. Backend: nemarOrg/nemar-cli#1553 (issue nemarOrg/nemar-cli#1551). Closes does not fire on staging, so close #371 by hand after merge.

What changed

Landing page. The two feature cards under the hero ("Assess before you analyze", "Analyze in place or download") are replaced by three live columns:

  • What's new on NEMAR: the newest post with its banner, summary, and Read more link, plus the next two as compact rows.
  • Most cited datasets: the top five by citation count, each linking to its page on the citation dashboard, with a bar showing its count against the top one.
  • Latest datasets: the five newest datasets NEMAR hosts, each linking to its dataset page.

Each column is fetched in parallel with the hero stats on the decorative deadline and fails soft: a failed or empty column is dropped and the rest widen. A partial render is edge-cached for 60 s instead of 10 min.

"Most cited last month" (a month because citations arrive too slowly for a week) is not possible yet: nothing records when a citation was found, and diffs of the citation repository's history are dominated by pipeline re-runs (nm000275 went from 100 to 636 after a dedupe backfill). The column shows all-time counts until nemarOrg/nemar-citations#247 publishes a real monthly signal.

News section.

  • /news: the newest post at full width, then a month timeline with the day on the rail. RSS at /news/feed.xml.
  • /news/<slug>: title, summary, banner, Markdown body with figures and captions, reading time, copy link, NewsArticle JSON-LD, and three more posts. A body's top heading level always renders as h2, under the title's h1.
  • /news/media/<sha256>.<ext>: post images, streamed from the API's R2 bucket and served same-origin and immutable, so CSP img-src stays 'self' (ADR 0020). Host-neutral, so the admin editor on app.nemar.org shows them too.
  • Social cards: a 1200x630 card per post, rendered at build time like the dataset cards (WebP banners converted with sharp when it is available) and refreshed by the rebuild cron. /og/news/<slug>.png redirects to the card, or to the post's banner until the next build renders one.
  • News is in the nav, the footer, the sitemap, and llms.txt.

Admin. A News tab at /admin/news lists every post with its state (draft, scheduled, published) and which three lead the home page. The editor writes Markdown with a live preview rendered by the same code the article uses, uploads a banner and inline images (button, drop, or paste), and saves, schedules (a future date), backdates, or deletes. Unlike notices, posts are editable.

Markdown renderer. Opt-in allowImage renders standalone image lines as figures (only /news/media/ paths for news), and headingOffset shifts heading levels. README rendering is unchanged.

Seed content. scripts/seed-news.mjs creates the first five posts with an admin API key, dated by the release that first shipped each feature to nemar.org: ORCID sign-in and the streaming viewer (2026-07-29, v0.2.0), HED and SCORE annotation (2026-09-02, v0.2.5), anonymous deposits (2026-09-16, v0.2.14 and nemar-cli 0.10.4), and the NEMAR Assistant (2026-09-24, v0.2.18). Idempotent; banners are converted to WebP when ImageMagick is present.

Review round

A Sonnet review found 12 issues; all are fixed in separate commits:

  • Security, pre-existing, also affects dataset READMEs: safeUrl denylisted javascript: by prefix, so a leading control character slipped a script URL through. It now allowlists http, https, and mailto on the scheme read with control characters removed. The same pass fixes double-escaped query strings, emphasis inside URLs, and a link nested in a link.
  • Pagination sent page 1 of the news to /discover; it takes a basePath now, and disabled Previous/Next are not focusable.
  • /news answers 503 when the list fails; the OG route checks the post is still public; "Updated" no longer appears on every backdated post; Copy link uses the canonical URL; the sitemap fetches news in parallel and short-caches a partial result.
  • Editor: no TypeError on the Visibility toggle; images must be described (placeholder instead of the file name); publishing an old draft warns and offers Now; the date hint names the time zone; captions may contain parentheses.

Deploy order

nemar-cli#1553 must reach an environment before this does: without /news, the landing news column is simply absent, but /news itself says the news could not load. Create the R2 buckets, promote nemar-cli, seed, then promote this.

Test plan

  • bun run test: 2,603 passed (new: news helpers, heading normalization, Markdown figures, highlights against captured catalog fixtures, RSS, social card, sitemap, llms.txt, host routing, admin tabs)
  • bun run typecheck: 0 errors; bun run lint: clean
  • astro build succeeds; generate:news-og exits 0 and renders nothing while the API has no /news
  • End to end against nemar-cli#1553 run locally (its real news, admin, and auth routes on a fully migrated in-memory D1 and Miniflare's local R2; catalog calls passed through to production), with a real admin web session:
    • seed-news.mjs created all five posts (banners 94 to 393 KB as WebP) and skipped all five on a re-run
    • Landing shows all three columns; /news, an article, the feed, and the OG redirect (to the banner, before a card exists) render; an unknown slug is a 404
    • /news/media/<file> serves 200 image/webp, immutable, nosniff; the backend answers 304 to If-None-Match
    • Admin: anonymous is redirected; the list shows states and the three home-page posts; the editor fills the slug from the title, uploads a dropped banner and a pasted inline image, previews, refuses a missing banner description beside the field, saves a future-dated post as Scheduled (hidden publicly, 404), shows a slug conflict beside the field, and deletes through the confirm dialog
    • Light and dark, desktop and 390 px, no horizontal scroll
    • After the review fixes, against the fixed backend: Visibility toggles without page errors, a pasted image's placeholder is selected and blocks saving until replaced, Now updates the date, and a full-body PUT saves
  • On test.nemar.org once nemar-cli#1553 deploys to dev and the posts are seeded there

Pure helpers for slugs, media URLs, categories, dates in NEMAR's time zone, month grouping, NewsArticle JSON-LD, and editor-side validation; a wire client for the public and admin news endpoints (nemar-cli#1551). Unit tested.
An allowImage predicate turns standalone image lines into figures with optional captions, and headingOffset shifts heading levels. READMEs keep the old behavior: without the option, image lines are still stripped. Unit tested.
Three columns under the hero: the latest news, the most cited datasets (linking to the citation dashboard), and the latest datasets. Each fails soft to a missing column. Adds news category marker tokens for both themes. Helpers tested against captured catalog fixtures.
/news lists posts newest first: the newest at full width, the rest on a month timeline. /news/<slug> renders the Markdown body with figures, NewsArticle JSON-LD, and a copy-link action. /news/media/<file> serves post images same-origin (host-neutral) so img-src stays 'self'.
/news/feed.xml carries the 20 newest posts with nemar.org links; a failed list answers 503 rather than an empty feed. Unit tested.
A 1200x630 card per post, rendered at build time like the dataset cards and refreshed by the rebuild cron. /og/news/<slug>.png redirects to the card, or to the post's banner until the next build renders one. Never fails the build.
/admin/news lists every post with its state (draft, scheduled, published) and which ones lead the home page. The editor at /admin/news/new and /admin/news/<id> writes Markdown with a live preview, uploads a banner and inline images (button, drop, or paste), and saves, schedules, or deletes a post.
ORCID sign-in and the streaming viewer (2026-07-29), HED and SCORE annotation (2026-09-02), anonymous deposits (2026-09-16), and the NEMAR Assistant (2026-09-24), each dated by the release that first shipped it to nemar.org. The script uploads banners (as WebP when ImageMagick is present) and creates the posts with an admin API key; it is idempotent.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 472011d
Status: ✅  Deploy successful!
Preview URL: https://59c0c4c3.nemar-website.pages.dev
Branch Preview URL: https://feature-issue-371-news.nemar-website.pages.dev

View logs

Crop banners from the top, where an interface screenshot carries its meaning; put each column's link right under its list instead of bottom-aligned across the row; give the news column a one-line note so first rows align.
Biome rewrites a generic arrow's <T,> to <T>, which astro check parses as JSX in .astro frontmatter.
A post body's top heading level now renders as h2 whatever level the author used (newsHeadingOffset, tested), so the outline never skips from h1 to h3. The text measure is in rem so the header and body columns share an edge.
Also crop the index and admin thumbnails from the top.
Also match the preview to the article: normalized headings, rem measure, top crop.
Like the other build scripts, so astro check does not need Bun's types.
safeUrl denylisted javascript: by prefix, so a leading control character (which browsers strip) slipped a script URL through; it now allowlists http, https, and mailto, reading the scheme with control characters and whitespace removed, and leaves relative URLs alone. This renderer also serves dataset READMEs. Links and code spans are held out before emphasis, which fixes double-escaped query strings, emphasis inside URLs, and a link nested in a link. Captions may contain parentheses. Tested.
Pagination hardcoded /discover for page 1, so page 2 of the news linked back to Discover; it takes a basePath now (Discover's default unchanged), and disabled Previous/Next render without an href so they are no longer focusable. A failed /news list answers 503 instead of a 200 error page.
The OG route checks the post is still public before redirecting to its card, so a deleted or unpublished post stops offering one at once. "Updated" appears only for an edit a day after the post was both written and dated, not on every backdated post. Copy link copies the canonical nemar.org URL, also on app.nemar.org.
In parallel rather than after it, and a sitemap missing its posts because the news list failed is cached for a minute, not an hour.
Uploaded body images get a selected "Describe this image" placeholder instead of the file name, and saving is refused until every image is described (undescribedImages, tested). Toggling Visibility no longer throws (a radio group is not an element). Publishing an old draft warns that it will list below newer posts and offers Now; the date hint names the time zone. The banner error is announced.
Biome's noControlCharactersInRegex rejects a NUL in a regex, which failed CI lint.
The backend ADR was renumbered when dev took 0075.
neuromechanist added a commit to nemarOrg/nemar-cli that referenced this pull request Sep 29, 2026
Adds the news_posts table (migration 0087), public GET /news, /news/:slug, /news/media/:file, admin CRUD with a raw image upload stored in the NEWS_MEDIA R2 bucket (nemar-news-media, nemar-news-media-dev), and ADR 0076. Refs #1551; website half nemarOrg/website#372. Tested: news suites 90 pass, tsc clean, migrations:d1-check, and end to end with the website against a local harness.
@neuromechanist
neuromechanist merged commit 1b08d1c into staging Sep 29, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-371-news branch September 29, 2026 18:35
neuromechanist added a commit to nemarOrg/nemar-cli that referenced this pull request Sep 29, 2026
* fix: type news media by name, not metadata

GET /news/media/:file now always sends the Content-Type its regex-locked
file extension implies, so a bad metadata write on the R2 object can never
make the API origin serve text/html.

Tested: the media route tests now run the public news routes in workerd
through Miniflare, which reaches the 200 branch bun cannot; the new test
fails on the old code (text/html) and passes (22 pass).

* fix: bound news published_at to 2000-2100

zod accepted 9999-12-31T23:59:59-12:00, which SQLite datetime() turns
into NULL (a 500 from the NOT NULL insert), and 0000-01-01T00:00:00+14:00,
stored as year -0001. The year as written must now be 2000 through 2100,
so both are a 400 naming published_at.

Tested: new cases for both extremes on POST and PUT, the years just
outside, and the accepted edges; they fail on the old code (500, 201) and
pass (70 pass).

* feat: audit news post create, update, delete

Each admin write now inserts an audit_log row (news_post_created,
news_post_updated, news_post_deleted; resource_type news_post, resource_id
the post id; details with id, slug, status, published_at and the actor's
username) in the same D1 batch as the write, so a failed audit insert
fails the request with nothing written. The row is read from the post
itself (INSERT ... SELECT) because a create's id does not exist until its
INSERT runs; for update and delete this also means a 404 writes no row.

Tested on real SQLite migrations: rows for all three writes, none for
refused or missed writes, and a trigger-failed audit insert rolls each
write back; the 5 new tests fail on the old code (75 pass).

* feat: audit news image uploads

An upload publishes: the object is readable by anyone with its URL, and
the API can neither list nor delete it. POST /admin/news/media now writes
a news_media_uploaded row (resource_id the file name; details with url,
type, size, already_stored, actor) before the R2 put, so an audit insert
that fails leaves nothing stored. Re-uploads of existing bytes are
audited too.

Tested: rows for a new and a repeated upload, none for every refusal,
and a trigger-failed audit insert stores nothing; the 2 new tests fail on
the old code (24 pass).

* docs: say why the admin news list keeps bodies

Trimming GET /admin/news to the summary columns would empty the website's
admin list: its parseAdminNewsList (nemarOrg/website#372) drops any row
without a string body. The list keeps full posts until the website parses
it as summaries; the test now pins the body on every row.

Tested: news-routes.test.ts (75 pass).

* docs: ADR 0076 recall, cache window, deploy token

Adds an Operations section: how to recall a mistaken image (R2 object
delete with --remote, the API and website cache purges, the website
redeploy), how long a post stays visible after unpublish or delete from
the public routes' Cache-Control, and why the deploy token needs R2 (run
36610376353 attempt 1). Also records the new audit rows.

Tested: test/adr-index.unit.test.ts.
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.

1 participant