feat: render home page via api to reduce js size
This commit is contained in:
parent
cd41e61363
commit
cd2fdaf3da
|
|
@ -70,7 +70,6 @@ export const PagesManager: React.FC<{
|
|||
site: subdomain!,
|
||||
take: 100,
|
||||
visibility,
|
||||
render: true,
|
||||
})
|
||||
|
||||
const tabItems: TabItem[] = [
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ export const getServerSideProps = async (
|
|||
...(options?.take && { take: options.take }),
|
||||
type: "post",
|
||||
visibility: PageVisibilityEnum.Published,
|
||||
render: true,
|
||||
...(tag && { tags: [tag] }),
|
||||
},
|
||||
queryClient,
|
||||
|
|
|
|||
|
|
@ -195,9 +195,6 @@ export async function getPagesBySite(
|
|||
visibility?: PageVisibilityEnum | null
|
||||
take?: number | null
|
||||
cursor?: string | null
|
||||
includeContent?: boolean
|
||||
includeExcerpt?: boolean
|
||||
render?: boolean
|
||||
tags?: string[]
|
||||
},
|
||||
customUnidata?: Unidata,
|
||||
|
|
@ -284,7 +281,7 @@ export async function getPagesBySite(
|
|||
pages.total = pages.total - ((input.take || 10) - pages.list.length)
|
||||
|
||||
pages?.list.map((page) => {
|
||||
expandPage(page, input.render || false)
|
||||
expandPage(page, true)
|
||||
delete page.body
|
||||
return page
|
||||
})
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ const expandSite = (site: Profile) => {
|
|||
(a: any) => a.trait_type === "xlog_custom_domain",
|
||||
)?.value || ""
|
||||
site.name = site.name || site.username
|
||||
site.description = renderPageContent(site.bio || "", true).contentHTML
|
||||
site.description = site.bio
|
||||
|
||||
if (site.avatars) {
|
||||
site.avatars = site.avatars.map((avatar) => toGateway(avatar))
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ function SiteArchivesPage({
|
|||
take: 100,
|
||||
type: "post",
|
||||
visibility: PageVisibilityEnum.Published,
|
||||
render: true,
|
||||
})
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|||
site: domainOrSubdomain,
|
||||
type: "post",
|
||||
visibility: PageVisibilityEnum.Published,
|
||||
render: true,
|
||||
},
|
||||
queryClient,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ function SiteIndexPage({ domainOrSubdomain }: { domainOrSubdomain: string }) {
|
|||
site: domainOrSubdomain,
|
||||
type: "post",
|
||||
visibility: PageVisibilityEnum.Published,
|
||||
render: true,
|
||||
})
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ function SiteTagPage({
|
|||
take: 100,
|
||||
type: "post",
|
||||
visibility: PageVisibilityEnum.Published,
|
||||
render: true,
|
||||
tags: [tag],
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next"
|
||||
import { getPagesBySite } from "~/models/page.model"
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse,
|
||||
) {
|
||||
const query = req.query
|
||||
|
||||
const result = await getPagesBySite(query as any)
|
||||
|
||||
res.status(200).json(result)
|
||||
}
|
||||
|
|
@ -11,17 +11,19 @@ import { useContract } from "./crossbell"
|
|||
export const useGetPagesBySite = (
|
||||
input: Parameters<typeof pageModel.getPagesBySite>[0],
|
||||
) => {
|
||||
const unidata = useUnidata()
|
||||
return useInfiniteQuery({
|
||||
queryKey: ["getPagesBySite", input.site, input],
|
||||
queryFn: async ({ pageParam }) => {
|
||||
return pageModel.getPagesBySite(
|
||||
{
|
||||
...input,
|
||||
cursor: pageParam,
|
||||
},
|
||||
unidata,
|
||||
)
|
||||
const result: ReturnType<typeof pageModel.getPagesBySite> = await (
|
||||
await fetch(
|
||||
"/api/pages?" +
|
||||
new URLSearchParams({
|
||||
...input,
|
||||
...(pageParam && { cursor: pageParam }),
|
||||
} as any),
|
||||
)
|
||||
).json()
|
||||
return result
|
||||
},
|
||||
getNextPageParam: (lastPage) => lastPage.cursor,
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue