feat: initial release of pengzhan.dev personal editorial blog platform
- Editorial web platform built with Node.js, Express, EJS, and Vanilla CSS - Markdown content engine with YAML frontmatter, bilingual variants, and hot-reload watcher - Unified SQLite with FTS5 search indexing, query logging, and schema filters - Centered editorial post layout with margin-docked left TOC and mobile bottom sheet - WordPress-grade comment system with moderation dashboard and bulk operations under /guanli - Complete SEO suite (JSON-LD structured data, RSS/Atom feeds, XML sitemap, robots.txt) - CI/CD workflows for linting, security audits (Gitleaks), automated tests, and Docker releases
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const contentService = require('../services/content');
|
||||
|
||||
router.get('/blogs', (req, res) => {
|
||||
let posts = contentService.getAllPosts();
|
||||
const { category, tag, page } = req.query;
|
||||
|
||||
let activeFilter = null;
|
||||
|
||||
if (category) {
|
||||
const catLower = category.trim().toLowerCase();
|
||||
posts = posts.filter(p => (p.category || '').toLowerCase() === catLower);
|
||||
activeFilter = { type: 'category', value: category };
|
||||
} else if (tag) {
|
||||
const tagLower = tag.trim().toLowerCase();
|
||||
posts = posts.filter(p => (p.tags || []).some(t => t.toLowerCase() === tagLower));
|
||||
activeFilter = { type: 'tag', value: tag };
|
||||
}
|
||||
|
||||
const postsPerPage = 12;
|
||||
const currentPage = Math.max(1, parseInt(page, 10) || 1);
|
||||
const totalPosts = posts.length;
|
||||
const totalPages = Math.ceil(totalPosts / postsPerPage);
|
||||
|
||||
const startIndex = (currentPage - 1) * postsPerPage;
|
||||
const paginatedPosts = posts.slice(startIndex, startIndex + postsPerPage);
|
||||
|
||||
const taxonomy = contentService.getTaxonomy();
|
||||
|
||||
res.render('pages/blogs', {
|
||||
title: activeFilter ? `Blogs - ${activeFilter.type}: ${activeFilter.value}` : 'Blogs',
|
||||
posts: paginatedPosts,
|
||||
currentPage,
|
||||
totalPages,
|
||||
totalPosts,
|
||||
activeFilter,
|
||||
taxonomy
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user