Skip to content

Commit 56823e3

Browse files
committed
fix: ui improve
1 parent a136560 commit 56823e3

File tree

14 files changed

+307
-49
lines changed

14 files changed

+307
-49
lines changed

public/404.svg

+155
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { SVGProps } from 'react'
2+
3+
export function SimpleIconsZhihu(props: SVGProps<SVGSVGElement>) {
4+
return (
5+
<svg
6+
xmlns="http://www.w3.org/2000/svg"
7+
width="1em"
8+
height="1em"
9+
viewBox="0 0 24 24"
10+
{...props}
11+
>
12+
<path
13+
fill="currentColor"
14+
d="M5.721 0C2.251 0 0 2.25 0 5.719V18.28C0 21.751 2.252 24 5.721 24h12.56C21.751 24 24 21.75 24 18.281V5.72C24 2.249 21.75 0 18.281 0zm1.964 4.078c-.271.73-.5 1.434-.68 2.11h4.587c.545-.006.445 1.168.445 1.171H9.384a58.104 58.104 0 0 1-.112 3.797h2.712c.388.023.393 1.251.393 1.266H9.183a9.223 9.223 0 0 1-.408 2.102l.757-.604c.452.456 1.512 1.712 1.906 2.177c.473.681.063 2.081.063 2.081l-2.794-3.382c-.653 2.518-1.845 3.607-1.845 3.607c-.523.468-1.58.82-2.64.516c2.218-1.73 3.44-3.917 3.667-6.497H4.491c0-.015.197-1.243.806-1.266h2.71c.024-.32.086-3.254.086-3.797H6.598c-.136.406-.158.447-.268.753c-.594 1.095-1.603 1.122-1.907 1.155c.906-1.821 1.416-3.6 1.591-4.064c.425-1.124 1.671-1.125 1.671-1.125zM13.078 6h6.377v11.33h-2.573l-2.184 1.373l-.401-1.373h-1.219zm1.313 1.219v8.86h.623l.263.937l1.455-.938h1.456v-8.86z"
15+
/>
16+
</svg>
17+
)
18+
}

src/components/ui/markdown/renderers/link.tsx renamed to src/components/ui/link/MLink.tsx

+21-7
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ import {
66
isGithubProfileUrl,
77
isTelegramUrl,
88
isTwitterProfileUrl,
9+
isZhihuProfileUrl,
10+
parseZhihuProfileUrl,
911
} from '~/lib/link-parser'
1012

11-
import { FloatPopover } from '../../float-popover'
12-
import { Favicon } from '../../rich-link/Favicon'
13-
import { RichLink } from '../../rich-link/RichLink'
13+
import { FloatPopover } from '../float-popover'
14+
import { Favicon } from '../rich-link/Favicon'
15+
import { RichLink } from '../rich-link/RichLink'
1416

1517
export const MLink: FC<{
1618
href: string
1719
title?: string
1820
children?: ReactNode
19-
}> = memo(({ href, children, title }) => {
21+
text?: string
22+
}> = memo(({ href, children, title, text }) => {
2023
const router = useRouter()
2124
const handleRedirect = useCallback(
2225
(e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
@@ -46,7 +49,7 @@ export const MLink: FC<{
4649
}
4750
}
4851
},
49-
[href],
52+
[href, router],
5053
)
5154

5255
let parsedType = ''
@@ -69,8 +72,14 @@ export const MLink: FC<{
6972
parsedName = url.pathname.split('/')[1]
7073
break
7174
}
75+
case isZhihuProfileUrl(url): {
76+
parsedType = 'ZH'
77+
parsedName = parseZhihuProfileUrl(url).id
78+
}
7279
}
73-
} catch {}
80+
} catch {
81+
/* empty */
82+
}
7483

7584
const showRichLink = !!parsedType && !!parsedName
7685

@@ -84,7 +93,11 @@ export const MLink: FC<{
8493
<span className="inline items-center">
8594
{!showRichLink && <Favicon href={href} />}
8695
{showRichLink ? (
87-
<RichLink name={parsedName} source={parsedType} />
96+
<RichLink
97+
name={text || parsedName}
98+
source={parsedType}
99+
href={href}
100+
/>
88101
) : (
89102
<a
90103
className="shiro-link--underline"
@@ -109,6 +122,7 @@ export const MLink: FC<{
109122
showRichLink,
110123
parsedName,
111124
parsedType,
125+
text,
112126
],
113127
)}
114128
>

src/components/ui/link/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './MLink'

src/components/ui/markdown/Markdown.tsx

+9-17
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import type { FC, PropsWithChildren } from 'react'
1212
import { MAIN_MARKDOWN_ID } from '~/constants/dom-id'
1313
import { isDev } from '~/lib/env'
1414
import { springScrollToElement } from '~/lib/scroller'
15-
import { useWrappedElementSize } from '~/providers/shared/WrappedElementProvider'
1615

1716
import { Gallery } from '../gallery'
18-
import { FixedZoomedImage } from '../image'
1917
import { LinkCard } from '../link-card'
18+
import { MLink } from '../link/MLink'
2019
import styles from './markdown.module.css'
2120
import { ContainerRule } from './parsers/container'
2221
import { InsertRule } from './parsers/ins'
@@ -34,7 +33,7 @@ import {
3433
import { MDetails } from './renderers/collapse'
3534
import { MFootNote } from './renderers/footnotes'
3635
import { MHeader } from './renderers/heading'
37-
import { MLink } from './renderers/link'
36+
import { MarkdownImage } from './renderers/image'
3837

3938
const CodeBlock = dynamic(() => import('~/components/widgets/shared/CodeBlock'))
4039

@@ -124,11 +123,17 @@ export const Markdown: FC<MdProps & MarkdownToJSX.Options & PropsWithChildren> =
124123
link: {
125124
react(node, output, state) {
126125
const { target, title } = node
126+
const realText =
127+
node.content[0]?.content === node.target
128+
? void 0
129+
: node.content[0]?.content
130+
127131
return (
128132
<MLink
129133
href={sanitizeUrl(target)!}
130134
title={title}
131135
key={state?.key}
136+
text={realText}
132137
>
133138
{output(node.content, state!)}
134139
</MLink>
@@ -233,6 +238,7 @@ export const Markdown: FC<MdProps & MarkdownToJSX.Options & PropsWithChildren> =
233238
}, [
234239
value,
235240
props.children,
241+
allowsScript,
236242
overrides,
237243
extendsRules,
238244
renderers,
@@ -259,17 +265,3 @@ export const Markdown: FC<MdProps & MarkdownToJSX.Options & PropsWithChildren> =
259265
)
260266
})
261267
Markdown.displayName = 'Markdown'
262-
263-
const MarkdownImage = (props: any) => {
264-
const nextProps = {
265-
...props,
266-
}
267-
nextProps.alt = props.alt?.replace(/^[¡!]/, '')
268-
const { w } = useWrappedElementSize()
269-
270-
if (props.src.endsWith('.mp4')) {
271-
return <video src={props.src} controls playsInline autoPlay />
272-
}
273-
274-
return <FixedZoomedImage {...nextProps} containerWidth={w} />
275-
}

0 commit comments

Comments
 (0)