mirror of
https://github.com/tjsga/tj-sga-website-react.git
synced 2025-04-21 12:00:17 -04:00
Links inside news articles open in a new tab
This commit is contained in:
parent
f53b64edab
commit
b9f611698a
|
@ -14,7 +14,7 @@ export default function NewsArticle() {
|
||||||
sanity.fetch('*[_id == $articleId] [0]', { articleId }).then(setArticle);
|
sanity.fetch('*[_id == $articleId] [0]', { articleId }).then(setArticle);
|
||||||
}, [articleId]);
|
}, [articleId]);
|
||||||
|
|
||||||
let thumbUrl: string | null = null;
|
let thumbUrl: string;
|
||||||
if (article?.thumbnail) {
|
if (article?.thumbnail) {
|
||||||
thumbUrl = imageUrl(article.thumbnail).url();
|
thumbUrl = imageUrl(article.thumbnail).url();
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,7 +36,21 @@ export default function NewsArticle() {
|
||||||
</i>
|
</i>
|
||||||
<br />
|
<br />
|
||||||
{/* Wrap the BlockContent in a div because it expands to <></> */}
|
{/* Wrap the BlockContent in a div because it expands to <></> */}
|
||||||
<div className='article-paragraphs'>
|
<div
|
||||||
|
id='article-content'
|
||||||
|
className='article-paragraphs'
|
||||||
|
ref={(ref) => {
|
||||||
|
/*
|
||||||
|
When this element loads, convert all the links to have target="_blank."
|
||||||
|
This ensures that the links open in a new tab
|
||||||
|
*/
|
||||||
|
if (ref) {
|
||||||
|
ref.querySelectorAll('a').forEach((link) => {
|
||||||
|
link.target = '_blank';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<BlockContent blocks={article.content} />
|
<BlockContent blocks={article.content} />
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user