Skip to content

Commit

Permalink
All outbound links in blog posts open in new tab
Browse files Browse the repository at this point in the history
Fixes #88
  • Loading branch information
UnsignedArduino committed Mar 20, 2024
1 parent 4a68127 commit b55baa3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/pages/blog/[filename].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { PostQuery } from "../../../tina/__generated__/types";
import React from "react";
import { createBreadCrumbSegment } from "@/components/Layout/layout";
import BlogPost from "@/components/Blog/Post/Post";
import getElement from "@/scripts/Utils/Element";
import { forceOutboundLinksToNewPage } from "@/scripts/Utils/PageUtils";

type BlogProps = {
variables: { relativePath: string };
Expand All @@ -27,6 +29,11 @@ export default function BlogPage(props: BlogProps) {

const pageName = `${data.post.title} | Blog`;

React.useEffect(() => {
const div = getElement(`blogPost${data.post.title}`) as HTMLDivElement;
forceOutboundLinksToNewPage(div);
}, [data.post.title]);

return (
<Layout
title={pageName}
Expand All @@ -40,7 +47,9 @@ export default function BlogPage(props: BlogProps) {
]}
>
{/*<code>{JSON.stringify(data, null, 2)}</code>*/}
<BlogPost data={data} />
<div id={`blogPost${data.post.title}`}>
<BlogPost data={data} />
</div>
</Layout>
);
}
Expand Down
11 changes: 10 additions & 1 deletion src/pages/blog/authors/[author].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { AuthorsQuery } from "../../../../tina/__generated__/types";
import React from "react";
import { createBreadCrumbSegment } from "@/components/Layout/layout";
import BlogAuthor from "@/components/Blog/Author/Author";
import { forceOutboundLinksToNewPage } from "@/scripts/Utils/PageUtils";
import getElement from "@/scripts/Utils/Element";

type BlogAuthorProps = {
variables: { relativePath: string };
Expand All @@ -27,6 +29,11 @@ export default function BlogAuthorPage(props: BlogAuthorProps) {

const pageName = `${data.authors.name} | Blog`;

React.useEffect(() => {
const div = getElement(`blogAuthor${data.authors.name}`) as HTMLDivElement;
forceOutboundLinksToNewPage(div);
}, [data.authors.name]);

return (
<Layout
title={pageName}
Expand All @@ -44,7 +51,9 @@ export default function BlogAuthorPage(props: BlogAuthorProps) {
]}
>
{/*<code>{JSON.stringify(data, null, 2)}</code>*/}
<BlogAuthor data={data} />
<div id={`blogAuthor${data.authors.name}`}>
<BlogAuthor data={data} />
</div>
</Layout>
);
}
Expand Down

0 comments on commit b55baa3

Please sign in to comment.