Skip to content

Add configurable post types#484

Merged
compscidr merged 2 commits intomainfrom
feature/configurable-post-types
Mar 3, 2026
Merged

Add configurable post types#484
compscidr merged 2 commits intomainfrom
feature/configurable-post-types

Conversation

@compscidr
Copy link
Copy Markdown
Collaborator

Summary

  • Adds a PostType model so admins can create custom content types (e.g. Notes, Links, Recipes), each with its own URL namespace (/notes/2024/01/15/slug) and automatic listing page (/notes)
  • The default type is "Post" with slug "posts", preserving all existing URLs and backward compatibility
  • Writing pages can optionally filter by a specific post type via admin dropdown

Changes

  • New model: PostType with name, slug, description
  • Post model: Added PostTypeID foreign key; Permalink() and Adminlink() use type slug
  • Page model: Added optional PostTypeID for writing page filtering
  • Routing: NoRoute resolves type-prefixed URLs (/{type}/{yyyy}/{mm}/{dd}/{slug}) and admin equivalents
  • Admin: Full PostType CRUD (create, edit, delete with referential integrity), post type dropdown on post create/edit, post type filter on writing page edit
  • Migration: Seeds default "Post" type, assigns existing posts, links writing pages to their post type
  • Templates: 4 new templates, 7 modified with Post Types nav link and dropdowns
  • JS: Updated redirects to use type-aware URLs
  • Tests: Updated across all packages (admin, blog, tools)

Test plan

  • Existing post URLs (/posts/2024/01/15/slug) work unchanged
  • Admin can create a new post type (e.g. "Notes" with slug "notes")
  • Posts can be reassigned to a different type and save correctly
  • /notes shows a listing of only "Notes" type posts
  • /notes/2024/01/15/my-note resolves correctly
  • Writing page filter dropdown shows saved value and filters posts accordingly
  • Slug conflicts between post types and pages are rejected
  • Deleting a post type with posts is rejected
  • go test ./... passes

Closes #165

🤖 Generated with Claude Code

Adds a PostType model so admins can create custom content types (e.g.
Notes, Links, Recipes), each with its own URL namespace and listing page.
The default type is "Post" with slug "posts", preserving all existing URLs.

Key changes:
- New PostType model with CRUD admin UI
- Posts have a PostTypeID foreign key with type-aware permalinks
- NoRoute resolves type-prefixed URLs (/notes/2024/01/15/slug)
- Writing pages can filter by post type via admin dropdown
- Migration seeds default "Post" type and links existing posts/pages
- Slug conflict prevention between post types and pages
- Updated backlinks regex to handle type-prefixed internal links

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 3, 2026 08:29
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 32.86119% with 237 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.72%. Comparing base (ec471d4) to head (d776b93).

Files with missing lines Patch % Lines
blog/blog.go 13.19% 120 Missing and 5 partials ⚠️
admin/admin.go 40.46% 75 Missing and 28 partials ⚠️
tools/migrate.go 73.07% 4 Missing and 3 partials ⚠️
blog/post_type.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #484      +/-   ##
==========================================
- Coverage   47.60%   45.72%   -1.88%     
==========================================
  Files           7        8       +1     
  Lines        1689     1999     +310     
==========================================
+ Hits          804      914     +110     
- Misses        811      975     +164     
- Partials       74      110      +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a configurable PostType concept to support multiple content types (e.g., Notes/Links) with their own URL namespaces and listing pages, while keeping the default posts URLs backward-compatible.

Changes:

  • Introduces PostType model + admin CRUD and UI wiring (dropdowns, navigation).
  • Updates post/page models, routing (type-prefixed URLs + listing pages), and sitemap generation.
  • Extends migrations and tests to seed/attach the default posts type and validate the new behavior.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
www/js/admin-script.js Sends post_type_id in create/update payloads and redirects to type-aware URLs.
tools/migrate_test.go Adds assertions that the default post type is seeded and writing pages are linked.
tools/migrate.go Migrates PostType, seeds the default type, links writing pages, and updates internal-link regex.
templates/post_type_listing.html New listing template for a post type (/{typeSlug}).
templates/post-admin.html Adds post type selector to the post edit view.
templates/admin_settings.html Adds “Post Types” link to admin nav.
templates/admin_post_types.html New admin listing/create/delete UI for post types.
templates/admin_pages.html Adds “Post Types” link to admin nav.
templates/admin_new_post.html Adds post type dropdown on the new post form.
templates/admin_edit_post_type.html New admin edit UI for a single post type.
templates/admin_edit_page.html Adds optional writing-page post type filter and saves post_type_id.
templates/admin_dashboard.html Adds “Post Types” link to admin nav.
templates/admin_all_posts.html Shows post type name in the all-posts table and adds nav link.
templates/admin.html Adds “Post Types” link to admin nav.
goblog.go Registers post type CRUD API routes and admin HTML routes.
blog/post_type.go Adds the PostType model and its listing permalink helper.
blog/post_test.go Updates permalink/adminlink tests for type-aware URLs.
blog/post.go Adds PostTypeID/relation and makes permalinks/adminlinks type-aware.
blog/page.go Adds optional PostTypeID to pages (writing-page filtering).
blog/blog_test.go Updates migrations/seeding and adds routing coverage for type-prefixed URLs.
blog/blog.go Preloads PostType, adds post type lookup/listing rendering, routing resolution, and sitemap entries.
admin/admin_test.go Adds post type CRUD API + HTML route coverage and seeds default type in tests.
admin/admin.go Implements post type CRUD endpoints, adds slug conflict checks, and wires post type data into admin views and post create/update.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Post type select auto-saves on change (draft-aware onchange handler)
- GetBacklinks/GetOutboundLinks now preload PostType so Adminlink()
  uses correct type slug instead of falling back to /admin/posts/...
- Fix N+1 in getPostsByTag: batch-load PostType with single query
- Validate PostTypeID exists in CreatePost before inserting
- Validate Name is non-empty in UpdatePostType
- Validate ID and check existence in DeletePostType before deleting
- Add error checking to seedDefaultPostType Create/Update operations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@compscidr compscidr merged commit 0f4cd9c into main Mar 3, 2026
1 of 2 checks passed
@compscidr compscidr deleted the feature/configurable-post-types branch March 3, 2026 08:48
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.

Add "notes" post type

2 participants