From 15e832604c3427c3b4a95cde6cc7a304a150abc9 Mon Sep 17 00:00:00 2001 From: yangshun Date: Wed, 13 Nov 2019 17:03:21 -0800 Subject: [PATCH 1/4] misc(v2): change blog front matter to snake_case --- .../templates/classic/blog/2019-05-28-hola.md | 1 - .../classic/blog/2019-05-29-hello-world.md | 1 - .../classic/blog/2019-05-30-welcome.md | 1 - .../src/blogUtils.ts | 19 ++++++--- .../src/index.ts | 1 + .../src/theme/BlogPostItem/index.js | 41 ++++++++++--------- website/docs/blog.md | 3 +- 7 files changed, 38 insertions(+), 29 deletions(-) diff --git a/packages/docusaurus-init/templates/classic/blog/2019-05-28-hola.md b/packages/docusaurus-init/templates/classic/blog/2019-05-28-hola.md index 94a963faa7ed..0224eb775d04 100644 --- a/packages/docusaurus-init/templates/classic/blog/2019-05-28-hola.md +++ b/packages/docusaurus-init/templates/classic/blog/2019-05-28-hola.md @@ -5,7 +5,6 @@ author: Gao Wei authorTitle: Docusaurus Core Team authorURL: https://github.com/wgao19 authorImageURL: https://avatars1.githubusercontent.com/u/2055384?v=4 -authorTwitter: wgao19 tags: [hola, docusaurus] --- diff --git a/packages/docusaurus-init/templates/classic/blog/2019-05-29-hello-world.md b/packages/docusaurus-init/templates/classic/blog/2019-05-29-hello-world.md index a51747554171..0b784595c9bc 100644 --- a/packages/docusaurus-init/templates/classic/blog/2019-05-29-hello-world.md +++ b/packages/docusaurus-init/templates/classic/blog/2019-05-29-hello-world.md @@ -5,7 +5,6 @@ author: Endilie Yacop Sucipto authorTitle: Maintainer of Docusaurus authorURL: https://github.com/endiliey authorImageURL: https://avatars1.githubusercontent.com/u/17883920?s=460&v=4 -authorTwitter: endiliey tags: [hello, docusaurus] --- diff --git a/packages/docusaurus-init/templates/classic/blog/2019-05-30-welcome.md b/packages/docusaurus-init/templates/classic/blog/2019-05-30-welcome.md index 781a7fae0a03..f75913b2aeb8 100644 --- a/packages/docusaurus-init/templates/classic/blog/2019-05-30-welcome.md +++ b/packages/docusaurus-init/templates/classic/blog/2019-05-30-welcome.md @@ -5,7 +5,6 @@ author: Yangshun Tay authorTitle: Front End Engineer @ Facebook authorURL: https://github.com/yangshun authorImageURL: https://avatars0.githubusercontent.com/u/1315101?s=400&v=4 -authorTwitter: yangshunz tags: [facebook, hello, docusaurus] --- diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index 870f7f007e57..77924ef0d573 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -1,3 +1,10 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + import fs from 'fs-extra'; import globby from 'globby'; import path from 'path'; @@ -11,7 +18,7 @@ export function truncate(fileString: string, truncateMarker: RegExp | string) { } // YYYY-MM-DD-{name}.mdx? -// prefer named capture, but old node version do not support +// prefer named capture, but old Node version does not support. const FILENAME_PATTERN = /^(\d{4}-\d{1,2}-\d{1,2})-?(.*?).mdx?$/; function toUrl({date, link}: DateLink) { @@ -93,7 +100,8 @@ export async function generateBlogPosts( await Promise.all( blogFiles.map(async (relativeSource: string) => { - // Cannot use path.join() as it resolves '../' and removes the '@site'. Let webpack loader resolve it. + // Cannot use path.join() as it resolves '../' and removes the '@site'. + // Let webpack loader resolve it. const source = path.join(blogDir, relativeSource); const aliasedSource = `@site/${path.relative(siteDir, source)}`; const blogFileName = path.basename(relativeSource); @@ -102,7 +110,7 @@ export async function generateBlogPosts( const {frontMatter, excerpt} = parse(fileString); let date; - // extract date and title from filename + // Extract date and title from filename. const match = blogFileName.match(FILENAME_PATTERN); let linkName = blogFileName.replace(/\.mdx?$/, ''); if (match) { @@ -110,11 +118,11 @@ export async function generateBlogPosts( date = new Date(dateString); linkName = name; } - // prefer usedefined date + // Prefer user-defined date. if (frontMatter.date) { date = new Date(frontMatter.date); } - // use file create time for blog + // Use file create time for blog. date = date || (await fs.stat(source)).birthtime; frontMatter.title = frontMatter.title || linkName; @@ -135,6 +143,7 @@ export async function generateBlogPosts( }); }), ); + blogPosts.sort( (a, b) => b.metadata.date.getTime() - a.metadata.date.getTime(), ); diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index a0a45615874e..3e6f31ef48b9 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ + import fs from 'fs-extra'; import _ from 'lodash'; import path from 'path'; diff --git a/packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.js b/packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.js index a6ad05faf57c..5cb13f6e62fa 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.js @@ -14,6 +14,21 @@ import MDXComponents from '@theme/MDXComponents'; import styles from './styles.module.css'; +const MONTHS = [ + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December', +]; + function BlogPostItem(props) { const { children, @@ -23,32 +38,20 @@ function BlogPostItem(props) { isBlogPostPage = false, } = props; const {date, permalink, tags} = metadata; - const {author, authorURL, authorTitle, authorFBID, title} = frontMatter; + const {author, title} = frontMatter; + + const authorURL = frontMatter.author_url || frontMatter.authorURL; + const authorTitle = frontMatter.author_title || frontMatter.authorTitle; + const authorImageURL = + frontMatter.author_image_url || frontMatter.authorImageURL; const renderPostHeader = () => { const TitleHeading = isBlogPostPage ? 'h1' : 'h2'; const match = date.substring(0, 10).split('-'); const year = match[0]; - const month = [ - 'January', - 'February', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'November', - 'December', - ][parseInt(match[1], 10) - 1]; + const month = MONTHS[parseInt(match[1], 10) - 1]; const day = parseInt(match[2], 10); - const authorImageURL = authorFBID - ? `https://graph.facebook.com/${authorFBID}/picture/?height=200&width=200` - : frontMatter.authorImageURL; - return (
Date: Wed, 13 Nov 2019 17:20:59 -0800 Subject: [PATCH 2/4] Fix blog image url --- website-1.x/blog/2017-12-14-introducing-docusaurus.md | 1 + .../blog/2018-04-30-How-I-Converted-Profilo-To-Docusaurus.md | 1 + website-1.x/blog/2018-12-14-Happy-First-Birthday-Slash.md | 1 + 3 files changed, 3 insertions(+) diff --git a/website-1.x/blog/2017-12-14-introducing-docusaurus.md b/website-1.x/blog/2017-12-14-introducing-docusaurus.md index c642d26feed4..40a6ca513ea0 100644 --- a/website-1.x/blog/2017-12-14-introducing-docusaurus.md +++ b/website-1.x/blog/2017-12-14-introducing-docusaurus.md @@ -2,6 +2,7 @@ title: Introducing Docusaurus author: Joel Marcey authorURL: http://twitter.com/JoelMarcey +authorImageURL: https://graph.facebook.com/611217057/picture/?height=200&width=200 authorFBID: 611217057 authorTwitter: JoelMarcey --- diff --git a/website-1.x/blog/2018-04-30-How-I-Converted-Profilo-To-Docusaurus.md b/website-1.x/blog/2018-04-30-How-I-Converted-Profilo-To-Docusaurus.md index bc1af6ec85da..34bbfdd7a0c2 100644 --- a/website-1.x/blog/2018-04-30-How-I-Converted-Profilo-To-Docusaurus.md +++ b/website-1.x/blog/2018-04-30-How-I-Converted-Profilo-To-Docusaurus.md @@ -2,6 +2,7 @@ title: How I Converted Profilo to Docusaurus in Under 2 Hours author: Christine Abernathy authorURL: http://twitter.com/abernathyca +authorImageURL: https://graph.facebook.com/1424840234/picture/?height=200&width=200 authorFBID: 1424840234 authorTwitter: abernathyca tags: [profilo, adoption] diff --git a/website-1.x/blog/2018-12-14-Happy-First-Birthday-Slash.md b/website-1.x/blog/2018-12-14-Happy-First-Birthday-Slash.md index c0b6b8b179a3..496faebe5162 100644 --- a/website-1.x/blog/2018-12-14-Happy-First-Birthday-Slash.md +++ b/website-1.x/blog/2018-12-14-Happy-First-Birthday-Slash.md @@ -3,6 +3,7 @@ title: Happy 1st Birthday Slash! author: Joel Marcey authorTitle: Co-creator of Docusaurus authorURL: https://github.com/JoelMarcey +authorImageURL: https://graph.facebook.com/611217057/picture/?height=200&width=200 authorFBID: 611217057 authorTwitter: JoelMarcey tags: [birth] From 85b5e1f4a5d984e7d9934c98d31ec43e638021b4 Mon Sep 17 00:00:00 2001 From: yangshun Date: Sun, 17 Nov 2019 05:06:46 -0800 Subject: [PATCH 3/4] Add docs for change --- .../templates/classic/blog/2019-05-28-hola.md | 6 +++--- .../classic/blog/2019-05-29-hello-world.md | 6 +++--- .../templates/classic/blog/2019-05-30-welcome.md | 6 +++--- website/docs/blog.md | 13 ++++++++----- website/docs/migrating-from-v1-to-v2.md | 8 ++++++-- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/docusaurus-init/templates/classic/blog/2019-05-28-hola.md b/packages/docusaurus-init/templates/classic/blog/2019-05-28-hola.md index 0224eb775d04..5552da124f7a 100644 --- a/packages/docusaurus-init/templates/classic/blog/2019-05-28-hola.md +++ b/packages/docusaurus-init/templates/classic/blog/2019-05-28-hola.md @@ -2,9 +2,9 @@ id: hola title: Hola author: Gao Wei -authorTitle: Docusaurus Core Team -authorURL: https://github.com/wgao19 -authorImageURL: https://avatars1.githubusercontent.com/u/2055384?v=4 +author_title: Docusaurus Core Team +author_url: https://github.com/wgao19 +author_image_url: https://avatars1.githubusercontent.com/u/2055384?v=4 tags: [hola, docusaurus] --- diff --git a/packages/docusaurus-init/templates/classic/blog/2019-05-29-hello-world.md b/packages/docusaurus-init/templates/classic/blog/2019-05-29-hello-world.md index 0b784595c9bc..3b331939384d 100644 --- a/packages/docusaurus-init/templates/classic/blog/2019-05-29-hello-world.md +++ b/packages/docusaurus-init/templates/classic/blog/2019-05-29-hello-world.md @@ -2,9 +2,9 @@ id: hello-world title: Hello author: Endilie Yacop Sucipto -authorTitle: Maintainer of Docusaurus -authorURL: https://github.com/endiliey -authorImageURL: https://avatars1.githubusercontent.com/u/17883920?s=460&v=4 +author_title: Maintainer of Docusaurus +author_url: https://github.com/endiliey +author_image_url: https://avatars1.githubusercontent.com/u/17883920?s=460&v=4 tags: [hello, docusaurus] --- diff --git a/packages/docusaurus-init/templates/classic/blog/2019-05-30-welcome.md b/packages/docusaurus-init/templates/classic/blog/2019-05-30-welcome.md index f75913b2aeb8..3cb4595faa39 100644 --- a/packages/docusaurus-init/templates/classic/blog/2019-05-30-welcome.md +++ b/packages/docusaurus-init/templates/classic/blog/2019-05-30-welcome.md @@ -2,9 +2,9 @@ id: welcome title: Welcome author: Yangshun Tay -authorTitle: Front End Engineer @ Facebook -authorURL: https://github.com/yangshun -authorImageURL: https://avatars0.githubusercontent.com/u/1315101?s=400&v=4 +author_title: Front End Engineer @ Facebook +author_url: https://github.com/yangshun +author_image_url: https://avatars0.githubusercontent.com/u/1315101?s=400&v=4 tags: [facebook, hello, docusaurus] --- diff --git a/website/docs/blog.md b/website/docs/blog.md index cae86a8324a5..1b84ecdbdff7 100644 --- a/website/docs/blog.md +++ b/website/docs/blog.md @@ -26,9 +26,11 @@ For example, at `my-website/blog/2019-09-05-hello-docusaurus-v2.md`: ```yml --- title: Welcome Docusaurus v2 -author: Dattatreya Tripathy -authorTitle: Contributor of Docusaurus 2 -authorURL: https://github.com/dt97 +author: Joel Marcey +author_title: Co-creator of Docusaurus 1 +author_url: https://github.com/JoelMarcey +author_image_url: https://graph.facebook.com/611217057/picture/?height=200&width=200 +authorURL: https://github.com/JoelMarcey tags: [hello, docusaurus-v2] --- Welcome to this blog. This blog is created with [**Docusaurus 2 alpha**](https://v2.docusaurus.io/). @@ -45,8 +47,9 @@ A whole bunch of exploration to follow. The only required field is `title`; however, we provide options to add author information to your blog post as well along with other options. - `author` - The author name to be displayed. -- `authorURL` - The URL that the author's name will be linked to. This could be a GitHub, Twitter, Facebook account URL, etc. -- `authorImageURL` - The URL to the author's image. +- `author_url` - The URL that the author's name will be linked to. This could be a GitHub, Twitter, Facebook profile URL, etc. +- `author_image_url` - The URL to the author's thumbnail image. +- `author_title` - A description of the author. - `title` - The blog post title. - `tags` - A list of strings to tag to your post. diff --git a/website/docs/migrating-from-v1-to-v2.md b/website/docs/migrating-from-v1-to-v2.md index a2d6d2f00821..fad1520f460c 100644 --- a/website/docs/migrating-from-v1-to-v2.md +++ b/website/docs/migrating-from-v1-to-v2.md @@ -400,9 +400,9 @@ This will copy the current `