@knowcode/doc-builder 1.10.1 → 1.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/core-builder.js +16 -10
  2. package/package.json +1 -1
@@ -1361,18 +1361,19 @@ async function buildDocumentation(config) {
1361
1361
  console.log(chalk.green('✅ Copied 404.html for .md link handling'));
1362
1362
  }
1363
1363
 
1364
- // Create index.html from index.html, README.html, or generate default
1364
+ // Create index.html with proper priority: index.md > README.md > auto-generated
1365
1365
  const indexPath = path.join(outputDir, 'index.html');
1366
- const indexSourcePath = path.join(outputDir, 'index.html'); // from index.md
1367
1366
  const readmePath = path.join(outputDir, 'README.html');
1368
-
1367
+ const indexMdPath = path.join(docsDir, 'index.md');
1368
+
1369
1369
  console.log(chalk.blue('\n📄 Checking for index.html creation...'));
1370
1370
  console.log(chalk.gray(` - Output directory: ${outputDir}`));
1371
1371
  console.log(chalk.gray(` - Index path: ${indexPath}`));
1372
1372
  console.log(chalk.gray(` - README path: ${readmePath}`));
1373
+ console.log(chalk.gray(` - index.md exists: ${fs.existsSync(indexMdPath)}`));
1373
1374
  console.log(chalk.gray(` - index.html exists: ${fs.existsSync(indexPath)}`));
1374
1375
  console.log(chalk.gray(` - README.html exists: ${fs.existsSync(readmePath)}`));
1375
-
1376
+
1376
1377
  // List all HTML files in output directory
1377
1378
  if (fs.existsSync(outputDir)) {
1378
1379
  const htmlFiles = fs.readdirSync(outputDir)
@@ -1381,22 +1382,27 @@ async function buildDocumentation(config) {
1381
1382
  } else {
1382
1383
  console.log(chalk.red(` - ERROR: Output directory does not exist!`));
1383
1384
  }
1384
-
1385
+
1385
1386
  // Check if we need to create/replace index.html
1386
1387
  let shouldCreateIndex = false;
1387
-
1388
- if (!fs.existsSync(indexPath)) {
1388
+
1389
+ // Priority 1: If index.md exists, index.html was generated from it - keep it
1390
+ if (fs.existsSync(indexMdPath) && fs.existsSync(indexPath)) {
1391
+ console.log(chalk.gray('â„šī¸ index.md exists - index.html was generated from it, keeping as-is'));
1392
+ shouldCreateIndex = false;
1393
+ } else if (!fs.existsSync(indexPath)) {
1394
+ // Priority 2: No index.html exists, need to create it
1389
1395
  console.log(chalk.yellow('âš ī¸ index.html does not exist, need to create it'));
1390
1396
  shouldCreateIndex = true;
1391
- } else if (fs.existsSync(readmePath)) {
1392
- // If README.html exists, always regenerate index.html from it to ensure current version
1397
+ } else if (fs.existsSync(readmePath) && !fs.existsSync(indexMdPath)) {
1398
+ // Priority 3: README.html exists but no index.md, use README as homepage
1393
1399
  console.log(chalk.blue('â„šī¸ Regenerating index.html from README.html to ensure current version'));
1394
1400
  shouldCreateIndex = true;
1395
1401
  } else {
1396
1402
  // Check if existing index.html is likely a directory listing or outdated
1397
1403
  const indexStats = fs.statSync(indexPath);
1398
1404
  const indexContent = fs.readFileSync(indexPath, 'utf8');
1399
-
1405
+
1400
1406
  // Check if it's a small file (likely directory listing) or contains directory listing markers
1401
1407
  if (indexStats.size < 3000 || indexContent.includes('<title>Documentation</title>') && indexContent.includes('<ul>') && !indexContent.includes('class="navigation"')) {
1402
1408
  console.log(chalk.yellow('âš ī¸ Existing index.html appears to be a directory listing (size: ' + indexStats.size + ' bytes), will replace it'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowcode/doc-builder",
3
- "version": "1.10.1",
3
+ "version": "1.10.2",
4
4
  "description": "Reusable documentation builder for markdown-based sites with Vercel deployment support",
5
5
  "main": "index.js",
6
6
  "bin": {