Remove unnecessary props and data structure
This commit is contained in:
+1
-58
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user