Skip to content

Commit

Permalink
add static html file generator
Browse files Browse the repository at this point in the history
  • Loading branch information
josark2005 committed Dec 21, 2019
1 parent 8377fc9 commit 55e3567
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .own_conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# 名称(标题)
NAV_NAME="MY Navigation"
NAV_NAME="OWN Navigation"

# 子标题
NAV_SUBTITLE="我的导航"
Expand All @@ -17,8 +17,8 @@ NAV_KEYWORDS="轻量级导航,动态导航,导航,自动导航,在线导航,导
NAV_DESCRIPTION="一个轻量级自动根据目录动态生成导航的PHP程序"

# 欢迎词
NAV_WELCOME_TITLE="MY Navigation"
NAV_WELCOME_CONTENT="MY Navigation,一个轻量级自动根据目录动态生成导航的PHP程序"
NAV_WELCOME_TITLE="OWN Navigation"
NAV_WELCOME_CONTENT="OWN Navigation,一个轻量级自动根据目录动态生成导航的PHP程序"

# 尝试读取独立配置(默认YES)
NAV_TRY_READ_CONF=YES
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MY Navigation
# OWN Navigation

[![](https://data.jsdelivr.com/v1/package/gh/jokin1999/my-navigation/badge)](https://www.jsdelivr.com/package/gh/jokin1999/my-navigation)

Expand Down Expand Up @@ -65,9 +65,9 @@ cp ./.own_navi.example ./[your_subfolder]/.own_navi
php nav.php [COMMAND]
dc 下载配置文件
dces 下载子目录的配置文件
static 在根目录生成静态的 index.html 文件
```


## 鸣谢

界面借鉴:[MikuTools](https://github.com/Ice-Hazymoon/MikuTools)
Expand Down
24 changes: 20 additions & 4 deletions nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
// 命令行模式
if (IS_CLI) {
$method = $argv[1] ?? null;
if ($method == null || $method == 'help') {
define('METHOD', $method);
if (METHOD == null || METHOD == 'help') {
echo 'php '.basename(__FILE__).' [COMMAND]'.PHP_EOL;
echo ' dc download default configuration file for navigation'.PHP_EOL;
echo ' dces download default configuration file for each subfolder of navigation'.PHP_EOL;
Expand All @@ -48,7 +49,7 @@
}

// download config
if ($method == 'dc') {
if (METHOD == 'dc') {
// 检查文件是否可写
if (!is_writable('./')) {
exit('目录'. __DIR__ .'无法写入文件');
Expand All @@ -64,7 +65,7 @@
}

// download config of each subfolder
if ($method == 'dces') {
if (METHOD == 'dces') {
// 检查文件是否可写
if (!is_writable('./')) {
exit('目录'. __DIR__ .'无法写入文件');
Expand All @@ -78,6 +79,8 @@
exit('获取默认配置文件失败,请稍候再试...');
}
}
}else{
define('METHOD', NULL);
}

// 获取合法目录
Expand Down Expand Up @@ -206,7 +209,13 @@ function ec(string $key) {
echo c($key);
}
?>
<?php if(!IS_CLI): ?>
<?php if(!IS_CLI || METHOD === 'static'): ?>
<?php
// 缓冲区处理
if (METHOD === 'static') {
ob_start();
}
?>
<!doctype html>
<html lang="zh-cn">
<head data-n-head="">
Expand Down Expand Up @@ -314,3 +323,10 @@ class="nya-btn <?php echo $value['mark'] ?? ''; ?> badge"
</body>
</html>
<?php endif; ?>
<?php
if (METHOD === 'static') {
$content = ob_get_contents();
file_put_contents('./index.html', $content);
ob_clean();
}
?>

0 comments on commit 55e3567

Please sign in to comment.