Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ exports[`blog plugin > process blog posts load content 2`] = `
"url": "https://sebastienlorber.com",
},
],
"createdAt": undefined,
"createdBy": undefined,
"date": 2020-08-15T00:00:00.000Z,
"description": "simple url slug",
"editUrl": "https://baseEditUrl.com/edit/blog/another-simple-slug-with-tags.md",
Expand Down Expand Up @@ -169,6 +171,8 @@ exports[`blog plugin > process blog posts load content 2`] = `
"id": "/another/tags",
"metadata": {
"authors": [],
"createdAt": undefined,
"createdBy": undefined,
"date": 2020-08-15T00:00:00.000Z,
"description": "with tag",
"editUrl": "https://baseEditUrl.com/edit/blog/another-with-tags.md",
Expand Down Expand Up @@ -218,6 +222,8 @@ exports[`blog plugin > process blog posts load content 2`] = `
"id": "/another/tags2",
"metadata": {
"authors": [],
"createdAt": undefined,
"createdBy": undefined,
"date": 2020-08-15T00:00:00.000Z,
"description": "with tag",
"editUrl": "https://baseEditUrl.com/edit/blog/another-with-tags2.md",
Expand Down
10 changes: 10 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
isUnlisted,
isDraft,
readLastUpdateData,
readCreationData,
normalizeTags,
aliasedSitePathToRelativePath,
} from '@docusaurus/utils';
Expand Down Expand Up @@ -260,6 +261,13 @@ async function processBlogSourceFile(
vcs,
);

const creation = await readCreationData(
blogSourceAbsolute,
options,
frontMatter.created_at,
vcs,
);

const draft = isDraft({frontMatter});
const unlisted = isUnlisted({frontMatter});

Expand Down Expand Up @@ -379,6 +387,8 @@ async function processBlogSourceFile(
unlisted,
lastUpdatedAt: lastUpdate.lastUpdatedAt,
lastUpdatedBy: lastUpdate.lastUpdatedBy,
createdAt: creation.createdAt,
createdBy: creation.createdBy,
},
content,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/frontMatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {
ContentVisibilitySchema,
FrontMatterLastUpdateSchema,
FrontMatterCreationSchema,
FrontMatterTOCHeadingLevels,
FrontMatterTagsSchema,
JoiFrontMatter as Joi, // Custom instance for front matter
Expand Down Expand Up @@ -76,6 +77,7 @@ const BlogFrontMatterSchema = Joi.object<BlogPostFrontMatter>({

...FrontMatterTOCHeadingLevels,
last_update: FrontMatterLastUpdateSchema,
created_at: FrontMatterCreationSchema,
})
.messages({
'deprecate.error':
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export const DEFAULT_OPTIONS: PluginOptions = {
sortPosts: 'descending',
showLastUpdateTime: false,
showLastUpdateAuthor: false,
showCreatedTime: false,
showCreatedBy: false,
processBlogPosts: async () => undefined,
tags: undefined,
authorsBasePath: 'authors',
Expand Down Expand Up @@ -227,6 +229,8 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
showLastUpdateAuthor: Joi.bool().default(
DEFAULT_OPTIONS.showLastUpdateAuthor,
),
showCreatedTime: Joi.bool().default(DEFAULT_OPTIONS.showCreatedTime),
showCreatedBy: Joi.bool().default(DEFAULT_OPTIONS.showCreatedBy),
processBlogPosts: Joi.function()
.optional()
.default(() => DEFAULT_OPTIONS.processBlogPosts),
Expand Down
119 changes: 64 additions & 55 deletions packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ declare module '@docusaurus/plugin-content-blog' {
FrontMatterTag,
TagMetadata,
LastUpdateData,
CreationData,
FrontMatterLastUpdate,
FrontMatterCreation,
TagsPluginOptions,
} from '@docusaurus/utils';
import type {
Expand Down Expand Up @@ -236,6 +238,8 @@ declare module '@docusaurus/plugin-content-blog' {
toc_max_heading_level?: number;
/** Allows overriding the last updated author and/or date. */
last_update?: FrontMatterLastUpdate;
/** Allows overriding the creation author and/or date. */
created_at?: FrontMatterCreation;
};

export type BlogPostFrontMatterAuthor = AuthorAttributes & {
Expand All @@ -260,61 +264,62 @@ declare module '@docusaurus/plugin-content-blog' {
| BlogPostFrontMatterAuthor
| (string | BlogPostFrontMatterAuthor)[];

export type BlogPostMetadata = LastUpdateData & {
/** Path to the Markdown source, with `@site` alias. */
readonly source: string;
/**
* Used to generate the page h1 heading, tab title, and pagination title.
*/
readonly title: string;
/**
* The publish date of the post. On client side, this will be serialized
* into a string.
*/
readonly date: Date;
/** Full link including base URL. */
readonly permalink: string;
/**
* Description used in the meta. Could be an empty string (empty content)
*/
readonly description: string;
/**
* Absolute URL to the editing page of the post. Undefined if the post
* shouldn't be edited.
*/
readonly editUrl?: string;
/**
* Reading time in minutes calculated based on word count.
*/
readonly readingTime?: number;
/**
* Whether the truncate marker exists in the post's content.
*/
readonly hasTruncateMarker: boolean;
/**
* Used in pagination. Generated after the other metadata, so not readonly.
* Content is just a subset of another post's metadata.
*/
nextItem?: {readonly title: string; readonly permalink: string};
/**
* Used in pagination. Generated after the other metadata, so not readonly.
* Content is just a subset of another post's metadata.
*/
prevItem?: {readonly title: string; readonly permalink: string};
/**
* Author metadata, normalized. Should be used in joint with
* `assets.authorsImageUrls` on client side.
*/
readonly authors: Author[];
/** Front matter, as-is. */
readonly frontMatter: BlogPostFrontMatter & {[key: string]: unknown};
/** Tags, normalized. */
readonly tags: TagMetadata[];
/**
* Marks the post as unlisted and visibly hides it unless directly accessed.
*/
readonly unlisted: boolean;
};
export type BlogPostMetadata = LastUpdateData &
CreationData & {
/** Path to the Markdown source, with `@site` alias. */
readonly source: string;
/**
* Used to generate the page h1 heading, tab title, and pagination title.
*/
readonly title: string;
/**
* The publish date of the post. On client side, this will be serialized
* into a string.
*/
readonly date: Date;
/** Full link including base URL. */
readonly permalink: string;
/**
* Description used in the meta. Could be an empty string (empty content)
*/
readonly description: string;
/**
* Absolute URL to the editing page of the post. Undefined if the post
* shouldn't be edited.
*/
readonly editUrl?: string;
/**
* Reading time in minutes calculated based on word count.
*/
readonly readingTime?: number;
/**
* Whether the truncate marker exists in the post's content.
*/
readonly hasTruncateMarker: boolean;
/**
* Used in pagination. Generated after the other metadata, so not readonly.
* Content is just a subset of another post's metadata.
*/
nextItem?: {readonly title: string; readonly permalink: string};
/**
* Used in pagination. Generated after the other metadata, so not readonly.
* Content is just a subset of another post's metadata.
*/
prevItem?: {readonly title: string; readonly permalink: string};
/**
* Author metadata, normalized. Should be used in joint with
* `assets.authorsImageUrls` on client side.
*/
readonly authors: Author[];
/** Front matter, as-is. */
readonly frontMatter: BlogPostFrontMatter & {[key: string]: unknown};
/** Tags, normalized. */
readonly tags: TagMetadata[];
/**
* Marks the post as unlisted and visibly hides it unless directly accessed.
*/
readonly unlisted: boolean;
};
/**
* @returns The edit URL that's directly plugged into metadata.
*/
Expand Down Expand Up @@ -524,6 +529,10 @@ declare module '@docusaurus/plugin-content-blog' {
showLastUpdateTime: boolean;
/** Whether to display the author who last updated the blog post. */
showLastUpdateAuthor: boolean;
/** Whether to display the creation date of the blog post. */
showCreatedTime: boolean;
/** Whether to display the author who created the blog post. */
showCreatedBy: boolean;
/** An optional function which can be used to transform blog posts
* (filter, modify, delete, etc...).
*/
Expand Down
Loading