lint/eslint: автоисправление проекта проекта
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
/* eslint-disable no-console -- logs required */
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
@@ -10,16 +12,25 @@ pinIndexToTop();
|
||||
*/
|
||||
function pinIndexToTop() {
|
||||
const indexPath = path.join(docsDir, 'index.md');
|
||||
if (!fs.existsSync(indexPath)) return;
|
||||
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let content = fs.readFileSync(indexPath, 'utf8');
|
||||
|
||||
if (content.startsWith('---\n')) {
|
||||
const endIdx = content.indexOf('\n---\n', 4);
|
||||
if (endIdx === -1) return;
|
||||
|
||||
if (endIdx === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const frontMatter = content.slice(4, endIdx);
|
||||
if (/^sidebar_position\s*:/m.test(frontMatter)) return;
|
||||
|
||||
if (/^sidebar_position\s*:/m.test(frontMatter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
content =
|
||||
'---\nsidebar_position: 0\n' + frontMatter + '\n---\n' + content.slice(endIdx + 5);
|
||||
|
||||
Reference in New Issue
Block a user