From 7e8c43c0f65d96f1ad4feb8f7e8579b443b92b5d Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 23 Feb 2023 03:37:06 +0000 Subject: [PATCH] feat: index page and site page i18n --- next-i18next.config.js | 1 + next.config.js | 5 - public/locales/en/common.json | 3 +- public/locales/en/dashboard.json | 1 + public/locales/en/index.json | 5 + public/locales/en/site.json | 4 + public/locales/zh/common.json | 31 +++++- public/locales/zh/dashboard.json | 1 + public/locales/zh/index.json | 26 +++++ public/locales/zh/site.json | 8 ++ src/components/common/BlockchainInfo.tsx | 31 +++--- src/components/common/Comment.tsx | 10 +- src/components/common/CommentInput.tsx | 17 ++-- src/components/common/CommentItem.tsx | 4 +- src/components/common/ConnectButton.tsx | 12 ++- src/components/common/FollowingButton.tsx | 12 ++- src/components/common/FollowingCount.tsx | 6 +- src/components/dashboard/PagesManager.tsx | 17 +++- src/components/main/MainLayout.tsx | 9 +- src/components/site/PostMeta.tsx | 24 ++--- src/components/site/SiteHeader.tsx | 8 +- src/components/site/SiteHome.tsx | 36 ++++--- src/components/site/SiteLayout.server.tsx | 8 +- src/lib/language-detector.ts | 8 +- src/pages/_site/[site]/[page].tsx | 14 ++- src/pages/_site/[site]/archives.tsx | 14 ++- src/pages/_site/[site]/index.tsx | 14 ++- src/pages/_site/[site]/nft.tsx | 14 ++- src/pages/_site/[site]/tag/[tag].tsx | 14 ++- src/pages/index.tsx | 115 +++++++++------------- 30 files changed, 305 insertions(+), 167 deletions(-) create mode 100644 public/locales/en/dashboard.json create mode 100644 public/locales/en/index.json create mode 100644 public/locales/en/site.json create mode 100644 public/locales/zh/dashboard.json create mode 100644 public/locales/zh/index.json create mode 100644 public/locales/zh/site.json diff --git a/next-i18next.config.js b/next-i18next.config.js index 7cf82e97..a733b6a9 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -2,5 +2,6 @@ module.exports = { i18n: { defaultLocale: "en", locales: ["en", "zh"], + reloadOnPrerender: process.env.NODE_ENV === "development", }, } diff --git a/next.config.js b/next.config.js index 1341a1fa..e1977952 100644 --- a/next.config.js +++ b/next.config.js @@ -112,10 +112,5 @@ module.exports = withBundleAnalyzer( ENV_OPENSEA_API_KEY: process.env.OPENSEA_API_KEY, ENV_POAP_API_KEY: process.env.POAP_API_KEY, }, - - i18n: { - ...i18n, - localeDetection: false, - }, }), ) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 0222f651..59492dd1 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -1,3 +1,4 @@ { - "easy": "Easy" + "intlDateTime": "{{val, datetime}}", + "intlRelativeTime": "{{val, relativetime}}" } \ No newline at end of file diff --git a/public/locales/en/dashboard.json b/public/locales/en/dashboard.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/public/locales/en/dashboard.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/public/locales/en/index.json b/public/locales/en/index.json new file mode 100644 index 00000000..8b9a530e --- /dev/null +++ b/public/locales/en/index.json @@ -0,0 +1,5 @@ +{ + "description": "xLog, <1>on-chain and <3>open-source blogging platform for everyone.", + "discover awesome": "Discover these awesome teams and geeks on xLog (sorted by update time)", + "Integration description": "xLog's open design allows it to integrate with many other open protocols and applications without friction." +} \ No newline at end of file diff --git a/public/locales/en/site.json b/public/locales/en/site.json new file mode 100644 index 00000000..1c8a1111 --- /dev/null +++ b/public/locales/en/site.json @@ -0,0 +1,4 @@ +{ + "load more": "There are {{count}} more {{name}}, click to load more", + "signed and stored on the blockchain": "This {{name}} has been signed and securely stored on the blockchain by its creator." +} \ No newline at end of file diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index 0bddd792..fceaa6a0 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -1,3 +1,32 @@ { - "easy": "简单" + "Connect": "连接", + "Followers": "关注者", + "Following": "正在关注", + "Followings": "正在关注", + "Follow": "关注", + "Unfollow": "取消关注", + "intlDateTime": "{{val, datetime}}", + "intlRelativeTime": "{{val, relativetime}}", + "post": "文章", + "posts": "文章", + "page": "页面", + "pages": "页面", + "comment": "评论", + "comments": "评论", + "Comment": "评论", + "Comments": "评论", + "reply": "回复", + "replies": "回复", + "like": "喜欢", + "likes": "喜欢", + "blog": "博客", + "Owner": "所有者", + "Transaction Hash": "交易哈希", + "IPFS Address": "IPF 地址", + "Creation": "创建", + "Last Update": "最后更新", + "Create Character": "创建角色", + "Submit": "提交", + "Reply": "回复", + "Cancel Reply": "取消回复" } \ No newline at end of file diff --git a/public/locales/zh/dashboard.json b/public/locales/zh/dashboard.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/public/locales/zh/dashboard.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/public/locales/zh/index.json b/public/locales/zh/index.json new file mode 100644 index 00000000..c9aee12c --- /dev/null +++ b/public/locales/zh/index.json @@ -0,0 +1,26 @@ +{ + "Blog Free": "自由创作", + "description": "xLog,给所有人的 <1>链上 <3>开源 博客平台。", + "Get my xLog in 5 minutes": "5 分钟拥有自己的 xLog", + "Features": "特点", + "Showcase": "展示", + "Integration": "集成", + "Source Code": "源码", + "Visit": "访问", + "Easy": "简单", + "Easy description": "使用 Web3钱包 或 电子邮件 连接,轻松构建拥有自定义域名、订阅、点赞、评论、NFT铸造、RSS等功能的个人网站,无需任何费用和限制。", + "Safe": "安全", + "Safe description": "所有的博客数据,包括配置、文章、订阅、评论等,都由你亲手签名并安全地存储在区块链上,除了你自己,包括我们在内的任何人都无法进行更改。", + "Fast": "快速", + "Fast description": "区块链不意味着低效。xLog 采用高效的缓存机制和多项优化措施,发挥了极致的性能。", + "Customizable": "可定制", + "Customizable description": "使用自己的域名,自定义网站风格,完全自由地打造你的网站。这是你的网站,没有任何限制。", + "Open": "开放", + "Open description": "采用标准的 Markdown 语法,并提供了导入和导出工具以及丰富的API,让迁入和迁出变得轻而易举。所有的代码都开源在 GitHub 上,所有的数据都透明地存储在区块链上。", + "discover awesome": "在 xLog 上发现这些超棒的团队和极客们(按更新时间排序)", + "Follow All!": "关注所有!", + "Show more": "显示更多", + "Submit yours": "提交你的", + "Integration description": "xLog 的开放式设计使其能够与许多其他开放协议和应用程序无缝集成,没有任何限制。", + "Dashboard": "仪表盘" +} \ No newline at end of file diff --git a/public/locales/zh/site.json b/public/locales/zh/site.json new file mode 100644 index 00000000..ed2b3624 --- /dev/null +++ b/public/locales/zh/site.json @@ -0,0 +1,8 @@ +{ + "Home": "主页", + "Archives": "归档", + "About": "关于", + "load more": "还有 {{count}} 篇{{name}},点击加载更多", + "signed and stored on the blockchain": "此{{name}}已经由它的创作者签名并安全地存储在区块链上。", + "Write a comment on the blockchain": "在区块链上写下你的评论" +} \ No newline at end of file diff --git a/src/components/common/BlockchainInfo.tsx b/src/components/common/BlockchainInfo.tsx index 719cbc92..f9f93e62 100644 --- a/src/components/common/BlockchainInfo.tsx +++ b/src/components/common/BlockchainInfo.tsx @@ -6,11 +6,15 @@ import { ChevronUpIcon } from "@heroicons/react/20/solid" import { BlockchainIcon } from "~/components/icons/BlockchainIcon" import { toIPFS, toGateway } from "~/lib/ipfs-parser" import { IPFS_GATEWAY } from "~/lib/env" +import { useTranslation } from "next-i18next" export const BlockchainInfo: React.FC<{ site?: Profile | null page?: Note | null }> = ({ site, page }) => { + const { t } = useTranslation("common") + const { t: siteT } = useTranslation("site") + return (
@@ -23,14 +27,15 @@ export const BlockchainInfo: React.FC<{ - This{" "} - {page - ? page.tags?.includes("post") - ? "post" - : "page" - : "blog"}{" "} - has been signed and securely stored on the blockchain by its - creator. + {siteT("signed and stored on the blockchain", { + name: t( + page + ? page.tags?.includes("post") + ? "post" + : "page" + : "blog", + ), + })} )}
  • -
    Owner
    +
    {t("Owner")}
  • -
    Transaction Hash
    +
    {t("Transaction Hash")}
  • -
    IPFS Address
    +
    {t("IPFS Address")}
    {page ? page.related_urls diff --git a/src/components/common/Comment.tsx b/src/components/common/Comment.tsx index aa8f5c9d..445ea43e 100644 --- a/src/components/common/Comment.tsx +++ b/src/components/common/Comment.tsx @@ -3,6 +3,7 @@ import { Note } from "~/lib/types" import { useGetComments } from "~/queries/page" import { CommentItem } from "~/components/common/CommentItem" import { CommentInput } from "~/components/common/CommentInput" +import { useTranslation } from "next-i18next" export const Comment: React.FC<{ page?: Note | null @@ -11,13 +12,18 @@ export const Comment: React.FC<{ const comments = useGetComments({ pageId: page?.id, }) + const { t } = useTranslation("common") return (
    - {comments.data?.count || "0"} Comment - {comments.data?.count && comments.data.count > 1 ? "s" : ""} + {comments.data?.count || "0"}{" "} + {t( + `Comment${ + comments.data?.count && comments.data.count > 1 ? "s" : "" + }`, + )}
    diff --git a/src/components/common/CommentInput.tsx b/src/components/common/CommentInput.tsx index bd56fd47..f5050687 100644 --- a/src/components/common/CommentInput.tsx +++ b/src/components/common/CommentInput.tsx @@ -11,6 +11,7 @@ import { useRouter } from "next/router" import { EmojiPicker } from "./EmojiPicker" import { Popover } from "@headlessui/react" import { FaceSmileIcon } from "@heroicons/react/24/outline" +import { useTranslation } from "next-i18next" export const CommentInput: React.FC<{ pageId?: string @@ -21,6 +22,8 @@ export const CommentInput: React.FC<{ const commentPage = useCommentPage() const router = useRouter() const [viewer, setViewer] = useState(null) + const { t } = useTranslation("common") + const { t: siteT } = useTranslation("site") useEffect(() => { if (userSites.isSuccess && userSites.data?.length) { @@ -73,7 +76,7 @@ export const CommentInput: React.FC<{ multiline maxLength={300} className="mb-2" - placeholder="Write a comment on the blockchain" + placeholder={siteT("Write a comment on the blockchain") || ""} {...form.register("content", {})} />
    @@ -101,11 +104,13 @@ export const CommentInput: React.FC<{ type="submit" isLoading={userSites.isLoading || commentPage.isLoading} > - {account - ? userSites.isSuccess && !userSites.data?.length - ? "Create Character" - : "Submit" - : "Connect"} + {t( + account + ? userSites.isSuccess && !userSites.data?.length + ? "Create Character" + : "Submit" + : "Connect", + )}
    diff --git a/src/components/common/CommentItem.tsx b/src/components/common/CommentItem.tsx index 2a38b43d..c590778e 100644 --- a/src/components/common/CommentItem.tsx +++ b/src/components/common/CommentItem.tsx @@ -11,6 +11,7 @@ import { Reactions } from "~/components/common/Reactions" import { useState } from "react" import { CommentInput } from "~/components/common/CommentInput" import { CharacterFloatCard } from "~/components/common/CharacterFloatCard" +import { useTranslation } from "next-i18next" export const CommentItem: React.FC<{ comment: NoteEntity & { @@ -20,6 +21,7 @@ export const CommentItem: React.FC<{ depth: number }> = ({ comment, originalId, depth }) => { const [replyOpen, setReplyOpen] = useState(false) + const { t } = useTranslation("common") return (
    setReplyOpen(!replyOpen)} > - {replyOpen ? "Cancel " : ""}Reply + {t(`${replyOpen ? "Cancel " : ""}Reply`)} {(comment as any)?.fromNotes?.count || 0} diff --git a/src/components/common/ConnectButton.tsx b/src/components/common/ConnectButton.tsx index 7ada79f6..f282ae0b 100644 --- a/src/components/common/ConnectButton.tsx +++ b/src/components/common/ConnectButton.tsx @@ -12,7 +12,6 @@ import { import { useAccountSites } from "~/queries/site" import { Avatar } from "~/components/ui/Avatar" import { Button } from "~/components/ui/Button" -import type { HeaderLinkType } from "~/components/site/SiteHeader" import { DashboardIcon } from "../icons/DashboardIcon" import { UniLink } from "../ui/UniLink" import { useEffect, useState } from "react" @@ -36,6 +35,14 @@ import { } from "@crossbell/notification" import { useAccountBalance } from "~/hooks/use-account-balance" import { Menu } from "~/components/ui/Menu" +import { useTranslation } from "next-i18next" + +type HeaderLinkType = { + icon?: React.ReactNode + label: string | JSX.Element + url?: string + onClick?: () => void +} export const ConnectButton: React.FC<{ left?: boolean @@ -87,6 +94,7 @@ export const ConnectButton: React.FC<{ const { isAllRead } = useNotifications() const [InsufficientBalance, setInsufficientBalance] = useState(false) + const { t } = useTranslation("common") useEffect(() => { if (balance) { @@ -184,7 +192,7 @@ export const ConnectButton: React.FC<{ style={{ height: avatarSize + "px" }} variant={variant || "primary"} > - Connect + {t("Connect")} ) } diff --git a/src/components/common/FollowingButton.tsx b/src/components/common/FollowingButton.tsx index 796f282a..cc550eeb 100644 --- a/src/components/common/FollowingButton.tsx +++ b/src/components/common/FollowingButton.tsx @@ -10,6 +10,7 @@ import { import { useConnectedAction } from "@crossbell/connect-kit" import clsx from "clsx" import { Profile } from "~/lib/types" +import { useTranslation } from "next-i18next" export const FollowingButton: React.FC<{ site: Profile | undefined | null @@ -22,6 +23,7 @@ export const FollowingButton: React.FC<{ const unsubscribeFromSite = useUnsubscribeFromSite() const userSite = useAccountSites() const characterId = site?.metadata?.proof ? Number(site.metadata.proof) : null + const { t } = useTranslation("common") const handleClickSubscribe = useConnectedAction(() => { if (characterId) { @@ -63,7 +65,7 @@ export const FollowingButton: React.FC<{ ) diff --git a/src/components/common/FollowingCount.tsx b/src/components/common/FollowingCount.tsx index 34501c5c..61e9c8cb 100644 --- a/src/components/common/FollowingCount.tsx +++ b/src/components/common/FollowingCount.tsx @@ -10,6 +10,7 @@ import { useGetSiteSubscriptions, useGetSiteToSubscriptions, } from "~/queries/site" +import { useTranslation } from "next-i18next" export const FollowingCount: React.FC<{ siteId?: string @@ -17,6 +18,7 @@ export const FollowingCount: React.FC<{ }> = ({ siteId, disableList }) => { let [isFollowListOpen, setIsFollowListOpen] = useState(false) let [isToFollowListOpen, setIsToFollowListOpen] = useState(false) + const { t } = useTranslation("common") const subscriptions = useGetSiteSubscriptions({ siteId: siteId || "", @@ -97,7 +99,7 @@ export const FollowingCount: React.FC<{ {subscriptions.data?.total || 0} {" "} - Followers + {t("Followers")} {toSubscriptions.data?.total || 0} {" "} - Followings + {t("Followings")} {!disableList && ( { if (deletePage.isSuccess) { @@ -460,10 +462,17 @@ export const PagesManager: React.FC<{ onClick={pages.fetchNextPage as () => void} isLoading={pages.isFetchingNextPage} > - There are {(pages.data?.pages?.[0].total || 0) - currentLength} more{" "} - {isPost ? "post" : "page"} - {(pages.data?.pages?.[0].total || 0) - currentLength > 1 ? "s" : ""} - , click to load more + {t("load more", { + name: t( + isPost + ? "post" + : "page" + + ((pages.data?.pages?.[0].total || 0) - currentLength > 1 + ? "s" + : ""), + ), + count: (pages.data?.pages?.[0].total || 0) - currentLength, + })} )}
    diff --git a/src/components/main/MainLayout.tsx b/src/components/main/MainLayout.tsx index 2bce014a..ca0a42b0 100644 --- a/src/components/main/MainLayout.tsx +++ b/src/components/main/MainLayout.tsx @@ -11,6 +11,7 @@ import { ConnectButton } from "../common/ConnectButton" import { getSiteLink } from "~/lib/helpers" import Image from "next/image" import { Link } from "react-scroll" +import { useTranslation } from "next-i18next" export function MainLayout({ children, @@ -21,6 +22,8 @@ export function MainLayout({ title?: string tabs?: string[] }) { + const { t } = useTranslation("index") + return ( <> -
    +
    @@ -51,14 +54,14 @@ export function MainLayout({ duration={500} key={tab} > - {tab} + {t(tab)} ))} - Source Code + {t("Source Code")}
    diff --git a/src/components/site/PostMeta.tsx b/src/components/site/PostMeta.tsx index 08dffd4c..a091060f 100644 --- a/src/components/site/PostMeta.tsx +++ b/src/components/site/PostMeta.tsx @@ -1,4 +1,4 @@ -import { formatDate, formatToISO } from "~/lib/date" +import { formatToISO } from "~/lib/date" import { BlockchainIcon } from "~/components/icons/BlockchainIcon" import { UniLink } from "~/components/ui/UniLink" import { Note, Profile } from "~/lib/types" @@ -9,17 +9,14 @@ import { getSiteLink } from "~/lib/helpers" import { Avatar } from "~/components/ui/Avatar" import { EyeIcon, PencilSquareIcon } from "@heroicons/react/24/outline" import { useUserRole } from "~/hooks/useUserRole" +import { useTranslation } from "next-i18next" export const PostMeta: React.FC<{ page: Note site?: Profile | null author?: Profile | null }> = ({ page, site, author }) => { - const [isMounted, setIsMounted] = useState(false) - - useEffect(() => { - setIsMounted(true) - }, []) + const { t } = useTranslation("common") const [showEdit, setShowEdit] = useState(false) const userRole = useUserRole(site?.username) @@ -35,11 +32,16 @@ export const PostMeta: React.FC<{ dateTime={formatToISO(page.date_published)} className="xlog-post-date whitespace-nowrap" > - {formatDate( - page.date_published, - undefined, - isMounted ? undefined : "America/Los_Angeles", - )} + {t("intlDateTime", { + val: new Date(page.date_published), + formatParams: { + val: { + year: "numeric", + month: "short", + day: "numeric", + }, + }, + })} {page.tags?.filter((tag) => tag !== "post" && tag !== "page").length ? ( <> diff --git a/src/components/site/SiteHeader.tsx b/src/components/site/SiteHeader.tsx index bd89f6ef..a4917695 100644 --- a/src/components/site/SiteHeader.tsx +++ b/src/components/site/SiteHeader.tsx @@ -18,10 +18,11 @@ import { FastAverageColor } from "fast-average-color" import { useState, useRef, useEffect, RefObject } from "react" import chroma from "chroma-js" import { Menu } from "~/components/ui/Menu" +import { useTranslation } from "next-i18next" -export type HeaderLinkType = { +type HeaderLinkType = { icon?: React.ReactNode - label: string | JSX.Element + label: string url?: string onClick?: () => void } @@ -30,6 +31,7 @@ const fac = new FastAverageColor() const HeaderLink: React.FC<{ link: HeaderLinkType }> = ({ link }) => { const router = useRouter() + const { t } = useTranslation("site") const active = router.asPath === link.url return ( = ({ link }) => { )} > {link.icon && {link.icon}} - {link.label} + {t(link.label)} ) } diff --git a/src/components/site/SiteHome.tsx b/src/components/site/SiteHome.tsx index 80a5fa3f..1e9c06ae 100644 --- a/src/components/site/SiteHome.tsx +++ b/src/components/site/SiteHome.tsx @@ -1,12 +1,12 @@ import Link from "next/link" -import { formatDate, formatToISO } from "~/lib/date" +import { formatToISO } from "~/lib/date" import { Notes } from "~/lib/types" import { EmptyState } from "../ui/EmptyState" import { useRouter } from "next/router" import { Image } from "~/components/ui/Image" import { Button } from "~/components/ui/Button" -import { useEffect, useState } from "react" import { EyeIcon } from "@heroicons/react/24/outline" +import { useTranslation } from "next-i18next" export const SiteHome: React.FC<{ postPages?: Notes[] @@ -15,12 +15,8 @@ export const SiteHome: React.FC<{ isFetchingNextPage?: boolean }> = ({ postPages, fetchNextPage, hasNextPage, isFetchingNextPage }) => { const router = useRouter() - - const [isMounted, setIsMounted] = useState(false) - - useEffect(() => { - setIsMounted(true) - }, []) + const { t } = useTranslation("common") + const { t: siteT } = useTranslation("site") if (!postPages?.length) return null @@ -49,11 +45,16 @@ export const SiteHome: React.FC<{ dateTime={formatToISO(post.date_published)} className="xlog-post-date whitespace-nowrap" > - {formatDate( - post.date_published, - undefined, - isMounted ? undefined : "America/Los_Angeles", - )} + {t("intlDateTime", { + val: new Date(post.date_published), + formatParams: { + val: { + year: "numeric", + month: "short", + day: "numeric", + }, + }, + })} {!!post.tags?.filter( (tag) => tag !== "post" && tag !== "page", @@ -114,9 +115,12 @@ export const SiteHome: React.FC<{ isLoading={isFetchingNextPage} aria-label="load more" > - There are {postPages[0].total - currentLength} more post - {postPages[0].total - currentLength > 1 ? "s" : ""}, click to load - more + {siteT("load more", { + name: t( + "post" + (postPages[0].total - currentLength > 1 ? "s" : ""), + ), + count: postPages[0].total - currentLength, + })} )} diff --git a/src/components/site/SiteLayout.server.tsx b/src/components/site/SiteLayout.server.tsx index bdc2bcce..012b6904 100644 --- a/src/components/site/SiteLayout.server.tsx +++ b/src/components/site/SiteLayout.server.tsx @@ -8,6 +8,8 @@ import { PageVisibilityEnum } from "~/lib/types" import { dehydrate, QueryClient } from "@tanstack/react-query" import { fetchGetPage } from "~/queries/page.server" import { notFound } from "~/lib/server-side-props" +import { serverSideTranslations } from "next-i18next/serverSideTranslations" +import { languageDetector } from "~/lib/language-detector" export const getServerSideProps = async ( ctx: any, @@ -83,7 +85,11 @@ export const getServerSideProps = async ( return { props: { - dehydratedState: dehydrate(queryClient), + ...(await serverSideTranslations(languageDetector(ctx), [ + "common", + "site", + ])), + dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))), }, } } diff --git a/src/lib/language-detector.ts b/src/lib/language-detector.ts index 90080832..504a8f18 100644 --- a/src/lib/language-detector.ts +++ b/src/lib/language-detector.ts @@ -1,5 +1,11 @@ import type { GetServerSidePropsContext } from "next" +import url from "url" export const languageDetector = (ctx: GetServerSidePropsContext) => { - return ctx.req.headers["accept-language"]?.split(",")[0].split("-")[0] || "en" + const queryLang = url.parse(ctx.req.url!, true).query.lang as string + return ( + queryLang || + ctx.req.headers["accept-language"]?.split(",")[0].split("-")[0] || + "en" + ) } diff --git a/src/pages/_site/[site]/[page].tsx b/src/pages/_site/[site]/[page].tsx index 51e263a2..add1397b 100644 --- a/src/pages/_site/[site]/[page].tsx +++ b/src/pages/_site/[site]/[page].tsx @@ -3,7 +3,7 @@ import { SiteLayout } from "~/components/site/SiteLayout" import { getServerSideProps as getLayoutServerSideProps } from "~/components/site/SiteLayout.server" import { SitePage } from "~/components/site/SitePage" import { serverSidePropsHandler } from "~/lib/server-side-props" -import { dehydrate, QueryClient } from "@tanstack/react-query" +import { QueryClient } from "@tanstack/react-query" import { useGetPage } from "~/queries/page" import { useGetSite } from "~/queries/site" import type { ReactElement } from "react" @@ -14,13 +14,17 @@ export const getServerSideProps: GetServerSideProps = serverSidePropsHandler( const domainOrSubdomain = ctx.params!.site as string const pageSlug = ctx.params!.page as string - await getLayoutServerSideProps(ctx, queryClient, { - useStat: true, - }) + const { props: layoutProps } = await getLayoutServerSideProps( + ctx, + queryClient, + { + useStat: true, + }, + ) return { props: { - dehydratedState: dehydrate(queryClient), + ...layoutProps, domainOrSubdomain, pageSlug, }, diff --git a/src/pages/_site/[site]/archives.tsx b/src/pages/_site/[site]/archives.tsx index 24767cc0..ef3935ad 100644 --- a/src/pages/_site/[site]/archives.tsx +++ b/src/pages/_site/[site]/archives.tsx @@ -4,7 +4,7 @@ import { getServerSideProps as getLayoutServerSideProps } from "~/components/sit import { serverSidePropsHandler } from "~/lib/server-side-props" import { SiteArchives } from "~/components/site/SiteArchives" import { Profile, Notes } from "~/lib/types" -import { dehydrate, QueryClient } from "@tanstack/react-query" +import { QueryClient } from "@tanstack/react-query" import { useGetPagesBySiteLite } from "~/queries/page" import { PageVisibilityEnum } from "~/lib/types" import type { ReactElement } from "react" @@ -13,13 +13,17 @@ export const getServerSideProps: GetServerSideProps = serverSidePropsHandler( async (ctx) => { const queryClient = new QueryClient() const domainOrSubdomain = ctx.params!.site as string - await getLayoutServerSideProps(ctx, queryClient, { - take: 100, - }) + const { props: layoutProps } = await getLayoutServerSideProps( + ctx, + queryClient, + { + take: 100, + }, + ) return { props: { - dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))), + ...layoutProps, domainOrSubdomain, }, } diff --git a/src/pages/_site/[site]/index.tsx b/src/pages/_site/[site]/index.tsx index e9edc777..aa872569 100644 --- a/src/pages/_site/[site]/index.tsx +++ b/src/pages/_site/[site]/index.tsx @@ -2,7 +2,7 @@ import { GetServerSideProps } from "next" import { SiteHome } from "~/components/site/SiteHome" import { SiteLayout } from "~/components/site/SiteLayout" import { getServerSideProps as getLayoutServerSideProps } from "~/components/site/SiteLayout.server" -import { dehydrate, QueryClient } from "@tanstack/react-query" +import { QueryClient } from "@tanstack/react-query" import { useGetPagesBySiteLite } from "~/queries/page" import { PageVisibilityEnum } from "~/lib/types" import type { ReactElement } from "react" @@ -10,13 +10,17 @@ import type { ReactElement } from "react" export const getServerSideProps: GetServerSideProps = async (ctx) => { const queryClient = new QueryClient() const domainOrSubdomain = ctx.params!.site as string - await getLayoutServerSideProps(ctx, queryClient, { - useStat: true, - }) + const { props: layoutProps } = await getLayoutServerSideProps( + ctx, + queryClient, + { + useStat: true, + }, + ) return { props: { - dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))), + ...layoutProps, domainOrSubdomain, }, } diff --git a/src/pages/_site/[site]/nft.tsx b/src/pages/_site/[site]/nft.tsx index 410febbc..015830f6 100644 --- a/src/pages/_site/[site]/nft.tsx +++ b/src/pages/_site/[site]/nft.tsx @@ -1,7 +1,7 @@ import { GetServerSideProps } from "next" import { SiteLayout } from "~/components/site/SiteLayout" import { getServerSideProps as getLayoutServerSideProps } from "~/components/site/SiteLayout.server" -import { dehydrate, QueryClient } from "@tanstack/react-query" +import { QueryClient } from "@tanstack/react-query" import { useGetSite, useGetNFTs } from "~/queries/site" import { ReactElement, useEffect, useState } from "react" import type { Asset } from "unidata.js" @@ -12,13 +12,17 @@ import { UniLink } from "~/components/ui/UniLink" export const getServerSideProps: GetServerSideProps = async (ctx) => { const queryClient = new QueryClient() const domainOrSubdomain = ctx.params!.site as string - await getLayoutServerSideProps(ctx, queryClient, { - skipPages: true, - }) + const { props: layoutProps } = await getLayoutServerSideProps( + ctx, + queryClient, + { + skipPages: true, + }, + ) return { props: { - dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))), + ...layoutProps, domainOrSubdomain, }, } diff --git a/src/pages/_site/[site]/tag/[tag].tsx b/src/pages/_site/[site]/tag/[tag].tsx index ddc89efc..10ca3fe4 100644 --- a/src/pages/_site/[site]/tag/[tag].tsx +++ b/src/pages/_site/[site]/tag/[tag].tsx @@ -4,7 +4,7 @@ import { getServerSideProps as getLayoutServerSideProps } from "~/components/sit import { serverSidePropsHandler } from "~/lib/server-side-props" import { SiteArchives } from "~/components/site/SiteArchives" import { Profile, Notes } from "~/lib/types" -import { dehydrate, QueryClient } from "@tanstack/react-query" +import { QueryClient } from "@tanstack/react-query" import { useGetPagesBySiteLite } from "~/queries/page" import { PageVisibilityEnum } from "~/lib/types" import type { ReactElement } from "react" @@ -15,13 +15,17 @@ export const getServerSideProps: GetServerSideProps = serverSidePropsHandler( const domainOrSubdomain = ctx.params!.site as string const tag = ctx.params!.tag as string - await getLayoutServerSideProps(ctx, queryClient, { - take: 100, - }) + const { props: layoutProps } = await getLayoutServerSideProps( + ctx, + queryClient, + { + take: 100, + }, + ) return { props: { - dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))), + ...layoutProps, domainOrSubdomain, tag, }, diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 4d2350f0..faf10d2b 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -33,7 +33,7 @@ import { XShopLogo, CrossbellChainLogo, } from "@crossbell/ui" -import { useTranslation } from "next-i18next" +import { useTranslation, Trans } from "next-i18next" import { serverSideTranslations } from "next-i18next/serverSideTranslations" import { languageDetector } from "~/lib/language-detector" @@ -43,7 +43,10 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return { props: { - ...(await serverSideTranslations(languageDetector(ctx), ["common"])), + ...(await serverSideTranslations(languageDetector(ctx), [ + "common", + "index", + ])), dehydratedState: dehydrate(queryClient), }, } @@ -53,7 +56,7 @@ export default function Home() { const isConnected = useAccountState((s) => !!s.computed.account) const router = useRouter() const showcaseSites = useGetSites(showcase) - const { t } = useTranslation("common") + const { t } = useTranslation("index") const tryNow = useConnectedAction(() => { router.push("/dashboard") @@ -65,15 +68,8 @@ export default function Home() { src: "/assets/easy.png", }, icon: , - title: t("easy"), - text: ( - <> - Connect with your Web3 Wallet or{" "} - Email. Build your own site with - custom domains, subscriptions, likes, comments, minting as nft, RSS - and more in one second. No fees, no friction. - - ), + title: "Easy", + text: "Connect with your Web3 Wallet or Email. Build your own site with custom domains, subscriptions, likes, comments, minting as nft, RSS and more in one second. No fees, no friction.", }, { screenshot: { @@ -81,14 +77,7 @@ export default function Home() { }, icon: , title: "Safe", - text: ( - <> - All blog data, including configs, posts, subscriptions, comments, - etc., are signed and securely stored on the{" "} - blockchain with your own hands. No - one else, including us, can make any changes. - - ), + text: "All blog data, including configs, posts, subscriptions, comments, etc., are signed and securely stored on the blockchain with your own hands. No one else, including us, can make any changes.", }, { screenshot: { @@ -96,13 +85,7 @@ export default function Home() { }, icon: , title: "Fast", - text: ( - <> - Blockchain doesn't always mean inefficiency. xLog's - efficient caching mechanism and numerous optimisations take it to the - peak of performance. - - ), + text: "Blockchain doesn't always mean inefficiency. xLog's efficient caching mechanism and numerous optimisations take it to the peak of performance.", }, { screenshot: { @@ -110,7 +93,7 @@ export default function Home() { }, icon: , title: "Customizable", - text: "Use your own domain, customise your site and style it however you like. This is your site, there are no restrictions.", + text: "Use your own domain, customise your site and style it however you like. This is your site, there are no restrictions.", }, { screenshot: { @@ -118,14 +101,7 @@ export default function Home() { }, icon: , title: "Open", - text: ( - <> - Uses standard Markdown with export - and import tools and rich APIs for a painless move in and out. All - code is open source on GitHub, all - data is transparent on the chain. - - ), + text: "Uses standard Markdown with export and import tools and rich APIs for a painless move in and out. All code is open source on GitHub, all data is transparent on the chain.", }, ] @@ -244,17 +220,21 @@ export default function Home() { height={200} />
    -

    Blog Free

    +

    + {t("Blog Free")} +

    - {APP_NAME}, the first{" "} - - on-chain - {" "} - and{" "} - - open-source - {" "} - blogging platform for everyone. + + xLog, the first{" "} + + on-chain + {" "} + and{" "} + + open-source + {" "} + blogging platform for everyone. +

    @@ -296,7 +276,9 @@ export default function Home() { width={3785} height={2170} > -

    Visit xlog.{OUR_DOMAIN}

    +

    + {t("Visit")} xlog.{OUR_DOMAIN} +

      {features.map((item, index) => ( @@ -314,22 +296,26 @@ export default function Home() {

    {item.icon} - {item.title} + {t(item.title)}

    - {item.text} + , + }} + ns="index" + />

  • ))} -
    Showcase
    +
    {t("Showcase")}
    -

    - Discover these awesome teams and geeks on xLog (sorted by - update time) -

    +

    {t("discover awesome")}

      setShowcaseMore(true)} > - Show more + {t("Show more")}
    {showcaseSites.data?.map((site: any) => (
  • @@ -399,19 +385,16 @@ export default function Home() { className="inline-block text-accent text-center" href={`${GITHUB_LINK}/edit/dev/showcase.json`} > - Submit yours + {t("Submit yours")}
  • -
    Integration
    +
    {t("Integration")}
    -

    - xLog's open design allows it to integrate with many other - open protocols and applications without friction. -

    +

    {t("Integration description")}

      {integrations.map((item, index) => (
    • - + ) : ( )}