Skip to content

Commit

Permalink
fix: date tz
Browse files Browse the repository at this point in the history
  • Loading branch information
CaliCastle committed May 22, 2023
1 parent 9a3eb31 commit 3fb8ff0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/api/favicon/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const faviconMapper: { [key: string]: string } = {
'(?:github.com)': 'https://cali.so/favicons/github.png',
'((?:t.co)|(?:twitter.com))': 'https://cali.so/favicons/twitter.png',
'coolshell.cn': 'https://cali.so/favicons/coolshell.png',
'vercel.com': 'https://cali.so/favicons/vercel.png',
}

function getPredefinedIconForUrl(url: string): string | undefined {
Expand Down Expand Up @@ -73,7 +74,7 @@ export async function GET(req: NextRequest) {
return renderFavicon(cachedFavicon)
}

const res = await fetch(url, {
const res = await fetch(new URL(`https://${url}`).href, {
headers: {
'Content-Type': 'text/html',
},
Expand All @@ -88,7 +89,7 @@ export async function GET(req: NextRequest) {
const shortcutFavicon = $('link[rel="shortcut icon"]').attr('href')
const finalFavicon = appleTouchIcon ?? favicon ?? shortcutFavicon
if (finalFavicon) {
iconUrl = new URL(finalFavicon, url).href
iconUrl = new URL(finalFavicon, new URL(`https://${url}`).href).href
}
}

Expand Down
10 changes: 10 additions & 0 deletions lib/date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import dayjs from 'dayjs'
import timezone from 'dayjs/plugin/timezone'
import utc from 'dayjs/plugin/utc'

dayjs.extend(utc)
dayjs.extend(timezone)

export function getDate(timezone = 'Asia/Shanghai'): dayjs.Dayjs {
return dayjs().tz(timezone)
}
Binary file added public/favicons/vercel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions sanity/queries.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { groq } from 'next-sanity'

import { getDate } from '~/lib/date'
import { clientFetch } from '~/sanity/lib/client'
import { type Post } from '~/sanity/schemas/post'

export const getLatestBlogPostsQuery = (limit = 5) =>
groq`
*[_type == "post" && !(_id in path("drafts.**")) && publishedAt <= "${
new Date().toISOString().split('T')[0]
}" && defined(slug.current)][0...${limit}] | order(publishedAt desc) {
*[_type == "post" && !(_id in path("drafts.**")) && publishedAt <= "${getDate().format(
'YYYY-MM-DD'
)}" && defined(slug.current)][0...${limit}] | order(publishedAt desc) {
_id,
title,
"slug": slug.current,
Expand All @@ -23,8 +24,9 @@ export const getLatestBlogPostsQuery = (limit = 5) =>
}
}
}`
export const getLatestBlogPosts = (limit = 5) =>
clientFetch<Post[]>(getLatestBlogPostsQuery(limit))
export const getLatestBlogPosts = (limit = 5) => {
return clientFetch<Post[]>(getLatestBlogPostsQuery(limit))
}

export const getBlogPostQuery = (slug: string) =>
groq`
Expand Down

0 comments on commit 3fb8ff0

Please sign in to comment.