Skip to content

Commit

Permalink
chore: optimize preview config
Browse files Browse the repository at this point in the history
  • Loading branch information
CaliCastle committed Jul 15, 2023
1 parent 3681794 commit 026a21e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ DATABASE_PASSWORD=""
DATABASE_URL=""
DATABASE_USERNAME=""

# 链接预览图 API 必需
LINK_PREVIEW_API_BASE_URL=""

# Sanity CMS 必需
NEXT_PUBLIC_SANITY_DATASET=""
NEXT_PUBLIC_SANITY_PROJECT_ID=""
Expand Down
2 changes: 1 addition & 1 deletion app/api/link-preview/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function GET(req: NextRequest) {
const { searchParams } = new URL(req.url)
const url = searchParams.get('url')

if (!url) {
if (!url || !env.LINK_PREVIEW_API_BASE_URL) {
return NextResponse.error()
}

Expand Down
19 changes: 19 additions & 0 deletions components/links/PeekabooLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { RichLink } from '~/components/links/RichLink'
import { HoverCard } from '~/components/ui/HoverCard'
import { makeBlurDataURL } from '~/lib/image'

// 改成 false 就可以关闭链接预览快照图了
const supportsPreview = true

type PeekabooLinkProps = LinkProps &
React.ComponentPropsWithoutRef<'a'> & {
children: React.ReactNode
Expand All @@ -32,6 +35,22 @@ export function PeekabooLink({
)
}

if (!supportsPreview) {
return (
<RichLink
href={href}
className={clsxm(
'font-semibold text-zinc-800 hover:underline dark:text-zinc-100',
className
)}
target="_blank"
{...props}
>
{children}
</RichLink>
)
}

function onOpenChange(open: boolean) {
setIsOpen(open)
}
Expand Down
2 changes: 1 addition & 1 deletion env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const server = z.object({
VERCEL_ENV: z.enum(['development', 'preview', 'production']),
UPSTASH_REDIS_REST_URL: z.string().min(1),
UPSTASH_REDIS_REST_TOKEN: z.string().min(1),
LINK_PREVIEW_API_BASE_URL: z.string().min(1),
LINK_PREVIEW_API_BASE_URL: z.string().optional(),
SITE_NOTIFICATION_EMAIL_TO: z.string().optional(),
})

Expand Down

0 comments on commit 026a21e

Please sign in to comment.