mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 04:57:05 +02:00
refactor: better regex & path parsing for metadata (#1492)
* Don't need using `toString` after `path.basename` * Use `parse` instead of `basename+extname`
This commit is contained in:
parent
9a18b7430a
commit
89582c7b7a
1 changed files with 2 additions and 5 deletions
|
@ -143,7 +143,7 @@ function processMetadata(file, refDir) {
|
||||||
const rawContent = result.rawContent;
|
const rawContent = result.rawContent;
|
||||||
|
|
||||||
if (!metadata.id) {
|
if (!metadata.id) {
|
||||||
metadata.id = path.basename(file, path.extname(file));
|
metadata.id = path.parse(file).name;
|
||||||
}
|
}
|
||||||
if (metadata.id.includes('/')) {
|
if (metadata.id.includes('/')) {
|
||||||
throw new Error('Document id cannot include "/".');
|
throw new Error('Document id cannot include "/".');
|
||||||
|
@ -374,10 +374,7 @@ function generateMetadataBlog() {
|
||||||
}
|
}
|
||||||
const metadata = blog.getMetadata(file);
|
const metadata = blog.getMetadata(file);
|
||||||
// Extract, YYYY, MM, DD from the file name
|
// Extract, YYYY, MM, DD from the file name
|
||||||
const filePathDateArr = path
|
const filePathDateArr = path.basename(file).split('-');
|
||||||
.basename(file)
|
|
||||||
.toString()
|
|
||||||
.split('-');
|
|
||||||
metadata.date = new Date(
|
metadata.date = new Date(
|
||||||
`${filePathDateArr[0]}-${filePathDateArr[1]}-${
|
`${filePathDateArr[0]}-${filePathDateArr[1]}-${
|
||||||
filePathDateArr[2]
|
filePathDateArr[2]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue