-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ui): add /featured, warn for old posts #554
Conversation
Reviewer's Guide by SourceryThis PR introduces several UI improvements including a new featured posts section, old post warnings, and various content cleanup changes. The implementation focuses on enhancing the blog's navigation and content organization while improving the user experience through better content presentation and warnings for outdated content. No diagrams generated as the changes look simple and do not need a visual representation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @duyet - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Review instructions: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
* @returns {TagCount} An object where each key is a unique tag and its value | ||
* is the number of times that tag appears across all posts. The type TagCount | ||
* is defined as Record<string, number>. | ||
*/ | ||
export function getAllTags(): TagCount { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (performance): The tags reduction could be optimized to use a single pass
Consider using a single reduce operation to build the tag count object instead of chaining multiple array operations. This would improve performance for large numbers of posts.
export function getAllTags(): TagCount {
return getAllPosts().reduce((acc: TagCount, post) => {
post.tags?.forEach(tag => acc[tag] = (acc[tag] || 0) + 1);
return acc;
}, {});
}
const extraFields = [...fields, 'date', 'featured'] | ||
let allPosts = getAllPosts(extraFields) | ||
|
||
if (featured !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider extracting the post filtering logic into a dedicated function to improve code organization
Consider extracting the filtering logic into a separate function to improve composability and maintainability:
type PostFilter = (post: Post) => boolean;
const createFeaturedFilter = (featured?: boolean): PostFilter =>
featured === undefined ? () => true : (post) => post.featured === true;
export function getPostsByAllYear(
fields: string[] = [],
yearLimit: number = -1,
featured?: boolean
): Record<number, Post[]> {
const extraFields = [...fields, 'date', 'featured'];
const allPosts = getAllPosts(extraFields);
const filteredPosts = allPosts.filter(createFeaturedFilter(featured));
return filteredPosts.reduce((acc, post) => {
const year = new Date(post.date).getFullYear();
if (!acc[year]) acc[year] = [];
acc[year].push(post);
return acc;
}, {} as Record<number, Post[]>);
}
This approach:
- Introduces a reusable PostFilter type
- Separates filtering logic into composable functions
- Makes it easier to add new filters in the future
- Maintains existing functionality while reducing complexity
Summary by Sourcery
Add a '/featured' page to showcase highlighted blog posts and implement a warning system for posts older than a specified number of years. Enhance the post data structure with a 'featured' attribute and update components to support and display this new feature.
New Features:
Enhancements: