<?php
/**
- 步子哥的博客 - 算法思维
*/
function findBlogConfig($startDir) {
$dir = $startDir;
$depth = 0;
while ($depth < 10) {
$configPath = $dir . DIRECTORY_SEPARATOR . '_blog' . DIRECTORY_SEPARATOR . 'config.php';
if (file_exists($configPath)) return $configPath;
$parent = dirname($dir);
if ($parent === $dir) break;
$dir = $parent;
$depth++;
}
return null;
}
$configPath = findBlogConfig(DIR);
if (!$configPath) die('无法找到博客配置文件');
require_once $configPath;
$currentDir = DIR;
$dirName = basename($currentDir);
$mdFiles = getMarkdownFiles($currentDir);
$articles = [];
foreach ($mdFiles as $mdFile) {
$mdPath = $currentDir . DIRECTORY_SEPARATOR . $mdFile;
$htmlFile = str_replace('.md', '.html', $mdFile);
$htmlPath = $currentDir . DIRECTORY_SEPARATOR . $htmlFile;
checkAndUpdateHtml($mdPath, $htmlPath);
$title = getTitleFromMarkdown($mdPath);
$articles[] = ['title' => $title, 'link' => $htmlFile];
}
$subDirs = getSubDirectories($currentDir);
$directories = [];
foreach ($subDirs as $dir) {
if ($dir[0] === '_' || $dir[0] === '.') continue;
$directories[] = ['name' => getDirectoryDisplayName($dir), 'link' => $dir . '/index.php'];
}
$pageTitle = getDirectoryDisplayName($dirName);
echo generateIndexHtml($currentDir, $pageTitle, $articles, $directories, '../index.php');