Skip to content

Commit

Permalink
refactor: add blog microdata in markup intead of use JSON-LD
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Aug 13, 2021
1 parent c76dfb8 commit 347f6fe
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ function BlogLayout(props: Props): JSX.Element {
className={clsx('col', {
'col--7': hasSidebar,
'col--9 col--offset-1': !hasSidebar,
})}>
})}
itemScope
itemType="http://schema.org/Blog">
{children}
</main>
{toc && (
Expand Down
56 changes: 41 additions & 15 deletions packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import clsx from 'clsx';
import {MDXProvider} from '@mdx-js/react';
import Translate, {translate} from '@docusaurus/Translate';
import Link from '@docusaurus/Link';
import {useBaseUrlUtils} from '@docusaurus/useBaseUrl';
import {usePluralForm} from '@docusaurus/theme-common';
import MDXComponents from '@theme/MDXComponents';
import Seo from '@theme/Seo';
Expand Down Expand Up @@ -40,6 +41,7 @@ function useReadingTimePlural() {

function BlogPostItem(props: Props): JSX.Element {
const readingTimePlural = useReadingTimePlural();
const {withBaseUrl} = useBaseUrlUtils();
const {
children,
frontMatter,
Expand Down Expand Up @@ -74,11 +76,19 @@ function BlogPostItem(props: Props): JSX.Element {

return (
<header>
<TitleHeading className={styles.blogPostTitle}>
{isBlogPostPage ? title : <Link to={permalink}>{title}</Link>}
<TitleHeading className={styles.blogPostTitle} itemProp="headline">
{isBlogPostPage ? (
title
) : (
<Link itemProp="url" to={permalink}>
{title}
</Link>
)}
</TitleHeading>
<div className={clsx(styles.blogPostData, 'margin-vert--md')}>
<time dateTime={date}>{formattedDate}</time>
<time dateTime={date} itemProp="datePublished">
{formattedDate}
</time>

{readingTime && (
<>
Expand All @@ -93,16 +103,22 @@ function BlogPostItem(props: Props): JSX.Element {
<img src={authorImageURL} alt={author} />
</Link>
)}
<div className="avatar__intro">
{author && (
<>
<div className="avatar__name">
<Link href={authorURL}>{author}</Link>
</div>
<small className="avatar__subtitle">{authorTitle}</small>
</>
)}
</div>
{author && (
<div
className="avatar__intro"
itemProp="author"
itemScope
itemType="https://schema.org/Person">
<div className="avatar__name">
<Link href={authorURL} itemProp="url">
<span itemProp="name">{author}</span>
</Link>
</div>
<small className="avatar__subtitle" itemProp="description">
{authorTitle}
</small>
</div>
)}
</div>
</header>
);
Expand All @@ -112,9 +128,19 @@ function BlogPostItem(props: Props): JSX.Element {
<>
<Seo {...{keywords, image}} />

<article className={!isBlogPostPage ? 'margin-bottom--xl' : undefined}>
<article
className={!isBlogPostPage ? 'margin-bottom--xl' : undefined}
itemProp="blogPost"
itemScope
itemType="http://schema.org/BlogPosting">
{renderPostHeader()}
<div className="markdown">
{image && (
<meta
itemProp="image"
content={withBaseUrl(image, {absolute: true})}
/>
)}
<div className="markdown" itemProp="articleBody">
<MDXProvider components={MDXComponents}>{children}</MDXProvider>
</div>
{(tags.length > 0 || truncated) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import React from 'react';
import BlogLayout from '@theme/BlogLayout';
import BlogPostItem from '@theme/BlogPostItem';
import BlogPostStructuredData from '@theme/BlogPostStructuredData';
import BlogPostPaginator from '@theme/BlogPostPaginator';
import type {Props} from '@theme/BlogPostPage';
import {ThemeClassNames} from '@docusaurus/theme-common';
Expand All @@ -31,11 +30,6 @@ function BlogPostPage(props: Props): JSX.Element {
? BlogPostContents.toc
: undefined
}>
<BlogPostStructuredData
frontMatter={frontMatter}
frontMatterAssets={frontMatterAssets}
metadata={metadata}
/>
<BlogPostItem
frontMatter={frontMatter}
frontMatterAssets={frontMatterAssets}
Expand Down

This file was deleted.

18 changes: 0 additions & 18 deletions packages/docusaurus-theme-classic/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@ declare module '@theme/BlogPostItem' {
export default BlogPostItem;
}

declare module '@theme/BlogPostStructuredData' {
import type {
FrontMatter,
FrontMatterAssets,
Metadata,
} from '@theme/BlogPostPage';

export type Props = {
readonly frontMatter: FrontMatter;
readonly frontMatterAssets: FrontMatterAssets;
readonly metadata: Metadata;
readonly truncated?: string | boolean;
};

const BlogPostStructuredData: (props: Props) => JSX.Element;
export default BlogPostStructuredData;
}

declare module '@theme/BlogPostPaginator' {
type Item = {readonly title: string; readonly permalink: string};

Expand Down

0 comments on commit 347f6fe

Please sign in to comment.