Skip to content

Commit

Permalink
Add target="_blank" to links in post
Browse files Browse the repository at this point in the history
  • Loading branch information
JorianWoltjer committed Dec 13, 2023
1 parent e9890a7 commit f99a5a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions frontend/components/PostContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Breadcrumbs, CodeBlock, RelativeTime, TableOfContents, Tags } from '@/c
import { faEye } from '@fortawesome/free-regular-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import 'highlight.js/styles/github-dark.css';
import parse from 'html-react-parser';
import parse, { domToReact } from 'html-react-parser';
import Image from 'next/image';
import Link from 'next/link';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -39,11 +39,13 @@ export function render(html, mounted) {
if (node.attribs.href === node.children[0].data && match) {
return <iframe width="560" height="315" src={`https://www.youtube-nocookie.com/embed/${match[1]}`} title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>
}
// Convert other links to `target="_blank"`
return <a href={node.attribs.href} target="_blank">{domToReact(node.children)}</a>

} else if (node.type === 'tag' && Object.keys(headers).includes(node.name)) {
// Add anchor links to headings
const id = node.attribs.id;
return headers[node.name]({ id, children: <a className="header-link" href={`#${id}`}>{node.children[0].data}</a> })
return headers[node.name]({ id, children: <a className="header-link" href={`#${id}`}>{domToReact(node.children)}</a> })
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/api/revalidate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';

export default async function handler(req, res) {
// X-Internal header is set to "false" by nginx, only internal requests can set it to "true"
// X-Internal header is set to "false" by nginx
const is_internal = req.headers["x-internal"] === process.env.INTERNAL_TOKEN;
if (!is_internal) {
return res.status(403).json({ message: "Forbidden" });
Expand Down

0 comments on commit f99a5a4

Please sign in to comment.