Skip to content

Commit

Permalink
[components,mdx][s]: fix next seo images build error and add components
Browse files Browse the repository at this point in the history
  - add checks for  next seo image in config
  - add custom anchor links component that supports next links
  - modify svg component to use react fragment replacing p tags
  • Loading branch information
khalilcodes committed Aug 31, 2022
1 parent d34e3cb commit 3b198f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions templates/default/components/Link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Link from 'next/link'

const CustomLink = ({ href, ...rest }) => {
const isInternalLink = href && href.startsWith('/')
const isAnchorLink = href && href.startsWith('#')

if (isInternalLink) {
return (
<Link href={href}>
<a {...rest} />
</Link>
)
}

if (isAnchorLink) {
return <a href={href} {...rest} />
}

return <a target="_blank" rel="noopener noreferrer" href={href} {...rest} />
}

export default CustomLink
6 changes: 5 additions & 1 deletion templates/default/components/MDX.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Fragment } from 'react'
import { NextSeo } from 'next-seo'
import Head from 'next/head'
import CustomLink from './Link'
import { Pre } from './Pre'
import siteConfig from '../config/siteConfig'

const components = {
Head,
a: CustomLink,
pre: Pre,
svg: props => <Fragment {...props} />,

This comment has been minimized.

Copy link
@olayway

olayway Sep 1, 2022

Member

This is stripping svgs of their root tag , so it won't work. And btw, what's the purpose of it?

This comment has been minimized.

Copy link
@khalilcodes

khalilcodes Sep 1, 2022

Author Contributor

@olayway This was actually an issue in ecosystem where svgs were being wrapped in <p> tags and was affecting the D3 graph visualizations

This comment has been minimized.

Copy link
@olayway

olayway Sep 1, 2022

Member

hmmm.. but this way you are not getting rid of the p tag, you are getting rid of the SVG tag

GlobalTest: ({children}) => <h1 className="bg-red-300">{children}</h1>,
wrapper: ({ layout, ...rest }) => {
const Layout = require(`../layouts/${layout}`).default
Expand Down Expand Up @@ -36,7 +40,7 @@ export default function MdxPage({ children, ...rest }) {
alt: frontMatter.title
}
]
: siteConfig.nextSeo.openGraph.images,
: siteConfig?.nextSeo?.openGraph?.images || [],
}}
/>
<Component
Expand Down

0 comments on commit 3b198f7

Please sign in to comment.