perf: independently loading large size pinyin modules
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
"signed and stored on the blockchain": "此{{name}}已由它的創作者簽名並安全儲存在區塊鏈上。",
|
||||
"Write a comment on the blockchain": "在區塊鏈上留言。",
|
||||
"powered by": "<span>由 </span><name/><span> 提供支援</span>",
|
||||
"This address is in local editing preview mode and cannot be viewed by the public. The expected online address is:": "此地址處於本地編輯預覽模式,尚未公開。預期的上線地址是:",
|
||||
"This address is in local editing preview mode and cannot be viewed by the public.": "此地址處於本地編輯預覽模式,尚未公開。",
|
||||
"View on xChar": "在 xChar 上檢視",
|
||||
"View on xFeed": "在 xFeed 上檢視",
|
||||
"View on Hoot It": "在 Hoot It 上檢視",
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
"signed and stored on the blockchain": "此{{name}}已经由它的创作者签名并安全地存储在区块链上。",
|
||||
"Write a comment on the blockchain": "在区块链上写下你的评论",
|
||||
"powered by": "<span>由 </span><name/><span> 提供支持</span>",
|
||||
"This address is in local editing preview mode and cannot be viewed by the public. The expected online address is:":
|
||||
"此地址处于本地编辑预览模式,无法被公众查看。预期的在线地址是:",
|
||||
"This address is in local editing preview mode and cannot be viewed by the public.":
|
||||
"此地址处于本地编辑预览模式,无法被公众查看。",
|
||||
"View on xChar": "在 xChar 上查看",
|
||||
"View on xFeed": "在 xFeed 上查看",
|
||||
"View on Hoot It": "在 Hoot It 上查看",
|
||||
|
||||
@@ -5,8 +5,6 @@ import { Note, Profile } from "~/lib/types"
|
||||
import Head from "next/head"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { useTranslation } from "next-i18next"
|
||||
import { UniLink } from "../ui/UniLink"
|
||||
import { getDefaultSlug } from "~/lib/helpers"
|
||||
|
||||
export const SitePage: React.FC<{
|
||||
page?: Note | null
|
||||
@@ -50,22 +48,8 @@ export const SitePage: React.FC<{
|
||||
{page?.preview && (
|
||||
<div className="fixed top-0 left-0 w-full text-center text-red-500 bg-gray-100 py-2 opacity-80 text-sm">
|
||||
{t(
|
||||
"This address is in local editing preview mode and cannot be viewed by the public. The expected online address is:",
|
||||
"This address is in local editing preview mode and cannot be viewed by the public.",
|
||||
)}
|
||||
<UniLink
|
||||
href={`${getSiteLink({
|
||||
subdomain: site?.username || "",
|
||||
domain: site?.custom_domain,
|
||||
})}/${page.slug || getDefaultSlug(page.title || "", page.id)}`}
|
||||
className="hover:underline"
|
||||
>
|
||||
{getSiteLink({
|
||||
subdomain: site?.username || "",
|
||||
domain: site?.custom_domain,
|
||||
noProtocol: true,
|
||||
})}
|
||||
/{page.slug || getDefaultSlug(page.title || "", page.id)}
|
||||
</UniLink>
|
||||
</div>
|
||||
)}
|
||||
<article>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import pinyin from "pinyin"
|
||||
|
||||
export const getDefaultSlug = (title: string, id?: string) => {
|
||||
let generated =
|
||||
pinyin(title as string, {
|
||||
style: pinyin.STYLE_NORMAL,
|
||||
compact: true,
|
||||
})?.[0]
|
||||
?.map((word) => word.trim())
|
||||
?.filter((word) => word)
|
||||
?.join("-")
|
||||
?.replace(/\s+/g, "-") ||
|
||||
id?.replace(`local-`, "") ||
|
||||
""
|
||||
generated = generated.replace(/[^a-zA-Z0-9\s-_]/g, "")
|
||||
|
||||
return generated
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import { NoteEntity } from "crossbell.js"
|
||||
|
||||
import { IS_PROD } from "./constants"
|
||||
import { OUR_DOMAIN } from "./env"
|
||||
import pinyin from "pinyin"
|
||||
import { Note } from "unidata.js"
|
||||
|
||||
export const getSiteLink = ({
|
||||
@@ -36,19 +35,3 @@ export const getNoteSlug = (note: NoteEntity) => {
|
||||
export const getNoteSlugFromNote = (page: Note) => {
|
||||
return page.attributes?.find(($) => $.trait_type === "xlog_slug")?.value
|
||||
}
|
||||
export const getDefaultSlug = (title: string, id?: string) => {
|
||||
let generated =
|
||||
pinyin(title as string, {
|
||||
style: pinyin.STYLE_NORMAL,
|
||||
compact: true,
|
||||
})?.[0]
|
||||
?.map((word) => word.trim())
|
||||
?.filter((word) => word)
|
||||
?.join("-")
|
||||
?.replace(/\s+/g, "-") ||
|
||||
id?.replace(`local-`, "") ||
|
||||
""
|
||||
generated = generated.replace(/[^a-zA-Z0-9\s-_]/g, "")
|
||||
|
||||
return generated
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { renderPageContent } from "~/markdown"
|
||||
import { getDefaultSlug, getSiteLink } from "~/lib/helpers"
|
||||
import { getDefaultSlug } from "~/lib/default-slug"
|
||||
|
||||
const makeArray = (value: any) => {
|
||||
if (Array.isArray(value)) {
|
||||
|
||||
@@ -9,7 +9,8 @@ import { getServerSideProps as getLayoutServerSideProps } from "~/components/sit
|
||||
import { serverSidePropsHandler } from "~/lib/server-side-props"
|
||||
import { QueryClient } from "@tanstack/react-query"
|
||||
import { useUserRole } from "~/hooks/useUserRole"
|
||||
import { getDefaultSlug, getSiteLink } from "~/lib/helpers"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { getDefaultSlug } from "~/lib/default-slug"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
|
||||
async (ctx) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { getDefaultSlug } from "~/lib/helpers"
|
||||
import { getDefaultSlug } from "~/lib/default-slug"
|
||||
import { checkDomainServer } from "~/models/site.model"
|
||||
|
||||
export default async function handler(
|
||||
|
||||
@@ -41,7 +41,7 @@ import { useTranslation } from "next-i18next"
|
||||
import { getServerSideProps as getLayoutServerSideProps } from "~/components/dashboard/DashboardLayout.server"
|
||||
import { GetServerSideProps } from "next"
|
||||
import { serverSidePropsHandler } from "~/lib/server-side-props"
|
||||
import { getDefaultSlug } from "~/lib/helpers"
|
||||
import { getDefaultSlug } from "~/lib/default-slug"
|
||||
import { useMobileLayout } from "~/hooks/useMobileLayout"
|
||||
import { OptionsButton } from "~/components/dashboard/OptionsButton"
|
||||
|
||||
|
||||
+2
-2
@@ -15,12 +15,10 @@ import {
|
||||
} from "@crossbell/connect-kit"
|
||||
import { useRefCallback } from "@crossbell/util-hooks"
|
||||
import { useContract } from "@crossbell/contract"
|
||||
import { NoteEntity } from "crossbell.js"
|
||||
|
||||
import * as pageModel from "~/models/page.model"
|
||||
|
||||
import { useUnidata } from "./unidata"
|
||||
import { getDefaultSlug } from "~/lib/helpers"
|
||||
|
||||
export const useGetPagesBySiteLite = (
|
||||
input: Parameters<typeof pageModel.getPagesBySite>[0],
|
||||
@@ -296,6 +294,8 @@ export function useGetSummary(input: { cid?: string; lang?: string }) {
|
||||
|
||||
export function useGetMirrorXyz(input: { address: string }) {
|
||||
return useQuery(["getMirror", input.address], async () => {
|
||||
const { getDefaultSlug } = await import("~/lib/default-slug")
|
||||
|
||||
if (!input.address) {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user