feat: optimize Twitter sharing copy
This commit is contained in:
parent
ea939d1719
commit
d2aeec95c9
|
|
@ -187,5 +187,6 @@
|
|||
"delete_confirmation_post": "你确定要删除这篇文章吗?",
|
||||
"delete_confirmation_page": "你确定要删除这个页面吗?",
|
||||
"Confirm": "确认",
|
||||
"Cancel": "取消"
|
||||
"Cancel": "取消",
|
||||
"Published a new post on my blockchain blog: {{title}}. Check it out now!": "在我的区块链博客发布了一篇新文章《{{title}}》,快来看看吧!"
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import { useQueryClient } from "@tanstack/react-query"
|
|||
|
||||
import { useGetState } from "~/hooks/useGetState"
|
||||
import { APP_NAME } from "~/lib/env"
|
||||
import { getNoteSlugFromNote, getSiteLink } from "~/lib/helpers"
|
||||
import { getNoteSlugFromNote, getTwitterShareUrl } from "~/lib/helpers"
|
||||
import { delStorage, getStorage, setStorage } from "~/lib/storage"
|
||||
import { useCreateOrUpdatePage, useDeletePage } from "~/queries/page"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
|
|
@ -153,17 +153,14 @@ export const PagesManagerMenu: FC<{
|
|||
text: "Share to Twitter",
|
||||
icon: <span className="i-mingcute:twitter-line inline-block"></span>,
|
||||
onClick() {
|
||||
const slug = getNoteSlugFromNote(page)
|
||||
if (!slug) return
|
||||
|
||||
window.open(
|
||||
`https://twitter.com/intent/tweet?url=${getSiteLink({
|
||||
subdomain,
|
||||
domain: site.data?.custom_domain,
|
||||
})}/${encodeURIComponent(slug)}&via=_xLog&text=${encodeURIComponent(
|
||||
`Read my new post - ${page.title}`,
|
||||
)}`,
|
||||
)
|
||||
if (site.data) {
|
||||
const twitterShareUrl = getTwitterShareUrl({
|
||||
page,
|
||||
site: site.data,
|
||||
t,
|
||||
})
|
||||
window.open(twitterShareUrl)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { NoteEntity } from "crossbell.js"
|
||||
import { Note } from "unidata.js"
|
||||
|
||||
import { Note, Profile } from "~/lib/types"
|
||||
|
||||
import { IS_PROD } from "./constants"
|
||||
import { OUR_DOMAIN } from "./env"
|
||||
|
|
@ -35,3 +36,31 @@ export const getNoteSlug = (note: NoteEntity) => {
|
|||
export const getNoteSlugFromNote = (page: Note) => {
|
||||
return page.attributes?.find(($) => $.trait_type === "xlog_slug")?.value
|
||||
}
|
||||
|
||||
export const getTwitterShareUrl = ({
|
||||
page,
|
||||
site,
|
||||
t,
|
||||
}: {
|
||||
page: Note
|
||||
site: Profile
|
||||
t: (key: string, options?: any) => string
|
||||
}) => {
|
||||
const slug = getNoteSlugFromNote(page)
|
||||
|
||||
if (!slug) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return `https://twitter.com/intent/tweet?url=${getSiteLink({
|
||||
subdomain: site.username!,
|
||||
domain: site.custom_domain,
|
||||
})}/${encodeURIComponent(slug)}&via=_xLog&text=${encodeURIComponent(
|
||||
t(
|
||||
`Published a new post on my blockchain blog: {{title}}. Check it out now!`,
|
||||
{
|
||||
title: page.title,
|
||||
},
|
||||
),
|
||||
)}`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import { useUploadFile } from "~/hooks/useUploadFile"
|
|||
import { showConfetti } from "~/lib/confetti"
|
||||
import { getDefaultSlug } from "~/lib/default-slug"
|
||||
import { CSB_SCAN } from "~/lib/env"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { getSiteLink, getTwitterShareUrl } from "~/lib/helpers"
|
||||
import { getPageVisibility } from "~/lib/page-helpers"
|
||||
import { serverSidePropsHandler } from "~/lib/server-side-props"
|
||||
import { delStorage, setStorage } from "~/lib/storage"
|
||||
|
|
@ -788,14 +788,15 @@ export default function SubdomainEditor() {
|
|||
<li>
|
||||
<UniLink
|
||||
className="text-accent"
|
||||
href={`https://twitter.com/intent/tweet?url=${getSiteLink({
|
||||
subdomain,
|
||||
domain: site.data?.custom_domain,
|
||||
})}/${encodeURIComponent(
|
||||
values.slug || defaultSlug,
|
||||
)}&via=_xLog&text=${encodeURIComponent(
|
||||
`Read my new post - ${page.data?.title}`,
|
||||
)}`}
|
||||
href={
|
||||
page.data && site.data
|
||||
? getTwitterShareUrl({
|
||||
page: page.data,
|
||||
site: site.data,
|
||||
t,
|
||||
})
|
||||
: ""
|
||||
}
|
||||
>
|
||||
{t("Share to Twitter")}
|
||||
</UniLink>
|
||||
|
|
|
|||
Loading…
Reference in New Issue