Skip to content

Commit

Permalink
feat: rss render
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed Jul 11, 2023
1 parent fc4e375 commit a47ad57
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/app/feed/route.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import Markdown from 'markdown-to-jsx'
import { compiler } from 'markdown-to-jsx'
import xss from 'xss'
import type { AggregateRoot } from '@mx-space/api-client'

import { InsertRule } from '~/components/ui/markdown/parsers/ins'
import { MarkRule } from '~/components/ui/markdown/parsers/mark'
import { MentionRule } from '~/components/ui/markdown/parsers/mention'
import { SpoilderRule } from '~/components/ui/markdown/parsers/spoiler'
import { escapeXml } from '~/lib/helper.server'
import { getQueryClient } from '~/lib/query-client.server'
import { apiClient } from '~/lib/request'
Expand Down Expand Up @@ -59,7 +63,27 @@ export async function GET() {
${`<blockquote>该渲染由 Shiro API 生成,可能存在排版问题,最佳体验请前往:<a href='${xss(
item.link,
)}'>${xss(item.link)}</a></blockquote>
${ReactDOM.renderToString(<Markdown>{item.text}</Markdown>)}
${ReactDOM.renderToString(
<div>
{compiler(item.text, {
overrides: {
LinkCard: () => null,
Gallery: () => (
<div style={{ textAlign: 'center' }}>这个内容只能在原文中查看哦~</div>
),
},
additionalParserRules: {
spoilder: SpoilderRule,
mention: MentionRule,
mark: MarkRule,
ins: InsertRule,
// kateX: KateXRule,
// container: ContainerRule,
},
})}
</div>,
)}
<p style='text-align: right'>
<a href='${`${xss(item.link)}#comments`}'>看完了?说点什么呢</a>
</p>`}
Expand Down
2 changes: 2 additions & 0 deletions src/components/ui/gallery/Gallery.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import { memo, useCallback, useEffect, useRef, useState } from 'react'
import { useInView } from 'react-intersection-observer'
import clsx from 'clsx'
Expand Down
2 changes: 2 additions & 0 deletions src/components/ui/link-card/LinkCard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import React, { useCallback, useMemo, useRef, useState } from 'react'
import { useInView } from 'react-intersection-observer'
import axios from 'axios'
Expand Down
2 changes: 2 additions & 0 deletions src/components/ui/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

/* eslint-disable react-hooks/rules-of-hooks */
import React, { Fragment, memo, Suspense, useMemo, useRef } from 'react'
import { clsx } from 'clsx'
Expand Down

1 comment on commit a47ad57

@vercel
Copy link

@vercel vercel bot commented on a47ad57 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

springtide.vercel.app
shiro-innei.vercel.app
innei.in
shiro-git-main-innei.vercel.app

Please sign in to comment.