feat: support itunes rss
This commit is contained in:
parent
a7e8969b0d
commit
aa7e0c37c0
|
|
@ -19,6 +19,7 @@ export const expandUnidataNote = async (page: Note, useStat?: boolean) => {
|
|||
}
|
||||
}
|
||||
page.cover = rendered.cover
|
||||
page.audio = rendered.audio
|
||||
if (page.metadata) {
|
||||
page.metadata.frontMatter = rendered.frontMatter
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ export const getJsonFeed = async (domainOrSubdomain: string, path: string) => {
|
|||
queryClient,
|
||||
)
|
||||
|
||||
const hasAudio = pages.list?.find((page: any) => page.audio)
|
||||
|
||||
const link = getSiteLink({
|
||||
subdomain: site.username || "",
|
||||
})
|
||||
|
|
@ -30,6 +32,13 @@ export const getJsonFeed = async (domainOrSubdomain: string, path: string) => {
|
|||
icon: site.avatars?.[0],
|
||||
home_page_url: link,
|
||||
feed_url: `${link}${path}`,
|
||||
...(hasAudio && {
|
||||
_itunes: {
|
||||
image: site.avatars?.[0],
|
||||
author: site.name,
|
||||
summary: site.description,
|
||||
},
|
||||
}),
|
||||
items: pages.list?.map((page: any) => ({
|
||||
id: page.id,
|
||||
title: page.title,
|
||||
|
|
@ -38,10 +47,24 @@ export const getJsonFeed = async (domainOrSubdomain: string, path: string) => {
|
|||
renderPageContent(page.body?.content, true).contentHTML,
|
||||
summary: page.summary?.content,
|
||||
url: `${link}/${page.slug || page.id}`,
|
||||
image: `${link}${page.cover}`,
|
||||
image: page.cover,
|
||||
date_published: page.date_published,
|
||||
date_modified: page.date_updated,
|
||||
tags: page.tags,
|
||||
author: site.name,
|
||||
...(page.audio && {
|
||||
_itunes: {
|
||||
image: page.cover,
|
||||
summary: page.summary?.content,
|
||||
},
|
||||
attachments: [
|
||||
{
|
||||
url: page.audio,
|
||||
mime_type: "audio/mpeg",
|
||||
title: page.title,
|
||||
},
|
||||
],
|
||||
}),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ export type Note = UniNote & {
|
|||
slug?: string
|
||||
character?: Profile
|
||||
cover?: string
|
||||
audio?: string
|
||||
body?: {
|
||||
content?: string
|
||||
address?: string
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ export type MarkdownEnv = {
|
|||
frontMatter: Record<string, any>
|
||||
__internal: Record<string, any>
|
||||
cover: string
|
||||
audio: string
|
||||
toc: TocResult | null
|
||||
tree: Root | null
|
||||
}
|
||||
|
|
@ -54,6 +55,7 @@ export type Rendered = {
|
|||
excerpt: string
|
||||
frontMatter: Record<string, any>
|
||||
cover: string
|
||||
audio: string
|
||||
toc: TocResult | null
|
||||
tree: Root | null
|
||||
}
|
||||
|
|
@ -71,6 +73,7 @@ export const renderPageContent = (
|
|||
__internal: {},
|
||||
frontMatter: {},
|
||||
cover: "",
|
||||
audio: "",
|
||||
toc: null,
|
||||
tree: null,
|
||||
}
|
||||
|
|
@ -113,7 +116,7 @@ export const renderPageContent = (
|
|||
.use(rehypeStringify)
|
||||
.use(rehypeRaw)
|
||||
.use(rehypeImage, { env })
|
||||
.use(rehypeAudio)
|
||||
.use(rehypeAudio, { env })
|
||||
.use(rehypeSlug)
|
||||
.use(rehypeAutolinkHeadings, {
|
||||
properties: {
|
||||
|
|
@ -211,6 +214,7 @@ export const renderPageContent = (
|
|||
excerpt: result?.data.meta.description,
|
||||
frontMatter: env.frontMatter,
|
||||
cover: env.cover,
|
||||
audio: env.audio,
|
||||
toc: env.toc,
|
||||
tree: env.tree,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,13 @@ import { visit } from "unist-util-visit"
|
|||
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
|
||||
export const rehypeAudio: Plugin<Array<void>, Root> = () => {
|
||||
import { MarkdownEnv } from "."
|
||||
|
||||
export const rehypeAudio: Plugin<Array<{ env: MarkdownEnv }>, Root> = ({
|
||||
env,
|
||||
}) => {
|
||||
return (tree) => {
|
||||
let first = true
|
||||
visit(tree, { tagName: "audio" }, (node, i, parent) => {
|
||||
if (!node.properties) {
|
||||
return
|
||||
|
|
@ -19,6 +24,11 @@ export const rehypeAudio: Plugin<Array<void>, Root> = () => {
|
|||
|
||||
node.properties.src = toGateway(src)
|
||||
|
||||
if (first) {
|
||||
env.audio = node.properties.src
|
||||
first = false
|
||||
}
|
||||
|
||||
if (parent) {
|
||||
parent.children[i!] = {
|
||||
type: "element",
|
||||
|
|
|
|||
Loading…
Reference in New Issue