Skip to content

Commit

Permalink
feat(v2): support custom description for blog-only mode (#2359)
Browse files Browse the repository at this point in the history
* feat: support custom description on blog page

resolve conflicts

* feat(v2): allow additional props to pass to route components

resolve conflicts

* Update blogDescription feature

* Update doc for blogDescription

* Remove test blogDescription config

* Fix blogDescription schema validation

* Fix minor errors

Co-authored-by: Xuqian <[email protected]>
  • Loading branch information
zxuqian and zxuqian authored Jul 30, 2020
1 parent 1db3fbb commit 4af25cd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default function pluginContentBlog(
page < numberOfPages - 1
? blogPaginationPermalink(page + 1)
: null,
blogDescription: options.blogDescription,
},
items: blogPosts
.slice(page * postsPerPage, (page + 1) * postsPerPage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const DEFAULT_OPTIONS = {
blogTagsListComponent: '@theme/BlogTagsListPage',
blogPostComponent: '@theme/BlogPostPage',
blogListComponent: '@theme/BlogListPage',
blogDescription: 'Blog',
postsPerPage: 10,
include: ['*.md', '*.mdx'],
routeBasePath: 'blog',
Expand All @@ -42,6 +43,9 @@ export const PluginOptionSchema = Joi.object({
blogTagsPostsComponent: Joi.string().default(
DEFAULT_OPTIONS.blogTagsPostsComponent,
),
blogDescription: Joi.string()
.allow('')
.default(DEFAULT_OPTIONS.blogDescription),
showReadingTime: Joi.bool().default(DEFAULT_OPTIONS.showReadingTime),
remarkPlugins: Joi.array()
.items(
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface PluginOptions {
blogPostComponent: string;
blogTagsListComponent: string;
blogTagsPostsComponent: string;
blogDescription: string;
remarkPlugins: ([Function, object] | Function)[];
rehypePlugins: string[];
truncateMarker: RegExp;
Expand Down Expand Up @@ -67,6 +68,7 @@ export interface BlogPaginatedMetadata {
totalCount: number;
previousPage: string | null;
nextPage: string | null;
blogDescription: string;
}

export interface BlogPaginated {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import BlogPostItem from '@theme/BlogPostItem';
import BlogListPaginator from '@theme/BlogListPaginator';

type Props = {
metadata: {permalink: string; title: string};
metadata: {permalink: string; title: string; blogDescription: string};
items: {content}[];
};

Expand All @@ -24,9 +24,9 @@ function BlogListPage(props: Props): JSX.Element {
} = useDocusaurusContext();
const isBlogOnlyMode = metadata.permalink === '/';
const title = isBlogOnlyMode ? siteTitle : 'Blog';

const {blogDescription} = metadata;
return (
<Layout title={title} description="Blog">
<Layout title={title} description={blogDescription}>
<div className="container margin-vert--lg">
<div className="row">
<main className="col col--8 col--offset-2">
Expand Down
18 changes: 18 additions & 0 deletions website/docs/blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ Don't forget to delete the existing homepage at `./src/pages/index.js` or else t

:::

You can also add meta description to the blog list page for better SEO:

```js {8} title="docusaurus.config.js"
module.exports = {
// ...
presets: [
[
'@docusaurus/preset-classic',
{
blog: {
blogDescription: 'A docusaurus powered blog!',
},
},
],
],
};
```

### Multiple blogs

By default, the classic theme assumes only one blog per website and hence includes only one instance of the blog plugin. If you would like to have multiple blogs on a single website, it's possible too! You can add another blog by specifying another blog plugin in the `plugins` option for `docusaurus.config.js`.
Expand Down
4 changes: 4 additions & 0 deletions website/docs/using-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ module.exports = {
*/
editUrl:
'https://github.com/facebook/docusaurus/edit/master/website/blog/',
/**
* Blog page meta description for better SEO
*/
blogDescription: 'Blog',
/**
* URL route for the blog section of your site.
* *DO NOT* include a trailing slash.
Expand Down

0 comments on commit 4af25cd

Please sign in to comment.