6. Native PHP + HTMX Blog, SEO & Media Layer
Repository:
Webpage (planovi-webpage)• Rule Prefix:BR-BLG• Documented Rules: 10 • Open[TEAM_WHY_NEEDED]Questions: 2
1. Business Purpose & Actors
- Problem solved: Publishes bilingual SEO/GEO-optimized articles with reactive category/search filtering (zero full-page reload via HTMX), cross-language article linking via
translation_key, dynamic XML sitemap generation, LLM discovery (llms.txt), and headless CMS publishing directly into Supabase (website.blog_posts+blog-mediaStorage bucket). - Actors: Readers searching/reading articles (
/blog,/blog/{slug}); Search & AI crawlers (/sitemap.xml,/llms.txt); Editorial/n8n automation publishing content directly via Supabase REST/Storage APIs (supabase/API_EXAMPLES.md).
2. All Features & End-to-End Flows
- Flow A — Blog Index SSR & HTMX Reactive Filtering (
blog.php,components/blog-grid-partial.php,includes/blog-repository.php):- Trigger (Full Load):
GET /blog[?category=...&q=...]renders full page SSR with up to24posts (get_blog_posts($current_lang, 24, $category, $search)) and category pills (get_blog_categories($current_lang)fetching up to50posts to derive unique categories). - Trigger (HTMX Live Update): Typing in
#blog-search-input(hx-trigger="keyup changed delay:350ms, search",hx-include="#blog-filter-category") or clicking a.category-pill(hx-include="#blog-search-input") firesGET /blog?...with headerHX-Request: trueandhx-push-url="true". - Processing:
blog.php:9-13detects!empty($_SERVER['HTTP_HX_REQUEST']), queriesget_blog_posts($current_lang, 24, $category, $search), renders ONLYcomponents/blog-grid-partial.php, and exits. HTMX swaps#blog-resultsand togglesaria-busyviahtmx:beforeRequest/htmx:afterOnLoad.
- Trigger (Full Load):
- Flow B — Single Article View & Bilingual Slug Switching (
blog-post.php,includes/blog-repository.php:92-183):- Trigger:
GET /blog/{slug}(rewritten toblog-post.php?slug={slug}). - Validation: Extracts slug from
$_GET['slug']or fallback regex onREQUEST_URI; validates viavalidate_slug(). - Lookup: Queries
website.blog_posts?slug=eq.<slug>&is_published=eq.true&limit=1(8stimeout). If found andtranslation_keyis non-empty, fires a second query (4stimeout) fortranslation_key=eq.<key>&lang=eq.<opposite>&is_published=eq.true&limit=1to populatetranslated_slug. - Not Found: Returns HTTP
404HTML page with<meta name="robots" content="noindex, follow">. - Found: Sets
$custom_lang_urlsso navbar PL/EN switcher routes to/blog/{translated_slug}?lang={other}(or/blog?lang={other}if untranslated). Sets<html lang="<?= $post['lang'] ?>">. Renders sanitized HTML body (sanitize_blog_html()), media viarender_blog_media(), tags, LinkedIn/X/Clipboard share buttons, Schema.orgBlogPosting+BreadcrumbListJSON-LD, hreflang alternates, and up to3related posts (same category excluding self; if< 2, falls back to latest posts in same language excluding self).
- Trigger:
- Flow C — Dynamic XML Sitemap (
sitemap.php) &llms.txt:GET /sitemap.xml: EmitsContent-Type: application/xml; charset=utf-8containing 4 static pages (/,/blog,/documentation,/status) + up to 50 PL posts + up to 50 EN posts withxhtml:link rel="alternate" hreflangcross-links matched bytranslation_key.GET /llms.txt: Static markdown file summarizing PLANOVI architecture, modules, pricing tiers, and links for LLMs.
- Flow D — Headless CMS Ingestion (
supabase/API_EXAMPLES.md,supabase/website_schema.sql:232-279):- External clients (n8n/Postman/cURL) upload assets to Supabase Storage
POST /storage/v1/object/blog-media/{filename}(service_role), then insert/update posts viaPOST/PATCH /rest/v1/blog_posts(Content-Profile: website,service_role).
- External clients (n8n/Postman/cURL) upload assets to Supabase Storage
3. Hard Business Rules, Validations, Calculations & Edge Cases
- BR-BLG-01 (Query Clamping & Sanitization):
get_blog_posts()constrains$langto['pl', 'en'](default'pl'),$limitto1..50,$offset >= 0. Category and search terms pass throughsanitize_postgrest_query()before buildingcategory=eq.<clean>andor=(title.ilike.*<clean>*,excerpt.ilike.*<clean>*)(includes/blog-repository.php:21-55). - BR-BLG-02 (Mock Data Fallback Asymmetry):
- In
get_blog_posts(): returnsget_fallback_blog_posts()ONLY if Supabase is unconfigured/placeholder OR HTTP request fails/non-2xx/invalid JSON. A valid200 []from Supabase returns[]without fallback (includes/blog-repository.php:29-83). - In
get_blog_post_by_slug(): falls through to mock search even when Supabase returns200 [](includes/blog-repository.php:121,161-180), so the 4 hardcoded mock slugs remain publicly accessible even if deleted/unpublished in Supabase!
- In
- BR-BLG-03 (No Pagination UI & Hard Caps):
blog.phprequests a fixedlimit=24withoffset=0and no pagination controls (blog.php:10,16);get_blog_categories()andsitemap.phpcap at50posts per language (includes/blog-repository.php:193,sitemap.php:55-56), so posts beyond #24 are invisible on/blogand beyond #50 are omitted from/sitemap.xmland category discovery. - BR-BLG-04 (Media Rendering & MIME Mismatch):
render_blog_media()defaults missingcover_media_urlto/assets/dashboard.jpg. Renders<video autoplay muted loop playsinline poster="/assets/dashboard.jpg">whencover_media_type === 'video'OR URL matches/\.(mp4|webm)$/i, but hardcodestype="video/mp4"even for.webmfiles (includes/blog-repository.php:210-225). - BR-BLG-05 (HTML-Only Rendering Despite Schema Comment): Both
supabase/website_schema.sql:182andsupabase/API_EXAMPLES.md:62claimcontentsupports"HTML lub Markdown", yetblog-post.php:252passescontentdirectly tosanitize_blog_html()with zero Markdown conversion. - BR-BLG-06 (Storage Bucket Constraints): Bucket
blog-mediais public-read (anon, authenticated, service_role),service_role-write, max file size104,857,600bytes (100 MB), allowed MIME types:image/jpeg,image/png,image/webp,image/gif,image/svg+xml,video/mp4,video/webm(supabase/website_schema.sql:240-278). - BR-BLG-07 (Sitemap
updated_atMissing Column Bug):get_blog_posts()selects 14 explicit columns excludingupdated_at(includes/blog-repository.php:31), yetsitemap.php:92,112checks$post['updated_at']first — so<lastmod>never reflects post edits and always falls back topublished_at. - BR-BLG-08 (Implicit Global
eventBug in Category Pill Click):blog.php:161-167callsevent.target.classList.add('active')without declaringeventas a parameter insetCategory(cat). In browsers without legacywindow.event(e.g., Firefox), clicking a category pill throwsReferenceError: event is not defined, preventing active pill highlighting. - BR-BLG-09 (Hardcoded Production Domain in SEO Tags):
index.php,blog.php,blog-post.php, andsitemap.phphardcodehttps://planovi.appforcanonical,hreflang,og:url, and sitemap<loc>even when deployed todev-webpage.planovi.app. - BR-BLG-10 (Direct Public Execution of Partial):
components/blog-grid-partial.php:7-13self-initializes if$postsis unset, making/components/blog-grid-partial.phpdirectly reachable via HTTP.
4. State Machines & Data Lifecycle
website.blog_posts.is_published is a binary boolean (true = publicly visible via RLS policy "Allow public read published blog posts", false = draft/hidden from anon and from queries filtering is_published=eq.true). updated_at is auto-maintained via trg_blog_posts_updated_at.
5. Technical Contract (Inputs → Processing → Side Effects)
- Endpoints:
GET /blog(?category=&q=&lang=, full HTML or HTMX partial whenHX-Requestpresent);GET /blog/{slug}(blog-post.php);GET /sitemap.xml(sitemap.php);GET /llms.txt. - DB Table (
supabase/website_schema.sql:172-229):website.blog_posts(id UUID PK,created_at,created_by,updated_at,slug TEXT UNIQUE,translation_key TEXT,lang VARCHAR(5),title,excerpt,content,category,tags TEXT[],cover_media_url,cover_media_type,author_name,author_role,reading_time_min INT,meta_title,meta_description,meta_keywords,is_published BOOLEAN,published_at). Indexes:slug,(lang, is_published, published_at DESC),translation_key,category. - Storage Bucket:
storage.bucketsid'blog-media'(public read,100 MBlimit).
6. Cross-Repository Dependencies
| Caller → Callee | Protocol & Auth | Exact Endpoint / Contract |
|---|---|---|
planovi-webpage → Supabase (planovi-backend DB) | HTTPS PostgREST (apikey + Authorization: Bearer, Accept-Profile: website) | GET /rest/v1/blog_posts |
External n8n / Editorial CMS → Supabase (planovi-backend DB & Storage) | HTTPS (service_role, Content-Profile: website) | POST/PATCH /rest/v1/blog_posts, POST/DELETE /storage/v1/object/blog-media/* |
7. Why It Works This Way (Decisions, Trade-offs & Workarounds)
- Native PHP SSR + HTMX: Chosen for instant crawler indexability (SEO/GEO) without a JavaScript SPA bundle while providing live search/category UX via HTMX (
blog.php:55, commitca2682d). - Dedicated
websitePostgreSQL schema: Isolates marketing tables (website_form_messages,waitlist,blog_posts) from core application tables inpublicwhile adhering to company audit columns (id,created_at,created_by,updated_at) (supabase/website_schema.sql:1-13). [TEAM_WHY_NEEDED: Why does get_blog_post_by_slug() fall back to hardcoded mock posts even when Supabase responds 200 [], and should mock fallback be gated by an explicit config flag?][TEAM_WHY_NEEDED: Is Markdown rendering planned for blog_posts.content (as mentioned in website_schema.sql:182 and API_EXAMPLES.md:62), or should those comments be updated to HTML-only?]
8. Debugging, Logs & Common Failure Modes
| Symptom / Error Message | Root Cause in Code | How to Verify | Fix |
|---|---|---|---|
Blog displays hardcoded mock articles (Jak Agent AI optymalizuje...) instead of Supabase rows | supabase.url / supabase.key missing, website schema not exposed in Supabase PostgREST Exposed schemas, or PostgREST returned non-2xx (includes/blog-repository.php:29-83) | curl -H "Accept-Profile: website" -H "apikey: <key>" "<url>/rest/v1/blog_posts?limit=1" | Add website to Supabase API Exposed Schemas and verify supabase.url/key |
| Published article returns 404 | Slug contains uppercase/underscores failing validate_slug(), or is_published = false | Check slug & is_published in website.blog_posts | Use lowercase kebab-case slug and set is_published = true |
| Category pill active border does not move in Firefox | setCategory() uses implicit event.target (blog.php:166) | Open Firefox DevTools Console and click a category pill | Pass this into setCategory(cat, this) |