Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): support custom description for blog-only mode #2359

Merged
merged 7 commits into from
Jul 30, 2020
Merged
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
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