diff --git a/public/locales/zh/dashboard.json b/public/locales/zh/dashboard.json index dee23cb6..904824d9 100644 --- a/public/locales/zh/dashboard.json +++ b/public/locales/zh/dashboard.json @@ -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}}》,快来看看吧!" } \ No newline at end of file diff --git a/src/components/dashboard/PagesManagerMenu.tsx b/src/components/dashboard/PagesManagerMenu.tsx index d982f479..067428f6 100644 --- a/src/components/dashboard/PagesManagerMenu.tsx +++ b/src/components/dashboard/PagesManagerMenu.tsx @@ -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: , 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) + } }, }, { diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index 00892d77..44fe043a 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -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, + }, + ), + )}` +} diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index 78b675a7..b9ada64e 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -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() {
  • {t("Share to Twitter")}