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(blog): update home #543

Merged
merged 2 commits into from
Nov 1, 2024
Merged

feat(blog): update home #543

merged 2 commits into from
Nov 1, 2024

Conversation

duyet
Copy link
Owner

@duyet duyet commented Nov 1, 2024

Summary by Sourcery

Update the blog's home page to display posts grouped by year, enhancing navigation and readability. Introduce a new page component for displaying posts by year. Improve tag normalization for consistent formatting. Update blog post metadata for clarity.

New Features:

  • Introduce a new page component for displaying blog posts by year, enhancing the blog's navigation and user experience.

Enhancements:

  • Refactor the blog's home page to display posts grouped by year, improving the organization and readability of the content.
  • Update tag normalization to ensure consistent formatting across the blog, enhancing tag management and searchability.

Documentation:

  • Update blog post metadata and content for improved clarity and consistency.

Copy link
Contributor

sourcery-ai bot commented Nov 1, 2024

Reviewer's Guide by Sourcery

This PR updates the blog's home page to display posts grouped by year instead of a paginated feed, improves tag normalization, and consolidates date formatting utilities. The changes also include various tag cleanup and categorization improvements across blog posts.

Updated class diagram for post fetching and display

classDiagram
    class Page {
        +Page()
        +postsByYear: Map
        +postCount: int
        +pastYears: int
    }
    class getPostsByAllYear {
        +getPostsByAllYear(fields: string[]): Map
    }
    class YearPost {
        +YearPost(year: int)
    }
    Page --> getPostsByAllYear
    Page --> YearPost

    class normalizeTag {
        +normalizeTag(tag: string): string
    }
    class dateFormat {
        +dateFormat(date: Date, formatString: string): string
    }
    class distanceToNow {
        +distanceToNow(dateTime: number | Date): string
    }
    class distanceFormat {
        +distanceFormat(from: Date, to: Date): string
    }

    class TagList {
        +TagList(tags: TagCount)
    }
    TagList --> normalizeTag

    class Feed {
        +Feed(posts: Post[])
    }
    Page --> Feed
Loading

File-Level Changes

Change Details Files
Redesigned the home page to show posts grouped by year
  • Moved existing feed page implementation to /feed route
  • Added new year-based post listing on home page
  • Added post count and years of blogging statistics
  • Updated navigation links to point to feed and tags pages
apps/blog/app/page.tsx
apps/blog/app/feed/page.tsx
apps/blog/components/year-post.tsx
Improved tag handling and normalization
  • Added tag normalization function to standardize tag capitalization
  • Updated getPost to normalize tags when loading posts
  • Cleaned up and consolidated similar tags across blog posts
packages/libs/tags.ts
packages/libs/getPost.ts
apps/blog/_posts/**/*.md
Consolidated date formatting utilities
  • Created new date.ts module with combined date formatting functions
  • Replaced individual dateRelative imports with consolidated date module
  • Added new dateFormat function for flexible date formatting
packages/libs/date.ts
packages/libs/dateRelative.ts
packages/components/CommentContent.tsx
apps/blog/app/[year]/[month]/[slug]/meta/meta.tsx

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 1, 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 1, 2024 6:14am
cv 🛑 Canceled (Inspect) Nov 1, 2024 6:14am
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 1, 2024 6:14am

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: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 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.

Comment on lines +7 to +15
const normalizedTag = tag
.split(' ')
.filter((word) => word.length > 0)
.map((word) => {
return word[0].toUpperCase() + word.toLowerCase().substring(1)
})
.join(' ')

return normalizedTag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Suggested change
const normalizedTag = tag
.split(' ')
.filter((word) => word.length > 0)
.map((word) => {
return word[0].toUpperCase() + word.toLowerCase().substring(1)
})
.join(' ')
return normalizedTag
return tag
.split(' ')
.filter((word) => word.length > 0)
.map((word) => {
return word[0].toUpperCase() + word.toLowerCase().substring(1)
})
.join(' ');


ExplanationSomething that we often see in people's code is assigning to a result variable
and then immediately returning it.

Returning the result directly shortens the code and removes an unnecessary
variable, reducing the mental load of reading the function.

Where intermediate variables can be useful is if they then get used as a
parameter or a condition, and the name can act like a comment on what the
variable represents. In the case where you're returning it from a function, the
function name is there to tell you what the result is, so the variable name
is unnecessary.

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