Skip to content

Commit

Permalink
Add top blog
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Dec 3, 2024
1 parent 3f23e06 commit dc32cef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ A static blog template built with [Astro](https://astro.build).

### Top Blog


In [config](./src/config.ts), set the `topBlog` to the title of the desired top blog

## 🚀 How to Use

Expand Down
7 changes: 1 addition & 6 deletions src/components/PostPage.astro
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
---
import { getPostUrlBySlug } from '@utils/url-utils'
import PostCard from './PostCard.astro'
import { siteConfig } from '../config'
const { page } = Astro.props
let delay = 0
const interval = 50
const topBlogEntry = page.data.filter(entry => entry.title == siteConfig.topBlog)[0]
const orderedData = [topBlogEntry].concat(page.data.filter(entry => entry.title != siteConfig.topBlog))
---
<div class="transition flex flex-col rounded-[var(--radius-large)] bg-[var(--card-bg)] py-1 md:py-0 md:bg-transparent md:gap-4 mb-4">
{orderedData.map((entry: {
{page.data.map((entry: {
data: {
draft: boolean;
title: string;
Expand Down
8 changes: 8 additions & 0 deletions src/utils/content-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getCollection } from 'astro:content'
import type { BlogPostData } from '@/types/config'
import I18nKey from '@i18n/i18nKey'
import { i18n } from '@i18n/translation'
import { siteConfig } from '../config'

export async function getSortedPosts(): Promise<
{ body: string, data: BlogPostData; slug: string }[]
Expand All @@ -12,6 +13,13 @@ export async function getSortedPosts(): Promise<

const sorted = allBlogPosts.sort(
(a: { data: BlogPostData }, b: { data: BlogPostData }) => {
if (a.data.title == siteConfig.topBlog) {
return -1
}
if (b.data.title == siteConfig.topBlog) {
return 1
}

const dateA = new Date(a.data.published)
const dateB = new Date(b.data.published)
return dateA > dateB ? -1 : 1
Expand Down

0 comments on commit dc32cef

Please sign in to comment.