Skip to content
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

Merged
merged 3 commits into from
Nov 11, 2024
Merged

feat(ui): add /featured, warn for old posts #554

merged 3 commits into from
Nov 11, 2024

Conversation

duyet
Copy link
Owner

@duyet duyet commented Nov 11, 2024

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:

  • Introduce a '/featured' page to highlight featured blog posts, allowing users to explore curated content.
  • Add a warning for old posts, informing readers when a post is over a certain age and may contain outdated information.

Enhancements:

  • Add a 'featured' attribute to posts, enabling the categorization and display of featured content.
  • Update the YearPost component to include and display featured status for posts.

Copy link
Contributor

sourcery-ai bot commented Nov 11, 2024

Reviewer's Guide by Sourcery

This 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

Change Details Files
Added featured posts functionality with a new /featured route
  • Added featured boolean field to Post interface
  • Created new /featured page to display featured posts
  • Modified getPostsByAllYear to support filtering by featured flag
  • Added featured flag to multiple existing blog posts
packages/interfaces/src/post.ts
packages/libs/getPost.ts
apps/blog/app/featured/page.tsx
apps/blog/app/featured/layout.tsx
Added warning component for old posts
  • Created new OldPostWarning component
  • Integrated warning component into post content layout
  • Warning appears for posts older than 5 years
apps/blog/app/[year]/[month]/[slug]/content/old-post-warning.tsx
apps/blog/app/[year]/[month]/[slug]/content/content.tsx
Improved post listing and navigation
  • Updated YearPost component to accept posts as props
  • Modified date format display in post listings
  • Added featured post indicator in listings
  • Updated navigation links to include featured posts section
apps/blog/components/year-post.tsx
apps/blog/app/page.tsx
apps/blog/app/archives/page.tsx
Content cleanup and optimization
  • Shortened and simplified multiple post titles
  • Removed redundant content
  • Updated post metadata and formatting
apps/blog/_posts/2015/08/google-cloud-platform-developer-roadshow-ho-chi-minh-viet-nam.md
apps/blog/_posts/2015/08/cach-su-dung-git-rebase.md
apps/blog/_posts/2019/03/7-thu-thuat-voi-resting-va-spreading.md
apps/blog/_posts/2020/05/tldr-why-rf.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

vercel bot commented Nov 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 11, 2024 6:42pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cv ⬜️ Ignored (Inspect) Visit Preview Nov 11, 2024 6:42pm
insights ⬜️ Ignored (Inspect) Visit Preview Nov 11, 2024 6:42pm

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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 {
Copy link
Contributor

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) {
Copy link
Contributor

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:

  1. Introduces a reusable PostFilter type
  2. Separates filtering logic into composable functions
  3. Makes it easier to add new filters in the future
  4. Maintains existing functionality while reducing complexity

@duyet duyet merged commit d6ab155 into master Nov 11, 2024
6 of 8 checks passed
@duyet duyet deleted the feat/ui-update branch November 11, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant