diff --git a/Lib/Cmd/CleanCmd.php b/Lib/Cmd/CleanCmd.php index 67a57f65039b8bcf684f4e946ad9feef5244f660..6640821216187e73991a77b270df69f9ba0f7efb 100644 --- a/Lib/Cmd/CleanCmd.php +++ b/Lib/Cmd/CleanCmd.php @@ -10,8 +10,12 @@ class CleanCmd implements BaseCmd { public static function handle($argv) { - self::handleRmFilesOfDir(DIST_DIR); - echo "Clean dist path finish\n"; + if (is_dir(DIST_DIR)) { + self::handleRmFilesOfDir(DIST_DIR); + echo "Clean dist path finish\n"; + } else { + echo "Dist path not exist, finish!" . PHP_EOL; + } } public static function handleRmFilesOfDir($path) diff --git a/Lib/Cmd/HelpCmd.php b/Lib/Cmd/HelpCmd.php index 831c1efcc62aeea59035e0e5ee46d5d5f2393bcb..1653c2c785c8a357455514c3506190e88523580f 100644 --- a/Lib/Cmd/HelpCmd.php +++ b/Lib/Cmd/HelpCmd.php @@ -10,29 +10,30 @@ class HelpCmd implements BaseCmd { public static function handle($argv) { - echo " - _ _ - _ __ ___ ___ ___ | |__ | | ___ __ _ -| '_ ` _ \ / _ \/ _ \ | '_ \| |/ _ \ / _` | -| | | | | | __/ (_) | | |_) | | (_) | (_| | -|_| |_| |_|\___|\___/ |_.__/|_|\___/ \__, | - |___/ + echo << -Here are all of commands: +Usage: php hikari \ +Here are main of commands: -- php meo help | h: Get help(just like you now!) -- php meo new \ \: Create a new post -- php meo build | b: Build static files -- php meo serve | s: Start develop server, and check page render when file change -- php meo clean | c: Clean static files and db file +- php hikari help | h: Get help(just like you now!) +- php hikari new \ \: Create a new post +- php hikari build | b: Build static files +- php hikari serve | s: Start develop server, and check page render when file change +- php hikari clean | c: Clean static files and db file -If you want join us, visit https://gitee.com/xtzero/meoBlog. +For others command, you can visit Lib/Cmd folder. + +If you want join us, visit https://gitee.com/xtzero/hikari. Enjoy yourself~ -"; +EOF . PHP_EOL; } } diff --git a/Lib/Cmd/ServeCmd.php b/Lib/Cmd/ServeCmd.php index 68e6ff0bf252459695c0431fb49182d79cd509a6..0511048a814ec59512f3a871ce61def5ab6c1c21 100644 --- a/Lib/Cmd/ServeCmd.php +++ b/Lib/Cmd/ServeCmd.php @@ -11,9 +11,9 @@ class ServeCmd implements BaseCmd { public static function handle($argv) { - echo "Exec php meo b \n\n"; + echo "Exec php hikari b \n\n"; BuildCmd::handle($argv); - echo "Exec php meo s \n\n"; + echo "Exec php hikari s \n\n"; HttpServer::init()->listen(); } } diff --git a/Lib/HttpServer.php b/Lib/HttpServer.php index df3aefb2f7059c6df491bb1dc78e9373814fffa3..dfa300aafd7983237ef9a2d242b106b47ce46371 100644 --- a/Lib/HttpServer.php +++ b/Lib/HttpServer.php @@ -36,7 +36,7 @@ class HttpServer echoLib::echoGreen("Started develop server: http://" . ENV['develop_server_host'] . ":" . self::$port . "\n" - . "You can use 'php meo b' in another terminal to rebuild dist files! \n"); + . "You can use 'php hikari b' in another terminal to rebuild dist files! \n"); while (1) { $msg = socket_accept(self::$socket); diff --git a/Lib/main.php b/Lib/main.php index db3083fbc032fad56b9742eb8b992e0bea09ba0f..3c98afebb2863a1d7d11da7d3692892ee598ffcf 100644 --- a/Lib/main.php +++ b/Lib/main.php @@ -1,6 +1,6 @@ php 7.4 + -> ->composer 1.9.1 + - -接下来开始安装项目。 - -- 访问[github](https://github.com/xtzero/meoBlog)的`main`分支,或[gitee](https://gitee.com/xtzero/meoBlog)的`master`分支,克隆项目到本地。 - -```shell script -$ git clone https://gitee.com/xtzero/meoBlog.git -//或 git clone https://github.com/xtzero/meoBlog.git -``` - -- 使用composer安装依赖。 - -```shell script -$ composer install -vvv -``` - -- 使用`meo`命令生成页面,开启服务。 - -```shell script -$ php meo s - -[Sun Jan 17 20:18:29 2021] PHP 7.4.1 Development Server (http://localhost:8888) started -``` - -- 点击控制台显示的地址,访问页面。 - -http://localhost:8888 - -> 文档约定 -> ->在本文档中,使用`/Volumes/proj/meoBlog`当做项目的根目录。 -> ->在本文档中,`$`表示终端提示符,`$`后是执行的命令,后面的行则是命令执行之后的回显。 -> ->在本文档中,会使用`[name]`来包含一个可选参数,使用``来包含一个必选参数。中间的单词请根据上下文或单词本身的意义来解读。 - -### 新建文章 - -使用`meo`命令可以为你新建文章 - -```shell script -$ php meo new post [post_name] -Create file success: /Volumes/proj/meoBlog/Sources/Posts/template/index.md -``` - -根据控制台输出可见,新建的markdown文档已经生成好了。你可以编辑`/Volumes/proj/meoBlog/Sources/Posts/[post_name]/index.md`来编写新的文章。 - -有关于文章内容的编辑问题,且等介绍完新建页面之后叙述。 - -### 新建页面 - -在`meo-blog`中,页面是独立于文章之外的独立页面,不会显示在文章列表页面中。 - -和新建文章一样,你也可以使用`meo`命令来新建页面。 - -```shell script -$ php meo new page [page_name] -Create file success: /Volumes/proj/meoBlog/Sources/Pages/page1/index.md -``` - -你可以编辑`/Volumes/proj/meoBlog/Sources/Pages/[page_name]/index.md`来编写新页面的内容。 - -### 编写文章和页面内容 - -使用`meo new`命令新建的文章或页面,都会有如下默认内容: -```html - -``` - -这部分叫做文章/页面的**注释部分**,使用html注释语法包含。默认模板只能解析到`title`和`datetime`,如果想要解析更多内容,可以通过重写模板来实现。 - -其中,`[default_title]`会被当成文章/页面标题,显示在内容页的顶部;`[create_datetime]`会被当成文章/页面的新建时间,放在标题下面。 - -对于文章,文章列表页会显示标题和创建日期,并且会按照创建日期排序。 - -除了注释部分,其余都是正文部分。正文支持`markdown`语法,使用[SegmentFault/HyperDown](https://github.com/SegmentFault/HyperDown)进行解析。除此之外,还支持传统的html语法。也就是说你可以在正文部分通过写html标签来实现更多定制功能。 - -### 生成静态页 - -使用如下`meo`命令来生成静态页。 - -```shell script -$ php meo b -... -Clean dist path finish -Load theme from path: /Volumes/proj/meoBlog/Templates/ -... -See at /Volumes/proj/meoBlog/Dist -``` - -生成的静态页内容是项目路径下的`Dist`目录,你可以直接访问文件来查看页面效果。 - -### 访问页面 - -你可以使用`meo`命令来生成静态页并开启php开发服务器来查看页面效果。 - -```shell script -$ php meo s -Started develop server: http://localhost:8888 -You can use 'php meo b' in another terminal to rebuild dist files! -``` - -访问显示的地址,可以查看生成的结果。 - -> `php meo s`命令还未支持实时刷新,但你可以另外开启一个终端,使用`php meo b`来重新生成静态文件。用这种方式不需要重新执行`php meo s`也能看到新的结果。 - -### 发布 - -你可以将`Dist`路径完整复制到服务器目录,或将网站根路径指向`Dist`目录的位置,即可发布你的网站。 - -## 高级 - -### 配置 - -配置文件是`/env.php`,你可以编辑你的个性化配置。 - -|配置项|解释| -|:--:|:--:| -|title|网站主标题| -|subtitle|网站副标题| -|develop_server_host|开发服务地址| -|develop_server_port|开发服务端口| - -在开发中,任何位置都可以通过访问`ENV`来使用`env.php`中的值。例如 - -```php -// 取网站主标题 -$title = ENV['title']; -``` - -### 全局变量 - -全局变量都在`/meo`中定义。`/meo`是一个php文件,为了命令简洁,所以省略了用户名。这样做才可以使用`php meo `来执行操作。 - -|全局变量|解释| -|:--:|:--:| -|ENV|`/env.php`返回的数组| -|THEME_CONFIG|主题配置,通常是`/Templates/_config.php`| -|ROOT_DIR|项目根目录| -|DIST_DIR|静态文件目录,通常是`/Dist`| -|SOURCES_DIR|源文件目录,通常是`/Sources`| -|POST_DIR|文章源文件目录,通常是`/Sources/Pages`| -|PAGE_DIR|页面源文件目录,通常是`/Sources/Pages`| -|THEME_BASE_DIR|模板根目录,通常是`/Templates`| - -### `meo`命令 - -你可以使用`php meo help`来查看所有支持的`meo`命令。 -```shell script -$ php meo h - -Welcome to use meo blog! -This is a blog system written by a white cat's father! - -Usage: php meo \ -Here are all of commands: - -- php meo help | h: Get help(just like you now!) -- php meo new \ \: Create a new post -- php meo build | b: Build static files -- php meo serve | s: Start develop server, and check page render when file change -- php meo clean | c: Clean static files and db file - -If you want join us, visit https://gitee.com/xtzero/meoBlog. - -Enjoy yourself~ -``` - -除此之外,你可以定制自己的`meo`命令来实现一些自定义操作。自定义命令写在`/Cmd`中,一个命令文件以大驼峰命名,需要以`Cmd.php`结尾。类名与文件名相同,而且需要实现`Lib\Base\BaseCmd`接口。例如: - -```php -Template`命名,且类名和文件名相同,且实现自接口`Lib\Base\BaseTemplate`。 - -对于`meo-blog`,默认模板里包含Archives、Index、Page、Post,这四个模板在模板的配置文件`/Templates/_config.php`中配置了渲染顺序,在执行`php meo b`时,`meo`会按照`/Templates/_config.php`中配置的顺序依次调用模板下的`render`方法来执行渲染。 - -如果需要更改渲染逻辑,或是开发新的模板,先在`Templates`里写好渲染逻辑,再在`/Templates/_config.php`中配置渲染顺序即可。 - - -### features - -> 这里写的是一些准备要做的事 +[Gitee](https://gitee.com/xtzero/hikari) diff --git a/Sources/Posts/meomeomeo/index.md b/Sources/Posts/meomeomeo/index.md index b9cfd2262bd80fadca91398cceee8807f7f77652..6fcfde1e27ec0ea25ac369b9c2ae0c3764a8be94 100644 --- a/Sources/Posts/meomeomeo/index.md +++ b/Sources/Posts/meomeomeo/index.md @@ -1,6 +1,6 @@ -欢迎使用meo \ No newline at end of file +欢迎使用hikari \ No newline at end of file diff --git a/Templates/base/ArchiveTemplate.php b/Templates/base/ArchiveTemplate.php index f8a6552deebc20f042558998e08170b6b0c3a691..7d5fa5b840e95396378b138c930b00f6f125ae28 100644 --- a/Templates/base/ArchiveTemplate.php +++ b/Templates/base/ArchiveTemplate.php @@ -60,7 +60,12 @@ class ArchiveTemplate implements BaseTemplate } usort($postsRes, function($a, $b) { - return $a['timestamp'] > $b ['timestamp'] ? -1 : 1; + if (THEME_CONFIG['archivesSort'] == 'desc') { + return $a['timestamp'] > $b ['timestamp'] ? -1 : 1; + } else if (THEME_CONFIG['archivesSort'] == 'asc') { + return $a['timestamp'] < $b ['timestamp'] ? -1 : 1; + } + }); return $postsRes; diff --git a/Templates/base/_config.php b/Templates/base/_config.php index 4729a6f1fa110d566c1d6d255fa2c4af801685ea..db8dec740674e7cfd85dc73dcb99b951d5250a8a 100644 --- a/Templates/base/_config.php +++ b/Templates/base/_config.php @@ -47,5 +47,6 @@ return [ "url" => "/search.html", "title" => "搜索" ] - ] + ], + "archivesSort" => "desc" ]; diff --git a/Templates/base/components/footer b/Templates/base/components/footer index df17aaab4e22053353356dbb5eb6fafa0ee4981d..63cbfb02d58b66d2ba0afa3d9a97ea450dd32b81 100644 --- a/Templates/base/components/footer +++ b/Templates/base/components/footer @@ -10,7 +10,7 @@