@@ -3,13 +3,28 @@ import { READ_ONLY_TEMPLATES } from './readOnlyTemplates'
33import { replaceTemplateVars } from './templateVars'
44import { slugify } from './slugify'
55
6+ /** Bundled marker — must appear in every published blog/posts/*.html file. */
7+ export const POST_PAGE_TEMPLATE_MARKER = 'POST PAGE TEMPLATE ACTIVE'
8+
69export class PublishValidationError extends Error {
710 constructor ( message ) {
811 super ( message )
912 this . name = 'PublishValidationError'
1013 }
1114}
1215
16+ /**
17+ * Full-page template for blog/posts/{slug}.html (templates/post-page-template.html).
18+ * Publish path: publishPipeline → renderPostPageHtml → getPostPageTemplate → this string.
19+ */
20+ export function getPostPageTemplate ( ) {
21+ return READ_ONLY_TEMPLATES . postPageTemplateHtml
22+ }
23+
24+ export function getPostCardTemplate ( ) {
25+ return READ_ONLY_TEMPLATES . postCardTemplateHtml
26+ }
27+
1328function formatDate ( d = new Date ( ) ) {
1429 try {
1530 return new Date ( d ) . toLocaleString ( undefined , { dateStyle : 'long' , timeStyle : 'short' } )
@@ -35,12 +50,35 @@ export function buildPublishTemplateData({ title, slug, content, excerpt, catego
3550 }
3651}
3752
53+ /**
54+ * Renders blog/posts/{slug}.html from templates/post-page-template.html only.
55+ */
56+ export function renderPostPageHtml ( data ) {
57+ const html = replaceTemplateVars ( getPostPageTemplate ( ) , data )
58+ assertRenderedPostPage ( html )
59+ return html
60+ }
61+
3862export function renderPostCardHtml ( data ) {
39- return replaceTemplateVars ( READ_ONLY_TEMPLATES . postCardTemplateHtml , data )
63+ return replaceTemplateVars ( getPostCardTemplate ( ) , data )
4064}
4165
42- export function renderPostPageHtml ( data ) {
43- return replaceTemplateVars ( READ_ONLY_TEMPLATES . postPageTemplateHtml , data )
66+ /** Ensures publish output used the bundled full-page template, not a stale/minimal fallback. */
67+ export function assertRenderedPostPage ( html ) {
68+ const h = String ( html )
69+ const missing = [ ]
70+ if ( ! h . includes ( POST_PAGE_TEMPLATE_MARKER ) ) missing . push ( POST_PAGE_TEMPLATE_MARKER )
71+ if ( ! h . includes ( '<nav class="nb-nav">' ) ) missing . push ( 'header (nb-nav)' )
72+ if ( ! h . includes ( '<footer class="nb-section">' ) ) missing . push ( 'footer' )
73+ if ( ! h . includes ( 'href="../style.css"' ) ) missing . push ( 'stylesheet ../style.css' )
74+ if ( ! h . includes ( 'href="../index.html"' ) ) missing . push ( 'home link ../index.html' )
75+ if ( ! h . includes ( 'class="nb-card nb-stack-md blog-post"' ) ) missing . push ( 'post article' )
76+ if ( missing . length ) {
77+ throw new PublishValidationError (
78+ `Post page was not built from templates/post-page-template.html (missing: ${ missing . join ( ', ' ) } ). ` +
79+ 'Stop and restart the dev server (npm run dev), then publish again.' ,
80+ )
81+ }
4482}
4583
4684export function validatePublishInputs ( { title, content, slug } ) {
@@ -51,11 +89,18 @@ export function validatePublishInputs({ title, content, slug }) {
5189 if ( ! t ) throw new PublishValidationError ( 'Add a title before publishing.' )
5290 if ( ! c || c === '<p></p>' ) throw new PublishValidationError ( 'Add some post content before publishing.' )
5391 if ( ! s ) throw new PublishValidationError ( 'Add a slug (or title) before publishing.' )
54- if ( ! READ_ONLY_TEMPLATES . postCardTemplateHtml . trim ( ) ) {
55- throw new PublishValidationError ( 'Missing post-card template.' )
92+
93+ const pageTpl = getPostPageTemplate ( ) . trim ( )
94+ if ( ! pageTpl ) {
95+ throw new PublishValidationError ( 'Missing templates/post-page-template.html (empty bundle).' )
96+ }
97+ if ( ! pageTpl . includes ( POST_PAGE_TEMPLATE_MARKER ) ) {
98+ throw new PublishValidationError (
99+ 'Bundled post-page template is outdated. Restart npm run dev and try again.' ,
100+ )
56101 }
57- if ( ! READ_ONLY_TEMPLATES . postPageTemplateHtml . trim ( ) ) {
58- throw new PublishValidationError ( 'Missing post-page template.' )
102+ if ( ! getPostCardTemplate ( ) . trim ( ) ) {
103+ throw new PublishValidationError ( 'Missing templates/ post-card- template.html .' )
59104 }
60105
61106 return { title : t , content : c , slug : s }
0 commit comments