Headless Rich-Text Blog CMS & Reader Analytics
The HiTech Blog Engine is a hybrid publishing platform combining statically localized core articles with a dynamic, headless MongoDB CMS and real-time reader engagement analytics. Designed for rapid SEO expansion, the system allows non-technical content editors and marketing teams to author, schedule, and distribute rich multimedia articles across English and Spanish locales.
1. Dual-Tier Content Architecture
To guarantee high availability and sub-millisecond initial page loads, the platform implements a dual-tier storage strategy:
- Static Fallback Tier (
src/messages/[locale]/blog-detail.json): Pre-compiled translation catalogs holding core cornerstone content (e.g. foundational guides on commercial trucking regulations, minimum California auto requirements, and SR-22 certification). If the database is unreachable or a legacy URL is accessed, the route seamlessly renders from disk without error. - Dynamic MongoDB Tier (
BlogModel): Managed through the Admin Control Center, dynamic articles support instantaneous publishing, scheduled releases, and bilingual variants without requiring code deployments or container rebuilds.
// Resolution priority in src/app/[locale]/blog/[slug]/page.tsx
export default async function Page({ params }: Props) {
const { locale, slug } = await params;
// 1. Check Dynamic Database First
const dynamicBlog = await getBlogBySlug(slug, locale);
if (dynamicBlog) {
return <BlogDetail dynamicBlog={dynamicBlog} />;
}
// 2. Fallback to Localized Static JSON
const localeData = messages[locale];
const detailData = localeData?.[slug];
if (!detailData) notFound();
return <BlogDetail data={detailData} />;
}
2. Dynamic Blog Data Schema (Blog Model)
Dynamic posts are persisted in the Blog collection (src/lib/db/models/Blog.ts):
export interface IBlog {
_id: string;
title: string;
slug: string;
description: string;
content: string; // HTML output from Tiptap editor
coverImage?: string; // Hero banner image URL
category: string; // 'auto', 'commercial', 'trucking', 'life', etc.
language: "en" | "es";
status: "draft" | "scheduled" | "published";
isRecent?: boolean; // Featured in "Recent Articles" widget
isPopular?: boolean; // Featured in "Popular Topics" sidebar
publishedAt?: Date | null;
scheduledAt?: Date | null;
structuredData?: {
faq?: {
QA?: Array<{ question: string; answer: string }>;
};
};
createdAt: Date;
updatedAt: Date;
}
Automatic Scheduled Publishing Engine
Rather than relying on a separate cron worker daemon, the Server Action getBlogs() executes an inline, lazy state-transition query whenever articles are fetched:
// Auto-transitions scheduled posts whose target timestamp has elapsed
const now = new Date();
const result = await Blog.updateMany(
{
status: "scheduled",
$or: [
{ scheduledAt: { $lte: now } },
{ publishedAt: { $lte: now } },
],
},
{ $set: { status: "published", publishedAt: now } }
);
if (result.modifiedCount > 0) {
revalidatePath("/blog");
}
3. Editorial Suite: Tiptap WYSIWYG Integration
Content editors interact with the custom Tiptap editor (src/components/feature/admin/blog-editor.tsx) built on top of ProseMirror.
Supported Editor Extensions
- Typography Primitives: Headings (
h1,h2,h3,h4), Blockquotes, Code Blocks, Horizontal Rules. - Rich Lists: Ordered and bulleted lists with nested indentation.
- Tables: Rich table builder with column resizing, header row locking, and cell merge capabilities.
- Link Protocol Sanitization: Strips dangerous
javascript:schemes and automatically enforcestarget="_blank" rel="noopener noreferrer". - FAQ Builder Accordion: Dedicated interface allowing writers to append structured Q&A pairs directly below the article, which the engine converts into valid Google
FAQPagerich snippet schemas.
Estimated Reading Time Algorithm
The editor automatically calculates reader duration during editing:
Reading Time (minutes) = Math.ceil(Total Word Count / 200)
4. Structured SEO & Rich Schema Generation
Dynamic articles automatically synthesize and embed three Google-compliant JSON-LD structured schemas:
// 1. Article Schema
const articleSchema = buildArticleSchema({
title: dynamicBlog.title,
description: dynamicBlog.description,
slug,
locale,
image: dynamicBlog.coverImage,
datePublished: dynamicBlog.publishedAt?.toISOString(),
dateModified: dynamicBlog.updatedAt?.toISOString(),
});
// 2. BreadcrumbList Schema
const breadcrumbSchema = buildBreadcrumbSchema([
{ name: locale === "es" ? "Inicio" : "Home", url: `/${locale}` },
{ name: "Blog", url: `/${locale}/blog` },
{ name: dynamicBlog.title, url: `/${locale}/blog/${slug}` },
]);
// 3. FAQPage Schema (when QA items exist)
const faqSchema = dynamicBlog.structuredData?.faq?.QA?.length
? buildFaqSchema(dynamicBlog.structuredData.faq.QA)
: null;
5. Reader Telemetry & Analytics (BlogVisit)
Every public viewing of a blog post invokes the <BlogVisitTracker /> client component, which fires an asynchronous, non-blocking telemetry beacon to log reader metrics without affecting Time to Interactive (TTI).
Telemetry Record (BlogVisit Schema)
- Article Context:
slug,title, and article category. - Network & Location: Anonymized IP hash, resolved ISO country code, state/region, and city (via
geoip-lite). - Device Fingerprint: Browser family (Chrome, Safari, Edge, Firefox), OS (iOS, Android, Windows, macOS), and form factor (desktop, mobile, tablet).
- Referrer Attribution: Captures external referring domain (e.g. Google Search, Facebook, Twitter, LinkedIn).
Admins can review article engagement graphs, high-traffic topics, and geographic readership distributions directly within the Blog tab of the Admin Control Center.