Skip to content

Commit

Permalink
update rich text link style
Browse files Browse the repository at this point in the history
  • Loading branch information
saml33 committed Dec 20, 2023
1 parent cb5f99b commit ae3b88a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/(pages)/learn/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { draftMode } from 'next/headers'
import { notFound } from 'next/navigation'
import Link from 'next/link'
import { fetchBlogPost, fetchBlogPosts } from '../../../../contentful/blogPost'
import RichText from '../../../../contentful/RichText'
import RichText from '../../../components/RichText'

interface BlogPostPageParams {
slug: string
Expand Down
15 changes: 14 additions & 1 deletion contentful/RichText.tsx → app/components/RichText.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BLOCKS, MARKS } from '@contentful/rich-text-types'
import { BLOCKS, INLINES, MARKS } from '@contentful/rich-text-types'
import { Document as RichTextDocument } from '@contentful/rich-text-types'
import { documentToReactComponents } from '@contentful/rich-text-react-renderer'
import Link from 'next/link'

type RichTextProps = {
document: RichTextDocument | undefined
Expand Down Expand Up @@ -30,6 +31,17 @@ const H4 = ({ children }) => <h3 className="mb-1.5 text-base">{children}</h3>
const Ul = ({ children }) => (
<ul style={{ listStyle: 'inside disc', marginLeft: '16px' }}>{children}</ul>
)
const mangoUrl = 'https://mango.markets'
const A = ({ node, children }) => (
<Link
className="text-th-fgd-2 border-b border-th-active md:hover:border-transparent"
href={node.data.uri}
target={node.data.uri.startsWith(mangoUrl) ? '_self' : '_blank'}
rel={node.data.uri.startsWith(mangoUrl) ? '' : 'noopener noreferrer'}
>
{children}
</Link>
)

const Spacer = () => (
<hr style={{ borderColor: 'transparent', marginBottom: '12px' }} />
Expand All @@ -41,6 +53,7 @@ const options = {
},
renderNode: {
[BLOCKS.PARAGRAPH]: (node, children) => <Text>{children}</Text>,
[INLINES.HYPERLINK]: (node, children) => <A node={node}>{children}</A>,
[BLOCKS.HEADING_2]: (node, children) => <H2>{children}</H2>,
[BLOCKS.HEADING_3]: (node, children) => <H3>{children}</H3>,
[BLOCKS.HEADING_4]: (node, children) => <H4>{children}</H4>,
Expand Down
2 changes: 1 addition & 1 deletion app/components/shared/RichTextDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Document as RichTextDocument } from '@contentful/rich-text-types'
import RichText from '../../../contentful/RichText'
import RichText from '../RichText'

const RichTextDisplay = ({
content,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.tsbuildinfo

Large diffs are not rendered by default.

1 comment on commit ae3b88a

@vercel
Copy link

@vercel vercel bot commented on ae3b88a Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.