lint/eslint: автоисправление проекта проекта

This commit is contained in:
2026-06-17 19:30:22 +03:00
parent 65eb2ce3cb
commit 1ccb499066
3 changed files with 26 additions and 11 deletions
+14 -3
View File
@@ -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);