From 1d0fc46b56387709474b501e5041ca991e52c2ed Mon Sep 17 00:00:00 2001 From: JiPai <3956400+PaiJi@users.noreply.github.com> Date: Fri, 6 Sep 2024 22:32:01 +0800 Subject: [PATCH] feat: use new API replace Xata (#202) * feat: use new API replace Xata * fix: fix zod schema * chore: kick out xata and superjson * chore: use new type * chore: update CI env --- .env.example | 13 +- .github/workflows/deploy-self-host.yml | 4 + .github/workflows/nextjs_bundle_analysis.yml | 5 +- .nvmrc | 2 +- README.md | 10 +- README.zh.md | 10 +- next.config.js | 14 +- package.json | 28 +- public/locales/en/common.json | 2 +- public/locales/zh-Hans/common.json | 2 +- src/api/index.ts | 14 + src/components/SimpleEventCard/index.tsx | 26 +- src/components/eventCard/index.tsx | 14 +- src/components/organizationStatus/index.tsx | 2 +- src/pages/500.tsx | 39 + src/pages/[organization]/[slug].tsx | 115 +- src/pages/[organization]/index.tsx | 149 +- src/pages/city.tsx | 80 +- src/pages/index.tsx | 63 +- src/pages/organization.tsx | 42 +- src/pages/years.tsx | 42 +- src/types/event.ts | 51 + src/types/organization.ts | 30 +- src/utils/event.ts | 48 +- src/utils/imageLoader.ts | 6 +- src/xata/xata.ts | 90 - yarn.lock | 1657 +++++++++--------- 27 files changed, 1384 insertions(+), 1174 deletions(-) create mode 100644 src/api/index.ts create mode 100644 src/pages/500.tsx delete mode 100644 src/xata/xata.ts diff --git a/.env.example b/.env.example index bddf473..549b0ba 100644 --- a/.env.example +++ b/.env.example @@ -1,14 +1,9 @@ -# API key used by the CLI and the SDK -# Make sure your framework/tooling loads this file on startup to have it available for the SDK -XATA_API_KEY= -# Xata branch that will be used if there's not a xata branch with the same name as your git branch -XATA_BRANCH=main -XATA_FALLBACK_BRANCH=main - -NEXT_PUBLIC_ENABLE_TRACK=false SENTRY_AUTH_TOKEN= +NEXT_PUBLIC_SENTRY_DSN= +FEC_API_TOKEN= + +NEXT_PUBLIC_ENABLE_TRACK=false NEXT_PUBLIC_REGION=GLOBAL NEXT_PUBLIC_WEBSITE_URL=www.furryeventchina.com NEXT_PUBLIC_STATIC_CDN_URL=https://static.furrycons.cn -NEXT_PUBLIC_SENTRY_DSN= \ No newline at end of file diff --git a/.github/workflows/deploy-self-host.yml b/.github/workflows/deploy-self-host.yml index 4309db7..4f85377 100644 --- a/.github/workflows/deploy-self-host.yml +++ b/.github/workflows/deploy-self-host.yml @@ -20,6 +20,7 @@ jobs: NEXT_PUBLIC_REGION: ${{ vars.NEXT_PUBLIC_REGION }} NEXT_PUBLIC_STATIC_CDN_URL: ${{vars.NEXT_PUBLIC_STATIC_CDN_URL}} NEXT_PUBLIC_WEBSITE_URL: ${{vars.NEXT_PUBLIC_WEBSITE_URL}} + FEC_API_TOKEN: ${{vars.FEC_API_TOKEN}} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -34,6 +35,7 @@ jobs: echo NEXT_PUBLIC_ENABLE_TRACK="$ENABLE_TRACK" >> .env echo NEXT_PUBLIC_STATIC_CDN_URL="$NEXT_PUBLIC_STATIC_CDN_URL" >>.env echo NEXT_PUBLIC_WEBSITE_URL="$NEXT_PUBLIC_WEBSITE_URL" >>.env + echo FEC_API_TOKEN="$FEC_API_TOKEN" >>.env - name: Login to ACR uses: aliyun/acr-login@v1 @@ -62,6 +64,7 @@ jobs: NEXT_PUBLIC_REGION: ${{ vars.NEXT_PUBLIC_REGION }} NEXT_PUBLIC_SENTRY_DSN: ${{vars.NEXT_PUBLIC_SENTRY_DSN}} NEXT_PUBLIC_WEBSITE_URL: ${{vars.NEXT_PUBLIC_WEBSITE_URL}} + FEC_API_TOKEN: ${{vars.FEC_API_TOKEN}} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -76,6 +79,7 @@ jobs: echo NEXT_PUBLIC_REGION="$NEXT_PUBLIC_REGION" >>.env echo NEXT_PUBLIC_SENTRY_DSN="$NEXT_PUBLIC_SENTRY_DSN" >>.env echo NEXT_PUBLIC_WEBSITE_URL="$NEXT_PUBLIC_WEBSITE_URL" >>.env + echo FEC_API_TOKEN="$FEC_API_TOKEN" >>.env - name: Login to ACR uses: aliyun/acr-login@v1 diff --git a/.github/workflows/nextjs_bundle_analysis.yml b/.github/workflows/nextjs_bundle_analysis.yml index e856435..0700267 100644 --- a/.github/workflows/nextjs_bundle_analysis.yml +++ b/.github/workflows/nextjs_bundle_analysis.yml @@ -1,7 +1,7 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 -name: 'Next.js Bundle Analysis' +name: "Next.js Bundle Analysis" on: pull_request: @@ -29,6 +29,7 @@ jobs: XATA_FALLBACK_BRANCH: ${{ vars.XATA_FALLBACK_BRANCH }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} NEXT_PUBLIC_ENABLE_TRACK: ${{ vars.ENABLE_TRACK }} + FEC_API_TOKEN: ${{vars.FEC_API_TOKEN}} steps: - uses: actions/checkout@v3 @@ -117,7 +118,7 @@ jobs: id: fc with: issue-number: ${{ github.event.number }} - body-includes: '' + body-includes: "" - name: Create Comment uses: peter-evans/create-or-update-comment@v2 diff --git a/.nvmrc b/.nvmrc index c32828c..0a47c85 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -lts/hydrogen \ No newline at end of file +lts/iron \ No newline at end of file diff --git a/README.md b/README.md index 8ad78e4..0543593 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ![](https://img.shields.io/badge/Sentry-purple.svg?style=flat-square&logo=sentry) ![](https://img.shields.io/badge/Umami-orange.svg?style=flat-square&logo=umami) ![](https://img.shields.io/badge/Google%20Analytics%205-blue.svg?style=flat-square&logo=google-analytics) -![](https://img.shields.io/badge/Xata-blue.svg?style=flat-square&logo=xata) +![](https://img.shields.io/badge/Hono.js-blue.svg?style=flat-square&logo=hono) ![](https://img.shields.io/badge/Cloudflare%20R2-blue.svg?style=flat-square&logo=cloudflare) ![](https://img.shields.io/badge/Cloudflare%20Worker-blue.svg?style=flat-square&logo=cloudflare) ![](https://img.shields.io/badge/CloudFront-orange.svg?style=flat-square&logo=amazon-aws) @@ -16,7 +16,15 @@ ## Start Developing +### Env config + +Copy `.env.example` and paste it, `FEC_API_TOKEN` needs to be obtained by registering in our console, the rest like Sentry do not need configuration. + ```bash +nvm use + +corepack enable + yarn install yarn dev ``` diff --git a/README.zh.md b/README.zh.md index a30642d..da7eb49 100644 --- a/README.zh.md +++ b/README.zh.md @@ -5,7 +5,7 @@ ![](https://img.shields.io/badge/Sentry-purple.svg?style=flat-square&logo=sentry) ![](https://img.shields.io/badge/Umami-orange.svg?style=flat-square&logo=umami) ![](https://img.shields.io/badge/Google%20Analytics%205-blue.svg?style=flat-square&logo=google-analytics) -![](https://img.shields.io/badge/Xata-blue.svg?style=flat-square&logo=xata) +![](https://img.shields.io/badge/Hono.js-blue.svg?style=flat-square&logo=hono) ![](https://img.shields.io/badge/Cloudflare%20R2-blue.svg?style=flat-square&logo=cloudflare) ![](https://img.shields.io/badge/Cloudflare%20Worker-blue.svg?style=flat-square&logo=cloudflare) ![](https://img.shields.io/badge/CloudFront-orange.svg?style=flat-square&logo=amazon-aws) @@ -16,7 +16,15 @@ ## 开始开发 +### 配置环境变量 + +复制 `.env.example`并粘贴,`FEC_API_TOKEN`需在我们的控制台注册获取,其余如 Sentry 等无需配置。 + ```bash +nvm use + +corepack enable + yarn install yarn dev ``` diff --git a/next.config.js b/next.config.js index 8bfcb2c..7f3f48e 100644 --- a/next.config.js +++ b/next.config.js @@ -9,7 +9,9 @@ const { withSentryConfig } = require("@sentry/nextjs"); const { GitRevisionPlugin } = require("git-revision-webpack-plugin"); const withBundleAnalyzer = require("@next/bundle-analyzer")({ - enabled: process.env.NODE_ENV === "production", + enabled: + process.env.NODE_ENV === "production" && + process.env.NEXT_PUBLIC_ENABLE_TRACK === "true", }); const { i18n } = require("./next-i18next.config"); @@ -31,16 +33,6 @@ const nextConfig = { loaderFile: "./src/utils/imageLoader.ts", }, assetPrefix: isProd && STATIC_CDN_URL ? STATIC_CDN_URL : undefined, - experimental: { - swcPlugins: [ - [ - "next-superjson-plugin", - { - excluded: [], - }, - ], - ], - }, sentry: { // disableClientWebpackPlugin: true, // disableServerWebpackPlugin: true, diff --git a/package.json b/package.json index df6a45f..f082a79 100644 --- a/package.json +++ b/package.json @@ -7,30 +7,27 @@ "build": "next build && next-sitemap", "start": "next start", "lint": "next lint", - "generate-schama": "xata codegen", "clean": "rm -rf .next && rm -rf out" }, "dependencies": { - "@headlessui/react": "^2.1.3", - "@next/third-parties": "^14.2.7", + "@headlessui/react": "^2.1.5", + "@next/third-parties": "^14.2.8", "@radix-ui/react-collapsible": "^1.1.0", "@sentry/nextjs": "^7.119.0", - "@xata.io/client": "^0.29.5", "autoprefixer": "^10.4.20", "clsx": "^2.1.1", "date-fns": "^3.6.0", - "embla-carousel-autoplay": "^8.2.0", - "embla-carousel-react": "^8.2.0", + "embla-carousel-autoplay": "^8.2.1", + "embla-carousel-react": "^8.2.1", "eslint": "8.57.0", - "eslint-config-next": "14.2.7", + "eslint-config-next": "14.2.8", "git-revision-webpack-plugin": "^5.0.0", "i18next": "^23.14.0", "lodash-es": "^4.17.21", - "next": "14.2.7", + "next": "14.2.8", "next-i18next": "^15.3.1", "next-sitemap": "^4.2.3", - "next-superjson-plugin": "^0.6.3", - "postcss": "^8.4.41", + "postcss": "^8.4.45", "postcss-flexbugs-fixes": "^5.0.2", "postcss-nested": "^6.2.0", "postcss-preset-env": "^9.6.0", @@ -39,18 +36,19 @@ "react-hot-toast": "^2.4.1", "react-i18next": "^15.0.1", "react-icons": "^5.3.0", - "superjson": "1.13.3", "tailwindcss": "^3.4.10", - "typescript": "5.5.4" + "typescript": "5.5.4", + "wretch": "^2.9.0", + "zod": "^3.23.8" }, "devDependencies": { - "@next/bundle-analyzer": "^14.2.7", + "@next/bundle-analyzer": "^14.2.8", "@types/lodash-es": "^4.17.12", - "@types/node": "20.16.2", + "@types/node": "20.16.5", "@types/react": "18.3.5", "@types/react-dom": "18.3.0" }, - "packageManager": "yarn@4.0.2", + "packageManager": "yarn@4.4.1", "nextBundleAnalysis": { "budget": 358400, "budgetPercentIncreaseRed": 20, diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 02f303d..4c375f6 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -66,7 +66,7 @@ }, "organization": { "active": "Active Organizers", - "deactive": "Inactive Organizers", + "inactive": "Inactive Organizers", "createdAt": "Established {{distance}} ago", "firstTimeEvent": "First held on {{year}}/{{month}}/{{day}}", "firstTimeShow": "First appeared on {{year}}/{{month}}/{{day}}", diff --git a/public/locales/zh-Hans/common.json b/public/locales/zh-Hans/common.json index 535b81f..f6f1bb5 100644 --- a/public/locales/zh-Hans/common.json +++ b/public/locales/zh-Hans/common.json @@ -66,7 +66,7 @@ }, "organization": { "active": "活跃展商", - "deactive": "停止活动展商", + "inactive": "停止活动展商", "createdAt": "已创立 {{distance}}", "firstTimeEvent": "首次举办于 {{year}}年{{month}}月{{day}}日", "firstTimeShow": "首次出现于 {{year}}年{{month}}月{{day}}日", diff --git a/src/api/index.ts b/src/api/index.ts new file mode 100644 index 0000000..a27bbdd --- /dev/null +++ b/src/api/index.ts @@ -0,0 +1,14 @@ +import wretch from "wretch"; +import QueryStringAddon from "wretch/addons/queryString"; + +wretch.options({ mode: "cors" }); + +const HOST = + process.env.NEXT_PUBLIC_REGION === "CN" + ? "https://api.furrycons.cn" + : "https://api.furryeventchina.com"; + +const wfetch = wretch(HOST, { cache: "default" }) + .auth(`Bearer ${process.env.FEC_API_TOKEN}`) + .addon(QueryStringAddon); +export default wfetch; diff --git a/src/components/SimpleEventCard/index.tsx b/src/components/SimpleEventCard/index.tsx index ac8f503..3547608 100644 --- a/src/components/SimpleEventCard/index.tsx +++ b/src/components/SimpleEventCard/index.tsx @@ -1,9 +1,9 @@ import { sendTrack } from "@/utils/track"; -import { Event } from "@/xata/xata"; import Link from "next/link"; import { format } from "date-fns"; +import { EventType } from "@/types/event"; -function SimpleEventCard({ event }: { event: Event }) { +function SimpleEventCard({ event }: { event: EventType }) { return ( - {/*
{event.organization?.name}
- {event.startDate && event.endDate && ( + {event.startAt && event.endAt && (- {event.startDate && ( - {format(event.startDate, "MM月dd日")} - )} - - - {event.endDate && ( - {format(event.endDate, "MM月dd日")} - )} + {event.startAt && {format(event.startAt, "MM月dd日")}}- + {event.endAt && {format(event.endAt, "MM月dd日")}}
)}- {event.startDate && ( - {format(event.startDate, "MM月dd日")} - )} - - - {event.startDate && ( - {format(event.startDate, "MM月dd日")} + {event.startAt && ( + {format(event.startAt, "MM月dd日")} )} + -{event.endAt && {format(event.endAt, "MM月dd日")}}
)}