-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
misc(v2): change blog front matter to snake_case #1989
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @endiliey why is there a hardcoded date 2019-01-01 here? On L53 as well o.o There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not me who put that. Iirc its hardcoded that way by some prevs contributor who added cjk support. He wanted to make it clear that its yyyy-mm-dd and then take the length lol. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just substring(0,9) lol |
||
|
@@ -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,19 +110,19 @@ 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) { | ||
const [, dateString, name] = match; | ||
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(), | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes in this file are just nits.