mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-30 09:27:04 +02:00
feat(blog): add LastUpdateAuthor & LastUpdateTime (#9912)
Co-authored-by: OzakIOne <OzakIOne@users.noreply.github.com> Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
7938803747
commit
c745021b01
40 changed files with 833 additions and 359 deletions
|
@ -73,5 +73,7 @@ export const ThemeClassNames = {
|
|||
},
|
||||
blog: {
|
||||
// TODO add other stable classNames here
|
||||
blogFooterTagsRow: 'theme-blog-footer-tags-row',
|
||||
blogFooterEditMetaRow: 'theme-blog-footer-edit-meta-row',
|
||||
},
|
||||
} as const;
|
||||
|
|
|
@ -23,19 +23,23 @@ import type {
|
|||
} from '@docusaurus/plugin-content-blog';
|
||||
import type {DocusaurusConfig} from '@docusaurus/types';
|
||||
|
||||
const convertDate = (dateMs: number) => new Date(dateMs * 1000).toISOString();
|
||||
|
||||
function getBlogPost(
|
||||
blogPostContent: PropBlogPostContent,
|
||||
siteConfig: DocusaurusConfig,
|
||||
withBaseUrl: BaseUrlUtils['withBaseUrl'],
|
||||
) {
|
||||
): BlogPosting {
|
||||
const {assets, frontMatter, metadata} = blogPostContent;
|
||||
const {date, title, description} = metadata;
|
||||
const {date, title, description, lastUpdatedAt} = metadata;
|
||||
|
||||
const image = assets.image ?? frontMatter.image;
|
||||
const keywords = frontMatter.keywords ?? [];
|
||||
|
||||
const blogUrl = `${siteConfig.url}${metadata.permalink}`;
|
||||
|
||||
const dateModified = lastUpdatedAt ? convertDate(lastUpdatedAt) : undefined;
|
||||
|
||||
return {
|
||||
'@type': 'BlogPosting',
|
||||
'@id': blogUrl,
|
||||
|
@ -45,6 +49,7 @@ function getBlogPost(
|
|||
name: title,
|
||||
description,
|
||||
datePublished: date,
|
||||
...(dateModified ? {dateModified} : {}),
|
||||
...getAuthor(metadata.authors),
|
||||
...getImage(image, withBaseUrl, title),
|
||||
...(keywords ? {keywords} : {}),
|
||||
|
@ -108,11 +113,13 @@ export function useBlogPostStructuredData(): WithContext<BlogPosting> {
|
|||
const {siteConfig} = useDocusaurusContext();
|
||||
const {withBaseUrl} = useBaseUrlUtils();
|
||||
|
||||
const {date, title, description, frontMatter} = metadata;
|
||||
const {date, title, description, frontMatter, lastUpdatedAt} = metadata;
|
||||
|
||||
const image = assets.image ?? frontMatter.image;
|
||||
const keywords = frontMatter.keywords ?? [];
|
||||
|
||||
const dateModified = lastUpdatedAt ? convertDate(lastUpdatedAt) : undefined;
|
||||
|
||||
const url = `${siteConfig.url}${metadata.permalink}`;
|
||||
|
||||
// details on structured data support: https://schema.org/BlogPosting
|
||||
|
@ -128,6 +135,7 @@ export function useBlogPostStructuredData(): WithContext<BlogPosting> {
|
|||
name: title,
|
||||
description,
|
||||
datePublished: date,
|
||||
...(dateModified ? {dateModified} : {}),
|
||||
...getAuthor(metadata.authors),
|
||||
...getImage(image, withBaseUrl, title),
|
||||
...(keywords ? {keywords} : {}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue