refactor: remove SEOHead

This commit is contained in:
DIYgod
2023-05-08 00:53:32 +01:00
parent c0d4bb7098
commit be59a3f78a
5 changed files with 3 additions and 775 deletions
+3 -3
View File
@@ -12,14 +12,13 @@ import {
import { ConnectButton } from "~/components/common/ConnectButton"
import { Logo } from "~/components/common/Logo"
import { SEOHead } from "~/components/common/SEOHead"
import { DashboardSidebar } from "~/components/dashboard/DashboardSidebar"
import { DashboardTopbar } from "~/components/dashboard/DashboardTopbar"
import { Avatar } from "~/components/ui/Avatar"
import { UniLink } from "~/components/ui/UniLink"
import { useIsMobileLayout } from "~/hooks/useMobileLayout"
import { useUserRole } from "~/hooks/useUserRole"
import { APP_NAME, DISCORD_LINK } from "~/lib/env"
import { DISCORD_LINK } from "~/lib/env"
import { getSiteLink } from "~/lib/helpers"
import { toGateway } from "~/lib/ipfs-parser"
import { getStorage } from "~/lib/storage"
@@ -169,7 +168,8 @@ export default function DashboardLayout({
return ready ? (
hasPermission ? (
<>
<SEOHead title={t(title) || ""} siteName={APP_NAME} />
{/* TODO */}
{/* <SEOHead title={t(title) || ""} siteName={APP_NAME} /> */}
{site?.data?.metadata?.content?.css && (
<link
type="text/css"
-127
View File
@@ -1,127 +0,0 @@
import Head from "next/head"
import { SITE_URL } from "~/lib/env"
export const SEOHead: React.FC<{
siteName: string
title: string | undefined
description?: string | null
image?: string | null
icon?: string | null
site?: string
}> = ({ siteName, title, description, image, icon, site }) => {
return (
<Head>
<title>{title ? `${title} - ${siteName}` : `${siteName}`}</title>
<meta name="og:site_name" content={siteName} />
<meta name="og:title" content={title} />
<meta name="twitter:title" content={title} />
<meta name="description" content={description || ""} />
<meta name="og:description" content={description || ""} />
<meta name="twitter:description" content={description || ""} />
<meta name="twitter:card" content="summary_large_image" />
{image && (
<>
<meta name="og:image" content={new URL(image, SITE_URL).toString()} />
<meta
name="twitter:image"
content={new URL(image, SITE_URL).toString()}
/>
</>
)}
<link rel="icon" href={icon || `${SITE_URL}/assets/logo.svg`}></link>
{site ? (
<>
<link
rel="alternate"
href="/feed"
title={siteName}
type="application/feed+json"
></link>
<link
rel="alternate"
href="/feed?format=xml"
title={siteName}
type="application/rss+xml"
></link>
<link
rel="alternate"
href="/feed/comments"
title={`Comments on ${siteName}`}
type="application/feed+json"
></link>
<link
rel="alternate"
href="/feed/comments?format=xml"
title={`Comments on ${siteName}`}
type="application/rss+xml"
></link>
<link rel="manifest" href="/manifest.json" />
</>
) : (
<>
<link
rel="alternate"
href="/feed/latest"
title="xLog Latest"
type="application/feed+json"
></link>
<link
rel="alternate"
href="/feed/latest?format=xml"
title="xLog Latest"
type="application/rss+xml"
></link>
<link
rel="alternate"
href="/feed/hottest/0"
title="xLog Hot"
type="application/feed+json"
></link>
<link
rel="alternate"
href="/feed/hottest/0?format=xml"
title="xLog Hot"
type="application/rss+xml"
></link>
<link
rel="alternate"
href="/feed/hottest/1"
title="xLog Daily Hot"
type="application/feed+json"
></link>
<link
rel="alternate"
href="/feed/hottest/1?format=xml"
title="xLog Daily Hot"
type="application/rss+xml"
></link>
<link
rel="alternate"
href="/feed/hottest/7"
title="xLog Weekly Hot"
type="application/feed+json"
></link>
<link
rel="alternate"
href="/feed/hottest/7?format=xml"
title="xLog Weekly Hot"
type="application/rss+xml"
></link>
<link
rel="alternate"
href="/feed/hottest/30"
title="xLog Monthly Hot"
type="application/feed+json"
></link>
<link
rel="alternate"
href="/feed/hottest/30?format=xml"
title="xLog Monthly Hot"
type="application/rss+xml"
></link>
</>
)}
</Head>
)
}
@@ -1,388 +0,0 @@
import { useParams } from "next/navigation"
import React, { useEffect } from "react"
import { useTranslation } from "react-i18next"
import { useAccountState, useConnectModal } from "@crossbell/connect-kit"
import {
useNotifications,
useShowNotificationModal,
} from "@crossbell/notification"
import { ConnectButton } from "~/components/common/ConnectButton"
import { Logo } from "~/components/common/Logo"
import { Avatar } from "~/components/ui/Avatar"
import { useIsMobileLayout } from "~/hooks/useMobileLayout"
import { useUserRole } from "~/hooks/useUserRole"
import { APP_NAME, DISCORD_LINK } from "~/lib/env"
import { getSiteLink } from "~/lib/helpers"
import { toGateway } from "~/lib/ipfs-parser"
import { getStorage } from "~/lib/storage"
import { cn } from "~/lib/utils"
import { useGetPagesBySite } from "~/queries/page"
import { useGetSite } from "~/queries/site"
import { SEOHead } from "../common/SEOHead"
import { UniLink } from "../ui/UniLink"
import { DashboardSidebar } from "./DashboardSidebar"
import { DashboardTopbar } from "./DashboardTopbar"
export function DashboardLayout({
children,
title,
}: {
children: React.ReactNode
title: string
}) {
const params = useParams()
const subdomain = params?.subdomain as string
const site = useGetSite(subdomain)
const userRole = useUserRole(subdomain)
const [ssrReady, account] = useAccountState(({ ssrReady, computed }) => [
ssrReady,
computed.account,
])
const connectModal = useConnectModal()
const [ready, setReady] = React.useState(false)
const [hasPermission, setHasPermission] = React.useState(false)
const { t } = useTranslation("dashboard")
const isMobileLayout = useIsMobileLayout()
useEffect(() => {
if (ssrReady) {
if (!account) {
setReady(false)
setHasPermission(false)
connectModal.show()
} else if (userRole.isSuccess) {
setReady(true)
if (userRole.data) {
setHasPermission(true)
} else {
setHasPermission(false)
}
}
}
}, [ssrReady, userRole.isSuccess, userRole.data, account, connectModal])
const showNotificationModal = useShowNotificationModal()
const { isAllRead } = useNotifications()
const pages = useGetPagesBySite({
type: "post",
characterId: 50153,
limit: 1,
})
const [isEventsAllRead, setIsEventsAllRead] = React.useState(true)
const latestEventRead = getStorage("latestEventRead")?.value || 0
useEffect(() => {
if (pages.isSuccess) {
if (
new Date(pages.data.pages[0].list?.[0].createdAt) >
new Date(latestEventRead)
) {
setIsEventsAllRead(false)
} else {
setIsEventsAllRead(true)
}
}
}, [pages.isSuccess, pages.data?.pages, latestEventRead])
const links: {
href?: string
onClick?: () => void
isActive: (ctx: { href: string; pathname: string }) => boolean
icon: React.ReactNode
text: string
}[] = [
{
href: `/dashboard/${subdomain}`,
isActive: ({ href, pathname }) => href === pathname,
icon: "icon-[mingcute--grid-line]",
text: "Dashboard",
},
{
href: `/dashboard/${subdomain}/posts`,
isActive: ({ href, pathname }) => href === pathname,
icon: "icon-[mingcute--news-line]",
text: "Posts",
},
{
href: `/dashboard/${subdomain}/pages`,
isActive: ({ href, pathname }) => href === pathname,
icon: "icon-[mingcute--file-line]",
text: "Pages",
},
{
href: `/dashboard/${subdomain}/comments`,
isActive: ({ href, pathname }) => href === pathname,
icon: "icon-[mingcute--comment-line]",
text: "Comments",
},
{
onClick: showNotificationModal,
isActive: ({ href, pathname }) => href === pathname,
icon: isAllRead
? "icon-[mingcute--notification-line]"
: "icon-[mingcute--notification-fill]",
text: isAllRead ? "Notifications" : "Unread notifications",
},
{
href: `/dashboard/${subdomain}/import`,
isActive: ({ pathname }) =>
pathname.startsWith(`/dashboard/${subdomain}/import`),
icon: "icon-[mingcute--file-import-line]",
text: "Import",
},
{
href: `/dashboard/${subdomain}/events`,
isActive: ({ href, pathname }) => href === pathname,
icon: isEventsAllRead
? "icon-[mingcute--flag-4-line]"
: "icon-[mingcute--flag-4-fill]",
text: isEventsAllRead ? "Events" : "New Events",
},
{
href: `/dashboard/${subdomain}/achievements`,
isActive: ({ href, pathname }) => href === pathname,
icon: "icon-[mingcute--trophy-line]",
text: "Achievements",
},
{
href: `/dashboard/${subdomain}/tokens`,
isActive: ({ href, pathname }) => href === pathname,
icon: "icon-[mingcute--pig-money-line]",
text: "Tokens",
},
{
href: `/dashboard/${subdomain}/settings/general`,
isActive: ({ pathname }) =>
pathname.startsWith(`/dashboard/${subdomain}/settings`),
icon: "icon-[mingcute--settings-3-line]",
text: "Settings",
},
]
return ready ? (
hasPermission ? (
<>
<SEOHead title={t(title) || ""} siteName={APP_NAME} />
{site?.data?.metadata?.content?.css && (
<link
type="text/css"
rel="stylesheet"
href={
"data:text/css;base64," +
Buffer.from(toGateway(site.data.metadata?.content?.css)).toString(
"base64",
)
}
/>
)}
<div className="flex h-screen">
{isMobileLayout ? (
<DashboardTopbar
userWidget={
<div className="mb-2 px-2 pt-3 pb-2">
<ConnectButton
left={true}
size="base"
hideNotification={true}
hideName={false}
/>
</div>
}
drawerWidget={(close: any) => (
<>
<div className="flex-1 min-h-0 flex flex-col h-full">
<div className="mb-2 px-5 pt-3 pb-2 text-2xl font-extrabold flex items-center">
<div className="inline-block w-9 h-9 mr-3">
<Logo
type="lottie"
width={36}
height={36}
autoplay={false}
/>
</div>
{"xLog"}
</div>
<div className="px-3 space-y-[2px] text-zinc-500 flex-1 min-h-0 overflow-y-auto">
{links.map((link) => {
const active =
link.href &&
link.isActive({
pathname: router.asPath,
href: link.href,
})
return (
<div key={link.text} onClick={() => close()}>
<UniLink
href={link.href}
className={cn(
`flex px-4 h-12 items-center rounded-md space-x-2 w-full transition-colors`,
active
? `bg-slate-200 font-medium text-accent`
: `hover:bg-slate-200 hover:bg-opacity-50`,
!true && "justify-center",
)}
onClick={link.onClick}
>
<span className={cn(link.icon, "text-xl")}></span>
<span>{t(link.text)}</span>
</UniLink>
</div>
)
})}
</div>
<div className="flex items-center px-4 flex-col pb-4">
<UniLink
href={DISCORD_LINK}
className="space-x-1 text-zinc-500 hover:text-zinc-800 flex w-full h-12 items-center justify-center transition-colors mb-2"
>
<i className="icon-[mingcute--question-line] text-lg" />
{<span>{t("Need help?")}</span>}
</UniLink>
<UniLink
href={getSiteLink({
subdomain,
})}
className="space-x-2 border rounded-lg bg-slate-100 border-slate-200 text-accent hover:scale-105 transition-transform flex w-full h-12 items-center justify-center"
>
<span className="icon-[mingcute--home-1-line]"></span>
{<span>{t("View Site")}</span>}
</UniLink>
</div>
</div>
</>
)}
>
{(isOpen) => <div>233</div>}
</DashboardTopbar>
) : (
<DashboardSidebar>
{(isOpen) => (
<>
<div className="flex-1 min-h-0 flex flex-col">
<div className="mb-2 px-5 pt-3 pb-2 text-2xl font-extrabold flex items-center">
<div className="inline-block w-9 h-9 mr-3">
<Logo
type="lottie"
width={36}
height={36}
autoplay={false}
/>
</div>
{isOpen && "xLog"}
</div>
{account?.character?.handle &&
subdomain &&
account?.character?.handle !== subdomain && (
<div className="mb-2 px-5 pt-3 pb-2 bg-orange-50 text-center">
<div className="mb-2">
{isOpen && "You are operating"}
</div>
<Avatar
images={site.data?.metadata?.content?.avatars || []}
size={isOpen ? 60 : 40}
name={site.data?.metadata?.content?.name}
/>
{isOpen && (
<span className="flex flex-col justify-center">
<span className="block">
{site.data?.metadata?.content?.name}
</span>
<span className="block text-sm text-zinc-400">
@{site.data?.handle}
</span>
</span>
)}
</div>
)}
<div className="mb-2 px-2 pt-3 pb-2">
<ConnectButton
left={true}
size="base"
hideNotification={true}
hideName={!isOpen}
/>
</div>
<div className="px-3 space-y-[2px] text-zinc-500 flex-1 min-h-0 overflow-y-auto">
{links.map((link) => {
const active =
link.href &&
link.isActive({
pathname: router.asPath,
href: link.href,
})
return (
<UniLink
href={link.href}
key={link.text}
className={cn(
`flex px-4 h-12 items-center rounded-md space-x-2 w-full transition-colors`,
active
? `bg-slate-200 font-medium text-accent`
: `hover:bg-slate-200 hover:bg-opacity-50`,
!isOpen && "justify-center",
)}
onClick={link.onClick}
>
<span className={cn(link.icon, "text-xl")}></span>
{isOpen && <span>{t(link.text)}</span>}
</UniLink>
)
})}
</div>
</div>
<div className="flex items-center px-4 flex-col pb-4">
<UniLink
href={DISCORD_LINK}
className="space-x-1 text-zinc-500 hover:text-zinc-800 flex w-full h-12 items-center justify-center transition-colors mb-2"
>
<i className="icon-[mingcute--question-line] text-lg" />
{isOpen && <span>{t("Need help?")}</span>}
</UniLink>
<UniLink
href={getSiteLink({
subdomain,
})}
className="space-x-2 border rounded-lg bg-slate-100 border-slate-200 text-accent hover:scale-105 transition-transform flex w-full h-12 items-center justify-center"
>
<span className="icon-[mingcute--home-1-line]"></span>
{isOpen && <span>{t("View Site")}</span>}
</UniLink>
</div>
</>
)}
</DashboardSidebar>
)}
<div
className={`${isMobileLayout ? "pt-16 flex-1" : "flex-1 min-w-0"}`}
>
{children}
</div>
</div>
</>
) : (
<div className="w-screen h-screen flex items-center justify-center flex-col">
<ConnectButton size="base" />
<div className="mt-8">
Sorry, you do not have permission to access the current page.
</div>
<div className="mt-4">
Please switch account or request the owner to set you as the operator.
</div>
<UniLink href="/dashboard" className="mt-4 text-accent">
Take me to my own dashboard
</UniLink>
</div>
)
) : (
<div className="w-screen h-screen flex justify-center items-center">
Loading...
</div>
)
}
-127
View File
@@ -1,127 +0,0 @@
import { useRouter } from "next/navigation"
import { Logo } from "~/components/common/Logo"
import {
APP_DESCRIPTION,
APP_NAME,
DISCORD_LINK,
GITHUB_LINK,
TWITTER_LINK,
} from "~/lib/env"
import { getSiteLink } from "~/lib/helpers"
import { useTranslation } from "~/lib/i18n/client"
import { cn } from "~/lib/utils"
import { ConnectButton } from "../common/ConnectButton"
import { DarkModeSwitch } from "../common/DarkModeSwitch"
import { SEOHead } from "../common/SEOHead"
import { Image } from "../ui/Image"
import { UniLink } from "../ui/UniLink"
const tabs = [
{
name: "Home",
link: "/",
},
{
name: "Activities",
link: "/activities",
},
{
name: (
<Image
className="no-optimization w-24"
alt="github stars"
src="https://img.shields.io/github/stars/Crossbell-Box/xLog?color=white&label=Stars&logo=github&style=social"
/>
),
link: GITHUB_LINK,
},
]
export function MainLayout({
children,
title,
}: {
children?: React.ReactNode
title?: string
}) {
const { t } = useTranslation("index")
const router = useRouter()
return (
<>
<SEOHead
title={title}
siteName={APP_NAME}
description={APP_DESCRIPTION}
/>
<header className="py-5 fixed w-full top-0 bg-white z-10">
<div className="max-w-screen-lg px-5 mx-auto flex justify-between items-center">
<UniLink
href="/"
className="text-2xl font-extrabold flex items-center"
>
<div className="inline-block w-9 h-9 mr-3">
<Logo type="lottie" width={36} height={36} autoplay={false} />
</div>
xLog
</UniLink>
<div className="space-x-14 text-zinc-500 flex">
{tabs?.map((tab, index) => (
<UniLink
className={cn(
"cursor-pointer items-center hidden sm:flex hover:text-accent text-lg",
{
"text-accent": router.pathname === tab.link,
},
)}
key={tab.link}
href={tab.link}
>
{typeof tab.name === "string" ? t(tab.name) : tab.name}
</UniLink>
))}
<ConnectButton size="base" variantColor="black" />
</div>
</div>
</header>
{children}
<footer className="mt-10 font-medium border-t">
<div className="max-w-screen-lg px-5 py-14 mx-auto flex justify-between">
<span className="text-zinc-700 ml-2 inline-flex items-center space-x-5 align-middle">
{GITHUB_LINK && (
<UniLink className="flex items-center" href={GITHUB_LINK}>
<span className="inline-block icon-[mingcute--github-fill] text-2xl hover:text-accent"></span>
</UniLink>
)}
{DISCORD_LINK && (
<UniLink className="flex items-center" href={DISCORD_LINK}>
<span className="inline-block icon-[mingcute--discord-fill] text-2xl hover:text-accent"></span>
</UniLink>
)}
{TWITTER_LINK && (
<UniLink className="flex items-center" href={TWITTER_LINK}>
<span className="inline-block icon-[mingcute--twitter-fill] text-2xl hover:text-accent"></span>
</UniLink>
)}
</span>
<span className="inline-flex items-center space-x-4">
<DarkModeSwitch />
<span>
&copy;{" "}
<UniLink
href={getSiteLink({
subdomain: "xlog",
})}
className="hover:text-accent"
>
{APP_NAME}
</UniLink>
</span>
</span>
</div>
</footer>
</>
)
}
-130
View File
@@ -1,130 +0,0 @@
import { useRouter } from "next/navigation"
import React, { useEffect } from "react"
import { useAccountState } from "@crossbell/connect-kit"
import { BlockchainInfo } from "~/components/common/BlockchainInfo"
import { Style } from "~/components/common/Style"
import { useUserRole } from "~/hooks/useUserRole"
import { IS_PROD, IS_VERCEL_PREVIEW } from "~/lib/constants"
import { OUR_DOMAIN, SITE_URL } from "~/lib/env"
import { getUserContentsUrl } from "~/lib/user-contents"
import { cn } from "~/lib/utils"
import { useCheckLike, useCheckMint, useGetPage } from "~/queries/page"
import { useGetSite, useGetSubscription } from "~/queries/site"
import { SEOHead } from "../common/SEOHead"
import { FABContainer } from "../ui/FAB"
import { BackToTopFAB } from "./BackToTopFAB"
import { SiteFooter } from "./SiteFooter"
import { SiteHeader } from "./SiteHeader"
export type SiteLayoutProps = {
children: React.ReactNode
title?: string | null
siteId?: string
useStat?: boolean
type: "index" | "post" | "tag" | "nft" | "404" | "archive"
}
export const SiteLayout: React.FC<SiteLayoutProps> = ({
children,
title,
siteId,
useStat,
type,
}) => {
const router = useRouter()
const domainOrSubdomain = (router.query.site || siteId) as string
const pageSlug = router.query.page as string
const tag = router.query.tag as string
const site = useGetSite(domainOrSubdomain)
const page = useGetPage({
characterId: site.data?.characterId,
slug: pageSlug,
...(useStat && {
useStat: true,
}),
})
const isConnected = useAccountState((s) => !!s.computed.account)
const userRole = useUserRole(domainOrSubdomain)
const subscription = useGetSubscription(site.data?.characterId)
const [{ isLiked }] = useCheckLike({
characterId: page.data?.characterId,
noteId: page.data?.noteId,
})
const isMint = useCheckMint({
characterId: page.data?.characterId,
noteId: page.data?.noteId,
})
useEffect(() => {
if (site.data) {
if (
window.location.host.split(".").slice(-2).join(".") !== OUR_DOMAIN &&
window.location.host !== site.data?.metadata?.content?.custom_domain &&
IS_PROD &&
!IS_VERCEL_PREVIEW
) {
window.location.href = SITE_URL
}
}
}, [site.isSuccess, site.data])
return (
<div
className={cn(
{
"xlog-user": true,
"xlog-user-login": isConnected,
"xlog-user-site-owner": userRole?.data === "owner",
"xlog-user-site-operator": userRole?.data === "operator",
"xlog-user-site-follower": subscription?.data,
"xlog-user-post-liker": isLiked,
"xlog-user-post-minter": isMint?.data?.count,
},
`xlog-page-${type}`,
)}
>
<SEOHead
title={title || tag || page.data?.metadata?.content?.title || ""}
siteName={site.data?.metadata?.content?.name || ""}
description={
page.data?.metadata?.content?.summary ??
site.data?.metadata?.content?.bio?.replace(/<[^>]*>/g, "")
}
image={
page.data?.metadata?.content?.cover ||
getUserContentsUrl(site.data?.metadata?.content?.avatars?.[0])
}
icon={getUserContentsUrl(site.data?.metadata?.content?.avatars?.[0])}
site={domainOrSubdomain}
/>
<Style content={site.data?.metadata?.content?.css} />
{site.data && <SiteHeader site={site.data} />}
<div
className={cn(
`xlog-post-id-${page.data?.characterId}-${page.data?.noteId} max-w-screen-md mx-auto px-5 pt-12 relative`,
page.data?.metadata?.content?.tags?.map(
(tag) => `xlog-post-tag-${tag}`,
),
)}
>
{children}
</div>
{site.data && (
<div className="max-w-screen-md mx-auto pt-12 pb-10">
<BlockchainInfo site={site.data} page={page.data || undefined} />
</div>
)}
<SiteFooter site={site.data || undefined} />
<FABContainer>
<BackToTopFAB />
</FABContainer>
</div>
)
}