Remove unnecessary props and data structure

This commit is contained in:
adilallo
2025-09-05 08:09:44 -06:00
parent fc096129dd
commit 93182e6c2d
8 changed files with 21 additions and 279 deletions
+1 -58
View File
@@ -108,8 +108,6 @@ class ContentProcessor {
frontmatter: processFrontmatter(sanitizedFrontmatter),
content: processedContent.content,
htmlContent: processedContent.htmlContent,
wordCount: processedContent.wordCount,
readingTime: processedContent.readingTime,
headings: processedContent.headings,
links: processedContent.links,
images: processedContent.images,
@@ -195,46 +193,6 @@ class ContentProcessor {
return recentPosts;
}
/**
* Get blog posts by tag
* @param {string} tag - The tag to filter by
* @returns {Array} Array of blog post objects matching the tag
*/
getPostsByTag(tag) {
const cacheKey = `tag:${tag}`;
const cached = getCachedBlogList(cacheKey);
if (cached) return cached;
const allPosts = this.getAllPosts();
const taggedPosts = allPosts.filter(
(post) => post.frontmatter.tags && post.frontmatter.tags.includes(tag)
);
cacheBlogList(cacheKey, taggedPosts);
return taggedPosts;
}
/**
* Get all unique tags with caching
* @returns {Array} Array of unique tags
*/
getAllTags() {
const cached = getCachedTags();
if (cached) return cached;
const allPosts = this.getAllPosts();
const tags = new Set();
allPosts.forEach((post) => {
if (post.frontmatter.tags) {
post.frontmatter.tags.forEach((tag) => tags.add(tag));
}
});
const tagsArray = Array.from(tags).sort();
cacheTags(tagsArray);
return tagsArray;
}
/**
* Search blog posts
* @param {string} query - Search query
@@ -255,11 +213,8 @@ class ContentProcessor {
.toLowerCase()
.includes(searchTerm);
const contentMatch = post.content.toLowerCase().includes(searchTerm);
const tagMatch = post.frontmatter.tags?.some((tag) =>
tag.toLowerCase().includes(searchTerm)
);
return titleMatch || descriptionMatch || contentMatch || tagMatch;
return titleMatch || descriptionMatch || contentMatch;
});
return results.slice(0, limit);
@@ -271,22 +226,12 @@ class ContentProcessor {
*/
getBlogStats() {
const allPosts = this.getAllPosts();
const tags = this.getAllTags();
return {
totalPosts: allPosts.length,
totalTags: tags.length,
totalAuthors: new Set(
allPosts.map((post) => post.frontmatter.author).size
),
totalWords: allPosts.reduce((sum, post) => sum + post.wordCount, 0),
averageReadingTime:
allPosts.length > 0
? Math.round(
allPosts.reduce((sum, post) => sum + post.readingTime, 0) /
allPosts.length
)
: 0,
dateRange: {
earliest:
allPosts.length > 0
@@ -367,8 +312,6 @@ export const getAllPosts = () => contentProcessor.getAllPosts();
export const getBlogPostBySlug = (slug) =>
contentProcessor.getBlogPostBySlug(slug);
export const getRecentPosts = (limit) => contentProcessor.getRecentPosts(limit);
export const getPostsByTag = (tag) => contentProcessor.getPostsByTag(tag);
export const getAllTags = () => contentProcessor.getAllTags();
export const searchPosts = (query, limit) =>
contentProcessor.searchPosts(query, limit);
export const getBlogStats = () => contentProcessor.getBlogStats();
-36
View File
@@ -24,8 +24,6 @@ export function processMarkdown(markdown) {
return {
content: "",
htmlContent: "",
wordCount: 0,
readingTime: 0,
headings: [],
links: [],
images: [],
@@ -41,18 +39,12 @@ export function processMarkdown(markdown) {
// Extract images
const images = extractImages(markdown);
// Calculate word count and reading time
const wordCount = calculateWordCount(markdown);
const readingTime = calculateReadingTime(wordCount);
// Convert markdown to HTML
const htmlContent = markdownToHtml(markdown);
return {
content: markdown,
htmlContent,
wordCount,
readingTime,
headings,
links,
images,
@@ -141,31 +133,6 @@ function generateHeadingId(text) {
.trim();
}
/**
* Calculate word count from markdown content
* @param {string} markdown - Raw markdown content
* @returns {number} Word count
*/
function calculateWordCount(markdown) {
// Remove markdown syntax and count words
const cleanText = markdown
.replace(/[#*`~\[\]()]/g, "") // Remove markdown characters
.replace(/\n+/g, " ") // Replace newlines with spaces
.trim();
return cleanText.split(/\s+/).filter((word) => word.length > 0).length;
}
/**
* Calculate estimated reading time
* @param {number} wordCount - Number of words
* @returns {number} Reading time in minutes
*/
function calculateReadingTime(wordCount) {
const wordsPerMinute = 200; // Average reading speed
return Math.ceil(wordCount / wordsPerMinute);
}
/**
* Convert markdown to HTML with enhanced formatting
* @param {string} markdown - Raw markdown content
@@ -255,9 +222,6 @@ export function processFrontmatter(frontmatter) {
month: new Date(frontmatter.date).getMonth() + 1,
day: new Date(frontmatter.date).getDate(),
isRecent: isRecentPost(frontmatter.date),
readingTime: frontmatter.content
? calculateReadingTime(calculateWordCount(frontmatter.content))
: 0,
};
return processed;
-10
View File
@@ -29,16 +29,6 @@ export const BLOG_POST_SCHEMA = {
required: true,
pattern: /^\d{4}-\d{2}-\d{2}$/, // YYYY-MM-DD format
},
tags: {
type: "array",
required: false,
default: [],
items: {
type: "string",
minLength: 1,
maxLength: 20,
},
},
related: {
type: "array",
required: false,