feat: integration with follow

This commit is contained in:
Stephen Zhou
2024-09-13 08:37:01 +08:00
parent 7b223590a4
commit 47d09468fc
8 changed files with 178 additions and 129 deletions
@@ -36,6 +36,8 @@ export default function SiteSettingsGeneralPage() {
uh: "",
code_theme_light: "",
code_theme_dark: "",
follow_feed_id: undefined,
follow_user_id: undefined,
} as {
icon?: string
banner?: {
@@ -51,6 +53,8 @@ export default function SiteSettingsGeneralPage() {
uh: string
code_theme_light: string
code_theme_dark: string
follow_feed_id?: string
follow_user_id?: string
},
})
@@ -70,6 +74,10 @@ export default function SiteSettingsGeneralPage() {
light: values.code_theme_light,
dark: values.code_theme_dark,
},
follow: {
feed_id: values.follow_feed_id,
user_id: values.follow_user_id,
},
})
})
@@ -126,6 +134,16 @@ export default function SiteSettingsGeneralPage() {
site.data.metadata?.content?.code_theme?.dark ||
"github-dark-default",
)
!form.getValues("follow_feed_id") &&
form.setValue(
"follow_feed_id",
site.data.metadata?.content?.follow?.feed_id,
)
!form.getValues("follow_user_id") &&
form.setValue(
"follow_user_id",
site.data.metadata?.content?.follow?.user_id,
)
}
}, [site.data, form])
@@ -248,6 +266,21 @@ export default function SiteSettingsGeneralPage() {
{...form.register("code_theme_dark")}
/>
</div>
<div className="mt-5 flex gap-6 items-center">
<p className="text-lg font-bold">Follow</p>
<div className="flex gap-3">
<Input
label="Feed ID"
id="follow_feed_id"
{...form.register("follow_feed_id")}
/>
<Input
label="User ID"
id="follow_user_id"
{...form.register("follow_user_id")}
/>
</div>
</div>
<div className="mt-5">
<Input
id="ga"
+86 -1
View File
@@ -1,3 +1,5 @@
import RSS from "rss"
import { SITE_URL } from "~/lib/env"
import { getSiteLink } from "~/lib/helpers"
import { NextServerResponse } from "~/lib/server-helper"
@@ -38,6 +40,10 @@ export async function GET(
subdomain: site?.handle || "",
domain: site?.metadata?.content?.custom_domain,
})
const followFeedId = site?.metadata?.content?.follow?.feed_id
const followUserId = site?.metadata?.content?.follow?.user_id
const data = {
version: "https://jsonfeed.org/version/1",
title: site?.metadata?.content?.site_name || site?.metadata?.content?.name,
@@ -57,6 +63,14 @@ export async function GET(
},
},
}),
...(followFeedId && followUserId
? {
follow_challenge: {
feed_id: followFeedId,
user_id: followUserId,
},
}
: {}),
items: pages.list?.map((page) => ({
id: page.characterId + "-" + page.noteId,
title: page.metadata?.content?.title || "Untitled",
@@ -84,13 +98,84 @@ export async function GET(
})),
}
const feed = new RSS({
title:
site?.metadata?.content?.site_name ||
site?.metadata?.content?.name ||
"Untitled",
description: site?.metadata?.content?.bio,
image_url: site?.metadata?.content?.avatars?.[0],
site_url: link,
feed_url: `${link}/feed`,
custom_namespaces: {
itunes: "http://www.itunes.com/dtds/podcast-1.0.dtd",
},
custom_elements: [
...(hasAudio
? [
{ "itunes:image": site?.metadata?.content?.avatars?.[0] },
{
"itunes:author":
site?.metadata?.content?.site_name ||
site?.metadata?.content?.name,
},
{ "itunes:summary": site?.metadata?.content?.bio },
{
"itunes:owner": [
{
"itunes:email": email,
},
{
"itunes:name": site?.metadata?.content?.name,
},
],
},
]
: []),
...(followFeedId && followUserId
? [
{
follow_challenge: [
{ feedId: followFeedId },
{ userId: followUserId },
],
},
,
]
: []),
],
})
pages.list.forEach((page) => {
feed.item({
guid: page.characterId + "-" + page.noteId,
title: page.metadata?.content?.title || "Untitled",
description: page.metadata?.content?.summary,
custom_elements: [
{
"content:encoded": page.metadata?.content?.contentHTML,
},
],
url: `${SITE_URL}/api/redirection?characterId=${page.characterId}&noteId=${page.noteId}`,
date: new Date(page.metadata?.content?.date_published),
categories: page.metadata?.content?.tags,
author: site?.metadata?.content?.name,
enclosure: hasAudio
? {
url: page.metadata?.content?.audio,
type: "audio/mpeg",
}
: undefined,
})
})
const format =
new URLSearchParams(request.url.split("?")[1]).get("format") === "json"
? "json"
: "xml"
const res = new NextServerResponse()
return res.status(200).rss(data, format)
return res.status(200).rss(format === "json" ? data : feed.xml(), format)
}
export const dynamic = "force-dynamic"
+7
View File
@@ -277,6 +277,13 @@ export const expandCrossbellCharacter = async (site: CharacterEntity) => {
dark: "github-dark-default",
}
expandedCharacter.metadata.content.follow =
JSON.parse(
(expandedCharacter.metadata?.content?.attributes?.find(
(a: any) => a.trait_type === "xlog_follow",
)?.value as string) || "null",
) || undefined
const getArribute = (outputKey: string, typeKey: string) => {
;(expandedCharacter.metadata.content as any)[outputKey] =
expandedCharacter.metadata?.content?.attributes?.find(
+1 -4
View File
@@ -1,6 +1,3 @@
// @ts-ignore
import jsonfeedToRSS from "jsonfeed-to-rss"
export const getQuery = (req: Request) => {
const url = new URL(req.url)
const searchParams = url.searchParams
@@ -69,7 +66,7 @@ export class NextServerResponse {
rss(data: any, format = "json") {
if (format === "xml") {
return new Response(jsonfeedToRSS(data), {
return new Response(data, {
status: this.#status,
headers: {
"Content-Type": "application/xml; charset=utf-8",
+4
View File
@@ -132,6 +132,10 @@ export type ExpandedCharacter = CharacterEntity & {
light?: BundledTheme
dark?: BundledTheme
}
follow?: {
feed_id?: string
user_id?: string
}
}
}
}
+5
View File
@@ -152,6 +152,10 @@ export function useUpdateSite() {
light?: string
dark?: string
}
follow?: {
feed_id?: string
user_id?: string
}
}) => {
if (!input.characterId) {
throw new Error("characterId are required")
@@ -222,6 +226,7 @@ export function useUpdateSite() {
}
setAttribute("navigation", "navigation", true)
setAttribute("code_theme", "code_theme", true)
setAttribute("follow", "follow", true)
setAttribute("css", "css")
setAttribute("ga", "ga")
setAttribute("ua", "ua")