Skip to content

feat: frontend View links for pages + CPTs, and sitemap completeness#137

Merged
JohnRDOrazio merged 1 commit into
mainfrom
feat/frontend-view-links-and-sitemap
May 23, 2026
Merged

feat: frontend View links for pages + CPTs, and sitemap completeness#137
JohnRDOrazio merged 1 commit into
mainfrom
feat/frontend-view-links-and-sitemap

Conversation

@JohnRDOrazio
Copy link
Copy Markdown
Member

@JohnRDOrazio JohnRDOrazio commented May 23, 2026

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, and post_type_link, deriving the frontend path from WordPress's own routing so there's no duplicated route table to drift:

  • page → the page's hierarchical URI (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.
  • CPTs/<rewrite-slug>/<slug>, read from the post type registration. acad_collab gains a rewrite slug of academic-collaborations to match its Next.js route; project already had projects. Aligning the rewrite slug is the source of truth, so the filter reads it rather than hardcoding.
  • post/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.)
  • Non-default Polylang locales get the /<lang> prefix; static front page maps to the locale root.

The filter still bails on WPGraphQL requests, so the frontend's uri field (e.g. the page sitemap) is never rewritten. Unroutable CPTs (team_member, sponsor, …) keep their default permalink. The static front page maps to /.

Note: changing acad_collab's rewrite slug affects WP-side URL parsing only after a rewrite-rule flush, but get_permalink() (link generation) uses the registered slug immediately — and nothing browses the WP frontend in headless mode — so the View links work right after deploy with no flush needed.

2. Sitemap completeness + duplicate-locale fix

  • Added academic collaborations (/academic-collaborations/<slug>) and the blog authors index + per-author pages — all were missing while posts and projects were present.
  • Fixed a doubled language prefix (/pt/pt/governanca/…) on the two pages per language that have no English translation: getAllPages fell 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

  • Theme PHPUnit: 349 pass (rewritten FrontendPostPermalinkTest, 14 cases — posts, pages, front page, CPT rewrite-slug, opt-outs, GraphQL bail, ID-arg resolution).
  • Frontend vitest: 119 pass (new getAcademicCollaborationsForSitemap + getAllPages doubled-prefix regression).
  • tsc + eslint clean; php -l clean. 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

    • Academic collaborations are now included in the site's sitemap
    • Blog authors index and individual author pages are now indexed in the sitemap
  • Bug Fixes

    • Fixed multilingual URL path duplication in sitemap entries for non-default languages
  • Chores

    • Updated URL structure for academic collaborations to align with frontend routes
    • Improved permalink handling for pages and custom content types in multilingual setups

Review Change Stack

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 83a55a26-3985-4345-907c-d73cd9cf3ea1

📥 Commits

Reviewing files that changed from the base of the PR and between 45bc660 and ce75ba6.

📒 Files selected for processing (7)
  • app/api/sitemap/[lang]/route.ts
  • lib/wordpress/api.test.ts
  • lib/wordpress/api.ts
  • lib/wordpress/queries.ts
  • wordpress/themes/cdcf-headless/functions.php
  • wordpress/themes/cdcf-headless/includes/frontend-permalinks.php
  • wordpress/themes/cdcf-headless/tests/FrontendPostPermalinkTest.php

📝 Walkthrough

Walkthrough

This 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.

Changes

Sitemap: Academic Collaborations Support

Layer / File(s) Summary
GraphQL Query and API Implementation
lib/wordpress/queries.ts, lib/wordpress/api.ts
Introduces GET_ACADEMIC_COLLABORATIONS_FOR_SITEMAP GraphQL query and getAcademicCollaborationsForSitemap() function to fetch and map academic collaboration records into sitemap shapes. Adds stripLocalePrefix() helper to normalize page URIs for non-default locales when English translations are missing.
API Tests for Academic Collaborations and Page URIs
lib/wordpress/api.test.ts
Tests getAcademicCollaborationsForSitemap including translation normalization, modified date fallback, and error handling. Adds regression test for getAllPages locale prefix stripping when EN translation is absent.
Sitemap Route: Academic Collaborations and Authors
app/api/sitemap/[lang]/route.ts
Updates sitemap route to fetch and render academic collaborations under /academic-collaborations/* per language, and adds blog author index and per-author pages under /blog/authors with derived author slugs.

WordPress Permalink Refactoring

Layer / File(s) Summary
Routing Infrastructure and Helper Functions
wordpress/themes/cdcf-headless/includes/frontend-permalinks.php
Adds CDCF_FRONTEND_ROUTABLE_TYPES allowlist and introduces cdcf_frontend_path_for() to compute locale-prefixed frontend paths for posts, pages, and CPTs using registered rewrite slugs. Replaces the filter with cdcf_frontend_permalink() to rewrite CMS permalinks to frontend URLs while handling GraphQL requests and missing content.
WordPress Hook Configuration and CPT Setup
wordpress/themes/cdcf-headless/functions.php
Registers academic-collaborations as the rewrite slug for acad_collab CPT. Updates post_link, page_link, and post_type_link filters to use the new cdcf_frontend_permalink callback.
Test Suite for Frontend Permalink Behavior
wordpress/themes/cdcf-headless/tests/FrontendPostPermalinkTest.php
Comprehensively tests path and permalink generation for posts with locale prefixing, hierarchical page URIs, static front-page routing with locale variants, CPT rewrite-slug resolution with fallback, and opt-out conditions for unroutable/unpublished/slugless content.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • CatholicOS/cdcf-website#134: This PR extends and replaces the headless permalink rewrite introduced in #134, substantially refactoring frontend-permalinks.php and updating filter wiring with expanded test coverage.
  • CatholicOS/cdcf-website#58: Both PRs modify sitemap locale handling for pages; this PR adds academic collaborations support while #58 addressed doubled locale prefixes in hreflang alternates.

Poem

🐰 A rabbit hops through URLs, new and grand,
Academic collaborations now mapped by hand.
WordPress bows to generalized routes divine,
Pages, posts, and CPTs all aligned.
The sitemap grows, locale prefixes dance—no more PT/PT!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 39.13% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: generalizing View links for pages and custom post types, plus improving sitemap completeness with new content and locale prefix fixes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/frontend-view-links-and-sitemap

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...mes/cdcf-headless/includes/frontend-permalinks.php 93.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 15 complexity · 4 duplication

Metric Results
Complexity 15
Duplication 4

View in Codacy

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.

@JohnRDOrazio JohnRDOrazio merged commit 14e281b into main May 23, 2026
13 checks passed
@JohnRDOrazio JohnRDOrazio deleted the feat/frontend-view-links-and-sitemap branch May 23, 2026 17:05
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.

2 participants