Skip to content

Commit 93d82e6

Browse files
authored
Merge pull request #2 from xwcoder/feature/article-content-optimize
Feature/article content optimize
2 parents 63f214f + 339f70d commit 93d82e6

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/renderer/apps/reader/MainPanel/Article/content.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable react/no-danger */
2-
2+
import { useEffect, useRef } from 'react'
33
import { makeStyles, tokens } from '@fluentui/react-components'
44
import { observer } from 'mobx-react-lite'
55
import { store } from '@/renderer/store'
66
import { format as formatTime } from '@/utils/common/date'
7+
import { openExternal } from '@/utils/browser/shell'
78

89
const { readerStore } = store
910

@@ -34,6 +35,21 @@ const useStyles = makeStyles({
3435
fontSize: tokens.fontSizeBase400,
3536
lineHeight: 1.2,
3637
},
38+
39+
'& a': {
40+
color: tokens.colorBrandForegroundLink,
41+
textDecorationLine: 'underline',
42+
43+
':hover': {
44+
color: tokens.colorBrandForegroundLinkHover,
45+
},
46+
':active': {
47+
color: tokens.colorBrandForegroundLinkSelected,
48+
},
49+
':visited': {
50+
color: tokens.colorBrandForegroundLinkPressed,
51+
},
52+
},
3753
},
3854
})
3955

@@ -53,6 +69,27 @@ function Content() {
5369
} = activeArticle
5470
const feed = feeds.find((v) => v.id === feedId)!
5571

72+
const containerRef = useRef<HTMLDivElement>(null)
73+
74+
useEffect(() => {
75+
const el = containerRef.current
76+
const handler = (e: MouseEvent) => {
77+
const { target } = e
78+
if (!(target instanceof HTMLAnchorElement) || !target.href) {
79+
return
80+
}
81+
82+
e.preventDefault()
83+
openExternal(target.href)
84+
}
85+
86+
el?.addEventListener('click', handler)
87+
88+
return () => {
89+
el?.removeEventListener('click', handler)
90+
}
91+
}, [containerRef.current])
92+
5693
return (
5794
<div>
5895
<h1 className="text-2xl px-5 pt-4 pb-3">
@@ -70,6 +107,7 @@ function Content() {
70107
</div>
71108
<div className="px-5">
72109
<div
110+
ref={containerRef}
73111
className={styles.content}
74112
dangerouslySetInnerHTML={{ __html: content }}
75113
/>

0 commit comments

Comments
 (0)