diff --git a/public/locales/zh-TW/site.json b/public/locales/zh-TW/site.json index 8a38a7e0..83727df8 100644 --- a/public/locales/zh-TW/site.json +++ b/public/locales/zh-TW/site.json @@ -7,7 +7,7 @@ "signed and stored on the blockchain": "此{{name}}已由它的創作者簽名並安全儲存在區塊鏈上。", "Write a comment on the blockchain": "在區塊鏈上留言。", "powered by": "由 提供支援", - "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 上檢視", diff --git a/public/locales/zh/site.json b/public/locales/zh/site.json index 76841b73..b90215e8 100644 --- a/public/locales/zh/site.json +++ b/public/locales/zh/site.json @@ -7,8 +7,8 @@ "signed and stored on the blockchain": "此{{name}}已经由它的创作者签名并安全地存储在区块链上。", "Write a comment on the blockchain": "在区块链上写下你的评论", "powered by": "由 提供支持", - "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 上查看", diff --git a/src/components/site/SitePage.tsx b/src/components/site/SitePage.tsx index 02d8ba45..a76d9dc9 100644 --- a/src/components/site/SitePage.tsx +++ b/src/components/site/SitePage.tsx @@ -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 && (
{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.", )} - - {getSiteLink({ - subdomain: site?.username || "", - domain: site?.custom_domain, - noProtocol: true, - })} - /{page.slug || getDefaultSlug(page.title || "", page.id)} -
)}
diff --git a/src/lib/default-slug.ts b/src/lib/default-slug.ts new file mode 100644 index 00000000..633621f5 --- /dev/null +++ b/src/lib/default-slug.ts @@ -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 +} diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index 3fa64703..b85ac1c3 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -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 -} diff --git a/src/lib/read-files.ts b/src/lib/read-files.ts index d062946f..39e2fcb7 100644 --- a/src/lib/read-files.ts +++ b/src/lib/read-files.ts @@ -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)) { diff --git a/src/pages/_site/[site]/preview/[page].tsx b/src/pages/_site/[site]/preview/[page].tsx index 9b2067eb..e0762468 100644 --- a/src/pages/_site/[site]/preview/[page].tsx +++ b/src/pages/_site/[site]/preview/[page].tsx @@ -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) => { diff --git a/src/pages/api/redirection.tsx b/src/pages/api/redirection.tsx index 6146aae6..fe761211 100644 --- a/src/pages/api/redirection.tsx +++ b/src/pages/api/redirection.tsx @@ -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( diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index 59905b7b..a71e23b3 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -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" diff --git a/src/queries/page.ts b/src/queries/page.ts index b8230619..290b0fa5 100644 --- a/src/queries/page.ts +++ b/src/queries/page.ts @@ -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[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 }