-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add types to doc.js & relative files
- Loading branch information
Showing
12 changed files
with
359 additions
and
329 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,106 @@ | ||
import React from 'react' | ||
import { Helmet } from 'react-helmet' | ||
import { useLocation } from '@reach/router' | ||
import { useStaticQuery, graphql } from 'gatsby' | ||
import { graphql, useStaticQuery } from 'gatsby' | ||
import { RequiredNonNull } from '../types/common' | ||
import { Article, WithContext } from 'schema-dts' | ||
|
||
interface Props { | ||
interface SEOProps { | ||
title: string; | ||
description: string; | ||
image: string; | ||
article: boolean; | ||
author: string; | ||
tags: string[]; | ||
dateModified: string; | ||
datePublished: string; | ||
image?: string | ||
} | ||
|
||
const SEO: React.FC<Props> = (props: Props) => { | ||
const SEO: React.FC<SEOProps> = (props: SEOProps) => { | ||
const { pathname } = useLocation() | ||
const { site: { siteMetadata } } = useStaticQuery<GatsbyTypes.SEOQuery>(graphql` | ||
query SEO { | ||
site { | ||
siteMetadata { | ||
defaultTitle: title | ||
defaultDescription: description | ||
siteUrl | ||
defaultAuthor: author | ||
} | ||
} | ||
} | ||
`) as RequiredNonNull<GatsbyTypes.SEOQuery> | ||
|
||
const { | ||
title = null, | ||
description = null, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
image = null, | ||
article = false, | ||
author = null, | ||
author = '', | ||
tags = null, | ||
dateModified, | ||
datePublished, | ||
} = props | ||
const { pathname } = useLocation() | ||
const { site } = useStaticQuery<GatsbyTypes.SEOQuery>(query) | ||
|
||
const { | ||
defaultTitle, | ||
defaultDescription, | ||
siteUrl, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
defaultAuthor, | ||
} = site.siteMetadata | ||
|
||
const seo = { | ||
title: title || defaultTitle, | ||
description: description || defaultDescription, | ||
// image: `${siteUrl}${image}`, | ||
title: title || siteMetadata.defaultTitle, | ||
description: description || siteMetadata.defaultDescription, | ||
image: 'https://cdn.jsdelivr.net/npm/[email protected]/wordArt.webp', | ||
url: `${siteUrl}${pathname}`, | ||
url: `${siteMetadata.siteUrl}${pathname}`, | ||
author: author && author.split(','), | ||
tags: tags, | ||
} | ||
|
||
const schemaMarkUp = { | ||
const schemaMarkUp: WithContext<Article> = { | ||
'@context': 'https://schema.org', | ||
'@type': 'Article', | ||
headline: seo.title, | ||
image: ['https://cdn.jsdelivr.net/npm/[email protected]/wordArt.webp'], | ||
image: [seo.image], | ||
datePublished: datePublished, | ||
dateModified: dateModified, | ||
mainEntityOfPage: seo.url, | ||
author: { | ||
'@type': 'Person', | ||
name: author, | ||
}, | ||
publisher: { | ||
'@type': 'Organization', | ||
name: 'OI Wiki', | ||
logo: { | ||
url: 'https://cdn.jsdelivr.net/npm/[email protected]/wordArt.webp', | ||
'@type': 'ImageObject', | ||
url: seo.image, | ||
}, | ||
}, | ||
} | ||
schemaMarkUp['@context'] = 'https://schema.org' | ||
schemaMarkUp['@type'] = 'Article' | ||
schemaMarkUp.author['@type'] = 'Person' | ||
schemaMarkUp.publisher['@type'] = 'Organization' | ||
schemaMarkUp.publisher.logo['@type'] = 'ImageObject' | ||
|
||
|
||
return ( | ||
<Helmet > | ||
<meta name="description" content={seo.description} /> | ||
<meta name="image" content={seo.image} /> | ||
<Helmet> | ||
<meta name="description" content={seo.description}/> | ||
<meta name="image" content={seo.image}/> | ||
|
||
{seo.url && <meta property="og:url" content={seo.url} />} | ||
{seo.url && <meta property="og:url" content={seo.url}/>} | ||
|
||
{article && <meta property="og:type" content="article" />} | ||
{seo.tags && seo.tags.map((tag) => <meta key={tag} property="og:article:tag" content={tag} />)} | ||
{seo.author && seo.author.map((author) => <meta key={author} property="og:article:author" content={author} />)} | ||
{article && <meta property="og:type" content="article"/>} | ||
{seo.tags && seo.tags.map((tag) => <meta key={tag} property="og:article:tag" content={tag}/>)} | ||
{seo.author && seo.author.map((author) => <meta key={author} property="og:article:author" content={author}/>)} | ||
|
||
{seo.title && <meta property="og:title" content={seo.title} />} | ||
{seo.title && <meta property="og:title" content={seo.title}/>} | ||
|
||
{seo.description && <meta property="og:description" content={seo.description} />} | ||
{seo.description && <meta property="og:description" content={seo.description}/>} | ||
|
||
{seo.image && <meta property="og:image" content={seo.image} />} | ||
{seo.image && <meta property="og:image" content={seo.image}/>} | ||
|
||
<meta name="twitter:card" content="summary_large_image" /> | ||
<meta name="twitter:card" content="summary_large_image"/> | ||
|
||
{seo.title && <meta name="twitter:title" content={seo.title} />} | ||
{seo.title && <meta name="twitter:title" content={seo.title}/>} | ||
|
||
{seo.description && ( | ||
<meta name="twitter:description" content={seo.description} /> | ||
)} | ||
{seo.description && <meta name="twitter:description" content={seo.description}/>} | ||
|
||
{seo.image && <meta name="twitter:image" content={seo.image} />} | ||
{seo.image && <meta name="twitter:image" content={seo.image}/>} | ||
{schemaMarkUp && <script type="application/ld+json">{JSON.stringify(schemaMarkUp, null, 2)}</script>} | ||
</Helmet> | ||
) | ||
} | ||
|
||
export default SEO | ||
|
||
const query = graphql` | ||
query SEO { | ||
site { | ||
siteMetadata { | ||
defaultTitle: title | ||
defaultDescription: description | ||
siteUrl | ||
defaultAuthor: author | ||
} | ||
} | ||
} | ||
` |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
import React from 'react' | ||
import reactiveHast, { ReactiveHastComponents, ReactiveHastHtmlAst } from './reactiveHast' | ||
|
||
export interface MDRendererProps { | ||
components: ReactiveHastComponents; | ||
htmlAst: ReactiveHastHtmlAst; | ||
} | ||
|
||
const MDRenderer: React.FC<MDRendererProps> = (props) => { | ||
const { components, htmlAst } = props | ||
return reactiveHast({ | ||
...htmlAst, | ||
tagName: 'div', | ||
}, components ?? {}) as ReturnType<React.FC> | ||
} | ||
|
||
export default React.memo(MDRenderer, () => true) |
Oops, something went wrong.