diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index c8f4c365..16899423 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -33,6 +33,7 @@ export const getNoteSlug = (note: NoteEntity) => { } export const getDefaultSlug = (title: string, id?: string) => { + title = title.replace(/[^a-zA-Z0-9\s]/g, "") return ( pinyin(title as string, { style: pinyin.STYLE_NORMAL, diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index 52d5b69f..9bd31ede 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -28,7 +28,6 @@ import { setStorage, delStorage } from "~/lib/storage" import { nanoid } from "nanoid" import { useQueryClient } from "@tanstack/react-query" import { PageContent } from "~/components/common/PageContent" -import pinyin from "pinyin" import type { Root } from "hast" import type { EditorView } from "@codemirror/view" import { Editor } from "~/components/ui/Editor" @@ -549,7 +548,9 @@ export default function SubdomainEditor() { href={`${getSiteLink({ subdomain, domain: site.data?.custom_domain, - })}/${values.slug || defaultSlug}`} + })}/${encodeURIComponent( + values.slug || defaultSlug, + )}`} className="hover:underline" > {getSiteLink({ @@ -557,7 +558,7 @@ export default function SubdomainEditor() { domain: site.data?.custom_domain, noProtocol: true, })} - /{values.slug || defaultSlug} + /{encodeURIComponent(values.slug || defaultSlug)} )} @@ -616,7 +617,7 @@ export default function SubdomainEditor() { href={`${getSiteLink({ subdomain, domain: site.data?.custom_domain, - })}/${values.slug || defaultSlug}`} + })}/${encodeURIComponent(values.slug || defaultSlug)}`} > {t("View the post")} @@ -641,9 +642,9 @@ export default function SubdomainEditor() { href={`https://twitter.com/intent/tweet?url=${getSiteLink({ subdomain, domain: site.data?.custom_domain, - })}/${ - values.slug || defaultSlug - }&via=_xLog&text=${encodeURIComponent( + })}/${encodeURIComponent( + values.slug || defaultSlug, + )}&via=_xLog&text=${encodeURIComponent( `Read my new post - ${page.data?.title}`, )}`} >