render outlawed images and links as text
This commit is contained in:
parent
b16234630b
commit
b5de515f5e
|
@ -212,7 +212,7 @@ export default function Comment ({
|
||||||
{item.searchText
|
{item.searchText
|
||||||
? <SearchText text={item.searchText} />
|
? <SearchText text={item.searchText} />
|
||||||
: (
|
: (
|
||||||
<Text itemId={item.id} topLevel={topLevel} rel={item.rel ?? UNKNOWN_LINK_REL} imgproxyUrls={item.imgproxyUrls}>
|
<Text itemId={item.id} topLevel={topLevel} rel={item.rel ?? UNKNOWN_LINK_REL} outlawed={item.outlawed} imgproxyUrls={item.imgproxyUrls}>
|
||||||
{item.outlawed && !me?.privates?.wildWestMode
|
{item.outlawed && !me?.privates?.wildWestMode
|
||||||
? '*stackers have outlawed this. turn on wild west mode in your [settings](/settings) to see outlawed content.*'
|
? '*stackers have outlawed this. turn on wild west mode in your [settings](/settings) to see outlawed content.*'
|
||||||
: truncate ? truncateString(item.text) : item.text}
|
: truncate ? truncateString(item.text) : item.text}
|
||||||
|
|
|
@ -171,7 +171,7 @@ function TopLevelItem ({ item, noReply, ...props }) {
|
||||||
function ItemText ({ item }) {
|
function ItemText ({ item }) {
|
||||||
return item.searchText
|
return item.searchText
|
||||||
? <SearchText text={item.searchText} />
|
? <SearchText text={item.searchText} />
|
||||||
: <Text itemId={item.id} topLevel rel={item.rel ?? UNKNOWN_LINK_REL} imgproxyUrls={item.imgproxyUrls}>{item.text}</Text>
|
: <Text itemId={item.id} topLevel rel={item.rel ?? UNKNOWN_LINK_REL} outlawed={item.outlawed} imgproxyUrls={item.imgproxyUrls}>{item.text}</Text>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ItemFull ({ item, bio, rank, ...props }) {
|
export default function ItemFull ({ item, bio, rank, ...props }) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ export function SearchText ({ text }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is one of the slowest components to render
|
// this is one of the slowest components to render
|
||||||
export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, ...outerProps }) {
|
export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, outlawed, ...outerProps }) {
|
||||||
const [overflowing, setOverflowing] = useState(false)
|
const [overflowing, setOverflowing] = useState(false)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [show, setShow] = useState(false)
|
const [show, setShow] = useState(false)
|
||||||
|
@ -139,6 +139,10 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, .
|
||||||
|
|
||||||
const Img = useCallback(({ node, src, ...props }) => {
|
const Img = useCallback(({ node, src, ...props }) => {
|
||||||
const url = IMGPROXY_URL_REGEXP.test(src) ? decodeOriginalUrl(src) : src
|
const url = IMGPROXY_URL_REGEXP.test(src) ? decodeOriginalUrl(src) : src
|
||||||
|
// if outlawed, render the image link as text
|
||||||
|
if (outlawed) {
|
||||||
|
return url
|
||||||
|
}
|
||||||
const srcSet = imgproxyUrls?.[url]
|
const srcSet = imgproxyUrls?.[url]
|
||||||
return <ZoomableImage srcSet={srcSet} tab={tab} src={src} rel={rel ?? UNKNOWN_LINK_REL} {...props} {...outerProps} />
|
return <ZoomableImage srcSet={srcSet} tab={tab} src={src} rel={rel ?? UNKNOWN_LINK_REL} {...props} {...outerProps} />
|
||||||
}, [imgproxyUrls, outerProps, tab])
|
}, [imgproxyUrls, outerProps, tab])
|
||||||
|
@ -166,6 +170,11 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, .
|
||||||
return <>{children}</>
|
return <>{children}</>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if outlawed, render the link as text
|
||||||
|
if (outlawed) {
|
||||||
|
return href
|
||||||
|
}
|
||||||
|
|
||||||
// If [text](url) was parsed as <a> and text is not empty and not a link itself,
|
// If [text](url) was parsed as <a> and text is not empty and not a link itself,
|
||||||
// we don't render it as an image since it was probably a conscious choice to include text.
|
// we don't render it as an image since it was probably a conscious choice to include text.
|
||||||
const text = children[0]
|
const text = children[0]
|
||||||
|
|
Loading…
Reference in New Issue