mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-14 00:32:47 +02:00
fix(migrate): do not modify non-MD files (#6146)
* fix(migrate): do not modify non-MD files * Little refactor
This commit is contained in:
parent
9d95d786fa
commit
cc0a439e12
1 changed files with 16 additions and 12 deletions
|
@ -513,11 +513,13 @@ function migrateVersionedDocs(
|
|||
});
|
||||
const files = walk(path.join(newDir, 'versioned_docs'));
|
||||
files.forEach((pathToFile) => {
|
||||
const content = fs.readFileSync(pathToFile).toString();
|
||||
fs.writeFileSync(
|
||||
pathToFile,
|
||||
sanitizedFileContent(content.replace(versionRegex, ''), migrateMDFiles),
|
||||
);
|
||||
if (path.extname(pathToFile) === '.md') {
|
||||
const content = fs.readFileSync(pathToFile).toString();
|
||||
fs.writeFileSync(
|
||||
pathToFile,
|
||||
sanitizedFileContent(content.replace(versionRegex, ''), migrateMDFiles),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -696,8 +698,10 @@ function migrateLatestDocs(
|
|||
);
|
||||
const files = walk(path.join(siteDir, '..', 'docs'));
|
||||
files.forEach((file) => {
|
||||
const content = String(fs.readFileSync(file));
|
||||
fs.writeFileSync(file, sanitizedFileContent(content, migrateMDFiles));
|
||||
if (path.extname(file) === '.md') {
|
||||
const content = fs.readFileSync(file).toString();
|
||||
fs.writeFileSync(file, sanitizedFileContent(content, migrateMDFiles));
|
||||
}
|
||||
});
|
||||
logger.success('Migrated docs to version 2');
|
||||
} else {
|
||||
|
@ -749,11 +753,11 @@ export async function migrateMDToMDX(
|
|||
fs.mkdirpSync(newDir);
|
||||
fs.copySync(siteDir, newDir);
|
||||
const files = walk(newDir);
|
||||
files.forEach((file) => {
|
||||
fs.writeFileSync(
|
||||
file,
|
||||
sanitizedFileContent(String(fs.readFileSync(file)), true),
|
||||
);
|
||||
files.forEach((filePath) => {
|
||||
if (path.extname(filePath) === '.md') {
|
||||
const content = fs.readFileSync(filePath).toString();
|
||||
fs.writeFileSync(filePath, sanitizedFileContent(content, true));
|
||||
}
|
||||
});
|
||||
logger.success`Successfully migrated path=${siteDir} to path=${newDir}`;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue