算法思维系列

<?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');

发表评论

人生梦想 - 关注前沿的计算机技术 acejoy.com 🐾 步子哥の博客 🐾 背多分论坛 🐾 知差(chai)网 🐾 DeepracticeX 社区 🐾 老薛主机 🐾 智柴论坛 🐾