Skip to content

Commit

Permalink
feat: update next to v13.4
Browse files Browse the repository at this point in the history
  • Loading branch information
CaliCastle committed May 4, 2023
1 parent d5c1e85 commit 1fbfa96
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 330 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/(home)/NewsletterSignup.tsx → app/Newsletter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const newsletterFormSchema = z.object({
})
export type NewsletterForm = z.infer<typeof newsletterFormSchema>

export function NewsletterSignup() {
export function Newsletter() {
const {
register,
handleSubmit,
Expand Down
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions app/_actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use server'

import { z } from 'zod'

import { env } from '~/env.mjs'
import { withValidate } from '~/lib/validation'

export const subscribeToNewsletter = withValidate(
z.object({
email: z.string().email({ message: '邮箱地址不正确' }).nonempty(),
}),
async ({ email }) => {
const url = [
'https://api.convertkit.com/v3',
'forms',
'5108903', // formId
'subscribe',
].join('/')

const headers = new Headers({
'Content-Type': 'application/json; charset=utf-8',
})

const res = await fetch(url, {
method: 'POST',
headers,
cache: 'no-cache',
body: JSON.stringify({
api_key: env.CONVERTKIT_API_KEY,
email,
tags: [
// cali.so newsletter tag
3817600,
// Chinese newsletter tag
3817754,
],
}),
})

if (!res.ok) {
throw new Error('Failed to subscribe')
}
}
)
17 changes: 2 additions & 15 deletions app/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
type MdxFrontMatter = {
title: string
publishedAt: string
tags: string[]
image?: string
summary?: string
}
type MDXComponent = {
default: React.FC
meta: MdxFrontMatter
}

declare module '*.mdx' {
export default MDXComponent
export const meta: MdxFrontMatter
type NewsletterFormData = {
email: string
}
10 changes: 5 additions & 5 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Headline } from '~/app/(home)/Headline'
import { NewsletterSignup } from '~/app/(home)/NewsletterSignup'
import { Photos } from '~/app/(home)/Photos'
import { Resume } from '~/app/(home)/Resume'
import { Headline } from '~/app/Headline'
import { Newsletter } from '~/app/Newsletter'
import { Photos } from '~/app/Photos'
import { Resume } from '~/app/Resume'
import { Container } from '~/components/ui/Container'

export default function HomePage() {
Expand All @@ -15,7 +15,7 @@ export default function HomePage() {
<div className="mx-auto grid max-w-xl grid-cols-1 gap-y-20 lg:max-w-none lg:grid-cols-2">
<div className="flex flex-col gap-16"></div>
<aside className="space-y-10 lg:pl-16 xl:pl-24">
<NewsletterSignup />
<Newsletter />
<Resume />
</aside>
</div>
Expand Down
3 changes: 0 additions & 3 deletions lib/helper.ts

This file was deleted.

10 changes: 10 additions & 0 deletions lib/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { type ZodSchema } from 'zod'

export function withValidate<TData>(
schema: ZodSchema<TData>,
action: (data: TData) => void
) {
return (formData: FormData) => {
return action(schema.parse(Object.fromEntries(formData.entries())))
}
}
53 changes: 5 additions & 48 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import withMdx from '@next/mdx'
import { get } from '@vercel/edge-config'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypePrettyCode from 'rehype-pretty-code'
import rehypeSlug from 'rehype-slug'
import remarkGfm from 'remark-gfm'

/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
Expand All @@ -15,13 +8,12 @@ import remarkGfm from 'remark-gfm'

/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
scrollRestoration: true,
},
// experimental: {
// serverActions: true,
// },

images: {
domains: ['assets.cali.so'],
domains: ['cdn.sanity.io'],
},

async redirects() {
Expand All @@ -33,39 +25,4 @@ const nextConfig = {
},
}

export default withMdx({
extension: /\.mdx?$/,
options: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
rehypeSlug,
[
rehypePrettyCode,
{
theme: 'one-dark-pro',
onVisitLine(node) {
// Prevent lines from collapsing in `display: grid` mode, and allow empty
// lines to be copy/pasted
if (node.children.length === 0) {
node.children = [{ type: 'text', value: ' ' }]
}
},
onVisitHighlightedLine(node) {
node.properties.className.push('line--highlighted')
},
onVisitHighlightedWord(node) {
node.properties.className = ['word--highlighted']
},
},
],
[
rehypeAutolinkHeadings,
{
properties: {
className: ['anchor'],
},
},
],
],
},
})(nextConfig)
export default nextConfig
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@
"lint": "next lint"
},
"dependencies": {
"@clerk/nextjs": "^4.16.4",
"@clerk/nextjs": "^4.17.0",
"@headlessui/react": "^1.7.14",
"@hookform/resolvers": "^3.1.0",
"@mdx-js/loader": "^2.3.0",
"@next/mdx": "^13.3.4",
"@portabletext/react": "^3.0.0",
"@radix-ui/react-select": "^1.2.1",
"@radix-ui/react-tooltip": "^1.0.5",
"@sanity/image-url": "^1.0.2",
"@upstash/redis": "^1.20.5",
"@vercel/analytics": "^1.0.0",
"@upstash/redis": "^1.20.6",
"@vercel/analytics": "^1.0.1",
"@vercel/edge-config": "^0.1.9",
"@zolplay/react": "^0.5.1",
"@zolplay/utils": "^1.3.4",
"dayjs": "^1.11.7",
"framer-motion": "^10.12.7",
"next": "^13.3.4",
"next-sanity": "^4.2.0",
"next": "^13.4.0",
"next-sanity": "^4.3.2",
"next-themes": "^0.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -44,16 +43,15 @@
"devDependencies": {
"@tailwindcss/typography": "^0.5.9",
"@types/eslint": "^8.37.0",
"@types/mdx": "^2.0.5",
"@types/node": "^18.16.3",
"@types/prettier": "^2.7.2",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.1",
"@types/react": "^18.2.5",
"@types/react-dom": "^18.2.3",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"autoprefixer": "^10.4.14",
"eslint": "^8.39.0",
"eslint-config-next": "^13.3.4",
"eslint-config-next": "^13.4.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
Expand Down
Loading

0 comments on commit 1fbfa96

Please sign in to comment.