feat: tag build-in page
This commit is contained in:
@@ -6,7 +6,8 @@ import { Notes, Note } from "~/lib/types"
|
||||
|
||||
export const SiteArchives: React.FC<{
|
||||
posts?: Notes
|
||||
}> = ({ posts }) => {
|
||||
title?: string
|
||||
}> = ({ posts, title }) => {
|
||||
const groupedByYear = useMemo<Map<string, Note[]>>(() => {
|
||||
const map = new Map()
|
||||
|
||||
@@ -26,7 +27,7 @@ export const SiteArchives: React.FC<{
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2 className="text-xl font-bold page-title">Archives</h2>
|
||||
<h2 className="text-xl font-bold page-title">{title || "Archives"}</h2>
|
||||
{posts.list.length === 0 && (
|
||||
<div className="mt-5">
|
||||
<EmptyState />
|
||||
|
||||
@@ -96,7 +96,6 @@ export const SiteHeader: React.FC<{
|
||||
const siteSubscriptions = useGetSiteSubscriptions({
|
||||
siteId: site?.username || "",
|
||||
})
|
||||
console.log(siteSubscriptions.data)
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
|
||||
@@ -107,6 +107,7 @@ export async function getPagesBySite(input: {
|
||||
includeContent?: boolean
|
||||
includeExcerpt?: boolean
|
||||
render?: boolean
|
||||
tags?: string[]
|
||||
}) {
|
||||
if (!input.site) {
|
||||
return {
|
||||
@@ -122,6 +123,9 @@ export async function getPagesBySite(input: {
|
||||
identity: input.site,
|
||||
platform: "Crossbell",
|
||||
limit: input.take || 1000,
|
||||
filter: {
|
||||
tags: [...(input.tags || []), input.type],
|
||||
},
|
||||
})) || {
|
||||
total: 0,
|
||||
list: [],
|
||||
@@ -154,7 +158,6 @@ export async function getPagesBySite(input: {
|
||||
page.applications?.includes("Crosslog") ||
|
||||
page.applications?.includes("xlog"),
|
||||
)
|
||||
.filter((page) => page.tags?.includes(input.type))
|
||||
.sort((a, b) => +new Date(b.date_published) - +new Date(a.date_published))
|
||||
pages.total = pages.list.length
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { GetServerSideProps } from "next"
|
||||
import { SiteLayout } from "~/components/site/SiteLayout"
|
||||
import { serverSidePropsHandler } from "~/lib/server-side-props"
|
||||
import { SiteArchives } from "~/components/site/SiteArchives"
|
||||
import { Viewer, Profile, Notes } from "~/lib/types"
|
||||
import { queryClientServer } from "~/lib/query-client.server"
|
||||
import { prefetchGetSite } from "~/queries/site.server"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
import { dehydrate, QueryClient } from "@tanstack/react-query"
|
||||
import { useGetPagesBySite } from "~/queries/page"
|
||||
import { prefetchGetPagesBySite } from "~/queries/page.server"
|
||||
import { PageVisibilityEnum } from "~/lib/types"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
|
||||
async (ctx) => {
|
||||
const domainOrSubdomain = ctx.params!.site as string
|
||||
const tag = ctx.params!.tag as string
|
||||
|
||||
await prefetchGetSite(domainOrSubdomain)
|
||||
await prefetchGetPagesBySite({
|
||||
site: domainOrSubdomain,
|
||||
take: 1000,
|
||||
type: "post",
|
||||
visibility: PageVisibilityEnum.Published,
|
||||
tags: [tag],
|
||||
})
|
||||
|
||||
return {
|
||||
props: {
|
||||
dehydratedState: dehydrate(queryClientServer),
|
||||
domainOrSubdomain,
|
||||
tag,
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
function SiteArchivesPage({
|
||||
domainOrSubdomain,
|
||||
tag,
|
||||
}: {
|
||||
site: Profile
|
||||
posts: Notes
|
||||
domainOrSubdomain: string
|
||||
tag: string
|
||||
}) {
|
||||
const site = useGetSite(domainOrSubdomain)
|
||||
const posts = useGetPagesBySite({
|
||||
site: domainOrSubdomain,
|
||||
take: 1000,
|
||||
type: "post",
|
||||
visibility: PageVisibilityEnum.Published,
|
||||
tags: [tag],
|
||||
})
|
||||
|
||||
return (
|
||||
<SiteLayout site={site.data} title={tag}>
|
||||
<SiteArchives posts={posts.data} title={tag} />
|
||||
</SiteLayout>
|
||||
)
|
||||
}
|
||||
|
||||
export default SiteArchivesPage
|
||||
@@ -128,6 +128,19 @@ export default function SiteSettingsNavigationPage() {
|
||||
return (
|
||||
<DashboardLayout title="Navigation">
|
||||
<SettingsLayout title="Site Settings" type="site">
|
||||
<div className="p-5 text-zinc-500 bg-zinc-50 mb-5 rounded-lg text-xs space-y-2">
|
||||
<p className="text-zinc-800 text-sm font-bold">
|
||||
Tips: built-in pages
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-zinc-800">Archives page:</span>{" "}
|
||||
<span className="bg-zinc-200 rounded-lg px-2">/archives</span>
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-zinc-900">Tag page:</span>{" "}
|
||||
<span className="bg-zinc-200 rounded-lg px-2">/tag/[tag]</span>
|
||||
</p>
|
||||
</div>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="bg-zinc-50 rounded-lg overflow-hidden">
|
||||
{items.length === 0 && (
|
||||
|
||||
Reference in New Issue
Block a user