mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 12:43:05 +00:00
Co-authored-by: Dan Abramov <dan.abramov@me.com> Co-authored-by: Sylwia Vargas <sylwia.vargas@gmail.com> Co-authored-by: Dan Lebowitz <dan.lebo@me.com> Co-authored-by: Razvan Gradinar <grazvan@fb.com> Co-authored-by: Jared Palmer <jared@palmer.net> Co-authored-by: Dane Grant <danecando@gmail.com> Co-authored-by: Dustin Goodman <dustin.s.goodman@gmail.com> Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com> Co-authored-by: Maggie Appleton <maggie.fm.appleton@gmail.com> Co-authored-by: Alex Moldovan <alex.n.moldovan@gmail.com> Co-authored-by: Ives van Hoorne <ives.v.h@gmail.com> Co-authored-by: Brian Vaughn <bvaughn@fb.com>
36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const fm = require('gray-matter');
|
|
const globby = require('globby');
|
|
|
|
/**
|
|
* This script ensures that every file in the docs folder is named corresponding
|
|
* to its respective frontmatter permalink. In the old site, the path of the page was set by
|
|
* the `permalink` in markdown frontmatter, and not the name of the file itself or it's id.
|
|
* In the new Next.js site, with its filesystem router, the name of the file must
|
|
* match exactly to its `permalink`.
|
|
*/
|
|
Promise.resolve()
|
|
.then(async () => {
|
|
const pages = await globby('src/pages/docs/**/*.{md,mdx}');
|
|
for (let sourcePath of pages.sort()) {
|
|
const rawStr = await fs.readFile(sourcePath, 'utf8');
|
|
const {data, content} = fm(rawStr);
|
|
const currentPath = sourcePath
|
|
.replace('src/pages/', '')
|
|
.replace('.md', '');
|
|
const permalink = data.permalink.replace('.html', '');
|
|
if (permalink !== currentPath) {
|
|
const destPath = 'src/pages/' + permalink + '.md';
|
|
try {
|
|
await fs.move(sourcePath, destPath);
|
|
console.log(`MOVED: ${sourcePath} --> ${destPath}`);
|
|
} catch (error) {
|
|
console.error(`ERROR: ${sourcePath} --> ${destPath}`);
|
|
console.error(error);
|
|
}
|
|
}
|
|
}
|
|
})
|
|
.catch(console.error);
|