feat: frontend View links for pages + CPTs, and sitemap completeness#137
Conversation
View links (WordPress theme)
----------------------------
Generalize the headless permalink rewrite (previously posts-only) to every
post type with a Next.js route, so the admin "View Post"/"View Page" link,
admin bar, post-list action, and block editor all reach the live frontend:
- page → the page's own hierarchical URI (get_page_uri); the frontend
catch-all resolves pages by that exact path (both the English-slug
and Polylang-localized forms resolve, verified on the live site)
- CPTs → /<rewrite-slug>/<slug>, read from the post type registration so the
path tracks WP rather than a duplicated table. acad_collab gains a
rewrite slug of "academic-collaborations" to match its route;
project already had "projects"
- post → /blog/<slug> (the built-in type's base is the site-wide permalink
structure, so this one prefix stays explicit)
The filter still bails on WPGraphQL requests so the frontend's `uri` data is
untouched. Unroutable CPTs (team_member, sponsor, …) keep their permalink.
Sitemap (Next.js)
-----------------
- Add academic collaborations (/academic-collaborations/<slug>) and the blog
authors index + per-author pages, which were missing.
- Fix a doubled language prefix (/pt/pt/…) for pages that have no English
translation: getAllPages now strips the Polylang /<locale> prefix from the
fallback URI so the sitemap route adds exactly one locale segment.
Tests: theme 349 pass, frontend 119 pass; tsc + eslint clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR extends the sitemap with academic collaborations and blog author entries, and refactors WordPress permalink rewriting to generalize post-only logic into a routable-type-aware system. The changes span Next.js API/route layer updates and a significant WordPress PHP infrastructure refactor with corresponding test coverage. ChangesSitemap: Academic Collaborations Support
WordPress Permalink Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 15 |
| Duplication | 4 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Two related improvements to how WordPress and the headless frontend agree on URLs.
1. "View Page" / "View" links for every routable type (approach C)
Previously only posts had their admin "View" link rewritten to the frontend (#134). This generalizes the rewrite to a single filter on
post_link,page_link, andpost_type_link, deriving the frontend path from WordPress's own routing so there's no duplicated route table to drift:get_page_uri). The frontend catch-all resolves pages by that exact path — verified on the live site that both the English-slug form (/pt/governance/research) and the Polylang-localized form (/pt/governanca/pesquisa) resolve./<rewrite-slug>/<slug>, read from the post type registration.acad_collabgains a rewrite slug ofacademic-collaborationsto match its Next.js route;projectalready hadprojects. Aligning the rewrite slug is the source of truth, so the filter reads it rather than hardcoding./blog/<slug>. The built-in post type's base is the site-wide permalink structure (not/blog/), so this one prefix stays explicit. (If you ever set the permalink structure to/blog/%postname%/, this could be dropped too.)/<lang>prefix; static front page maps to the locale root.The filter still bails on WPGraphQL requests, so the frontend's
urifield (e.g. the page sitemap) is never rewritten. Unroutable CPTs (team_member, sponsor, …) keep their default permalink. The static front page maps to/.2. Sitemap completeness + duplicate-locale fix
/academic-collaborations/<slug>) and the blog authors index + per-author pages — all were missing while posts and projects were present./pt/pt/governanca/…) on the two pages per language that have no English translation:getAllPagesfell back to the page's own Polylang-prefixed URI, which the sitemap route then prefixed again. It now strips the/<locale>prefix from that fallback so exactly one segment is added.Testing
FrontendPostPermalinkTest, 14 cases — posts, pages, front page, CPT rewrite-slug, opt-outs, GraphQL bail, ID-arg resolution).getAcademicCollaborationsForSitemap+getAllPagesdoubled-prefix regression).tsc+eslintclean;php -lclean. Live GraphQL queries confirmed the academic-collaboration data resolves.Deployment
The View-link changes are in the WP theme (ships on production deploys only). The sitemap changes are frontend and ship on any deploy.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Chores