loading

Loading

请输入关键字开始搜索
    首页 技术实践网站部署

    【3】代码和主题修改

    分类:网站部署
    字数: (4651)
    阅读: (186)
    0

    本来是参考emlog的开发文档, 直接调用emlog的API接口。但是发现有几个问题,因此借助大模型快速修复了一下,最新的代码已修复,大家可进行下载。

    git clone https://github.com/apostle9891/emlog_modify.git

    1 emlog 问题

    1.1 文章发布

    文章发布发现传入正确的sort_id分类管理并不生效,在include/controller/api_controller.php原因是多了2个空格,在以下:

    124         $logData = [
    125             'title'        => $title,
    126             'content'      => $content,
    127             'excerpt'      => $excerpt,
    128             'author'       => $author_uid,
    129             'sortid'       => $sort_id,
    130             'cover'        => $cover,
    131             'date'         => strtotime($post_date ?: date('Y-m-d H:i:s')),
    132             'hide'         => $draft === 'y' ? 'y' : 'n',
    133             'checked'      => $checked,
    134             'alias'        => $alias,
    135             'top '         => $top,     # top多了空格
    136             'sortop '      => $sortop,  # 多了空格
    137             'allow_remark' => $allow_remark,
    138             'password'     => $password,
    139             'link'         => $link,
    140             'template'     => $template,
    141         ];

    去掉空格可以完成。

    1.2 新增alias别名

    alias别名是很有用的,比如以前我的域名是https://blog.askerlab.com/?post=1,如果文档删除了,对应的链接又重新生成,会不同。而通过在obsidian和后台配置别名,则可以每次链接名称都是一样的,启用链接别名。

    emlog因为有源码,通过大模型分析源码发现其实后台是支持alias别名控制的,所以重新修改了对应的代码,使用git 生成了一个patch,也可以直接通过git clone https://github.com/apostle9891/emlog_modify.git下载所有代码
    可以在对应的emlog的源码中,执行如下操作:

    vim fix_bug.patch

    将如下代码复制进去:

    diff --git a/include/controller/api_controller.php b/include/controller/api_controller.php
    old mode 100644
    new mode 100755
    index 8a6bb1e8..349d205f
    --- a/include/controller/api_controller.php
    +++ b/include/controller/api_controller.php
    @@ -132,8 +132,8 @@ class Api_Controller
                 'hide'         => $draft === 'y' ? 'y' : 'n',
                 'checked'      => $checked,
                 'alias'        => $alias,
    -            'top '         => $top,
    -            'sortop '      => $sortop,
    +            'top'          => $top,
    +            'sortop'       => $sortop,
                 'allow_remark' => $allow_remark,
                 'password'     => $password,
                 'link'         => $link,
    @@ -164,6 +164,13 @@ class Api_Controller
             $tags = strip_tags(Input::postStrVar('tags'));
             $author_uid = Input::postIntVar('author_uid', 1);
             $draft = Input::postStrVar('draft', 'n');
    +        $alias = Input::postStrVar('alias');
    +        $top = Input::postStrVar('top', 'n');
    +        $sortop = Input::postStrVar('sortop', 'n');
    +        $allow_remark = Input::postStrVar('allow_remark', 'n');
    +        $password = Input::postStrVar('password');
    +        $link = Input::postStrVar('link');
    +        $template = Input::postStrVar('template');
             $field_keys = Input::postStrArray('field_keys');
             $field_values = Input::postStrArray('field_values');
    
    @@ -173,19 +180,35 @@ class Api_Controller
                 Output::error('parameter error');
             }
    
    +        // 检查文章别名
    +        if (!preg_match('/^[a-zA-Z0-9_-]+$/', $alias)) {
    +            $alias = '';
    +        }
    +        if (!empty($alias)) {
    +            $logalias_cache = $this->Cache->readCache('logalias');
    +            $alias = $this->Log_Model->checkAlias($alias, $logalias_cache, $id);
    +        }
    +
             if ($this->curUid) {
                 $author_uid = $this->curUid;
             }
    
             $logData = [
    -            'title'   => $title,
    -            'content' => $content,
    -            'excerpt' => $excerpt,
    -            'sortid'  => $sort_id,
    -            'cover'   => $cover,
    -            'author'  => $author_uid,
    -            'date'    => strtotime($post_date ?: date('Y-m-d H:i:s')),
    -            'hide'    => $draft === 'y' ? 'y' : 'n',
    +            'title'        => $title,
    +            'content'      => $content,
    +            'excerpt'      => $excerpt,
    +            'sortid'       => $sort_id,
    +            'cover'        => $cover,
    +            'author'       => $author_uid,
    +            'date'         => strtotime($post_date ?: date('Y-m-d H:i:s')),
    +            'hide'         => $draft === 'y' ? 'y' : 'n',
    +            'alias'        => $alias,
    +            'top'          => $top,
    +            'sortop'       => $sortop,
    +            'allow_remark' => $allow_remark,
    +            'password'     => $password,
    +            'link'         => $link,
    +            'template'     => $template,
             ];
    
             $this->Log_Model->updateLog($logData, $id, $author_uid);
    

    最终打补丁

    # 检查补丁
    git apply --check fix_bug.patch
    # 打补丁
    git apply fix_bug.patch

    2 主题问题

    使用cursor修改了对应代码,支持目录。

    本文发布于2025年10月31日16:04,已经过了58天,若内容或图片失效,请留言反馈
    文章出处: 求索空间
    文章链接: https://blog.askerlab.com/emlog_modify_source
    评论列表:
    empty

    暂无评论