mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 11:36:53 +02:00
feat(v2): blog slug frontmatter (#3284)
This commit is contained in:
parent
0f357606cd
commit
3ea2f8cfde
16 changed files with 107 additions and 27 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
import fs from 'fs-extra';
|
||||
import globby from 'globby';
|
||||
import chalk from 'chalk';
|
||||
import path from 'path';
|
||||
import readingTime from 'reading-time';
|
||||
import {Feed} from 'feed';
|
||||
|
@ -126,6 +127,14 @@ export async function generateBlogPosts(
|
|||
return;
|
||||
}
|
||||
|
||||
if (frontMatter.id) {
|
||||
console.warn(
|
||||
chalk.yellow(
|
||||
`${blogFileName} - 'id' header option is deprecated. Please use 'slug' option instead.`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
let date;
|
||||
// Extract date and title from filename.
|
||||
const match = blogFileName.match(FILENAME_PATTERN);
|
||||
|
@ -144,16 +153,15 @@ export async function generateBlogPosts(
|
|||
|
||||
// Use file create time for blog.
|
||||
date = date || (await fs.stat(source)).birthtime;
|
||||
|
||||
const slug =
|
||||
frontMatter.slug || (match ? toUrl({date, link: linkName}) : linkName);
|
||||
frontMatter.title = frontMatter.title || linkName;
|
||||
|
||||
blogPosts.push({
|
||||
id: frontMatter.id || frontMatter.title,
|
||||
id: frontMatter.slug || frontMatter.title,
|
||||
metadata: {
|
||||
permalink: normalizeUrl([
|
||||
baseUrl,
|
||||
routeBasePath,
|
||||
frontMatter.id || toUrl({date, link: linkName}),
|
||||
]),
|
||||
permalink: normalizeUrl([baseUrl, routeBasePath, slug]),
|
||||
editUrl: editBlogUrl,
|
||||
source: aliasedSource,
|
||||
description: frontMatter.description || excerpt,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue