-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #991 from datopian/feature/seo-improvements-ii
SEO Improvements (II) - JSON-LD
- Loading branch information
Showing
20 changed files
with
223 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { ArticleJsonLd } from 'next-seo'; | ||
import { useRouter } from 'next/router'; | ||
|
||
export default function JSONLD({ | ||
meta, | ||
source, | ||
}: { | ||
meta: any; | ||
source: string; | ||
}): JSX.Element { | ||
if (!source) { | ||
return <></>; | ||
} | ||
|
||
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://portaljs.org'; | ||
const pageUrl = `${baseUrl}/${meta.urlPath}`; | ||
|
||
const imageMatches = source.match( | ||
/(?<=src: ")(.*)\.((png)|(jpg)|(jpeg))(?=")/g | ||
); | ||
let images = []; | ||
if (imageMatches) { | ||
images = [...imageMatches]; | ||
images = images.map((img) => | ||
img.startsWith('http') | ||
? img | ||
: `${baseUrl}${img.startsWith('/') ? '' : '/'}${img}` | ||
); | ||
} | ||
|
||
let Component: JSX.Element; | ||
|
||
const isBlog: boolean = | ||
/^blog\/.*/.test(meta.urlPath) || meta.filetype === 'blog'; | ||
const isDoc: boolean = /^((docs)|(howtos\/)|(guide\/)).*/.test(meta.urlPath); | ||
|
||
if (isBlog) { | ||
Component = ( | ||
<ArticleJsonLd | ||
type="BlogPosting" | ||
url={pageUrl} | ||
title={meta.title} | ||
datePublished={meta.date} | ||
dateModified={meta.date} | ||
authorName={meta.authors.length ? meta.authors[0].name : 'PortalJS'} | ||
description={meta.description} | ||
images={images} | ||
/> | ||
); | ||
} else if (isDoc) { | ||
Component = ( | ||
<ArticleJsonLd | ||
url={pageUrl} | ||
title={meta.title} | ||
images={images} | ||
datePublished={meta.date} | ||
dateModified={meta.date} | ||
authorName={meta.authors.length ? meta.authors[0].name : 'PortalJS'} | ||
description={meta.description} | ||
/> | ||
); | ||
} | ||
|
||
return Component; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d88a23c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
site-portaljs – ./site
docs-portaljs.vercel.app
site-portaljs-datopian1.vercel.app
site-portaljs-git-main-datopian1.vercel.app
portaljs.org
www.portaljs.org