Welcome to Hexo (opens new window)! 以下内容介绍关于怎么搭建github pages, 以及管理blog文章.

# 安装/初始化使用 hexo

安装node.js和python2.7以及npm

根据官网的指导开始

# 主题的使用

如何下载,拉取主题, 主题的配置使用 遇到使用主题过程的中的一些问题, 主题pages目录没有index.html, 需要手动复制过来.

# 一些关键配置

介绍 deploy到github上的配置 将hexo的代码发布到github上作为另一个项目 配置github pages域名和dns

# 发布文章

两种方式 使用HexoCLient 或者hexo-admin

# hexo 部署github上出现custom domain重置的现象

每次hexo d时, 都会出现此现象

解决办法: 在source文件夹下新建一个CNAME文件, 里面写入你的域名.

# 一些特殊符号在hexo中显示出现问题

比如使用[^_^]:作为注释语法, 在大部分markdown的渲染里都可以, 而hexo却不行

解决办法: hexo默认的渲染引擎(hexo-renderer-marked)的问题, 使用hexo-renderer-markdown-it-plus引擎替换默认就好了. 步骤:

  1. 安装插件
npm un hexo-renderer-marked --save
npm i hexo-renderer-markdown-it-plus --save
npm i markdown-it-katex  --save
  1. 如果文章中未正确渲染(我只走了第一步就正常渲染了), 则在_config.xml中加入如下配置:
markdown_it_plus:
  highlight: true
  html: true
  xhtmlOut: true
  breaks: true
  langPrefix:
  linkify: true
  typographer:
  quotes: “”‘’
  plugins:
    - plugin:
        name: markdown-it-katex
        enable: true
    - plugin:
        name: markdown-it-mark
        enable: false  
  1. 文章如果要启用mathjax, 则在文章中配置:
title: Hello World
mathjax: true

# 使用TOC目录结构显示

  1. 在主题的layout/_partial/post/下新建一个toc.ejs文件, 内容如下:
<div id="toc" class="toc-article">
    <div class="toc-title">目录</div>
    <%- toc(item.content, {list_number: false}) %>
</div>
  1. 找到_partial/article.ejs文件, 在其中添加如下内容:
<div class="article-entry" itemprop="articleBody">
      <% if (post.excerpt && index){ %>
        <%- post.excerpt %>
      <% } else { %>
            <!-- Table of Contents -->
            <% if (!index && post.toc){ %>
              <div id="toc" class="toc-article">
                <strong class="toc-title">文章目录</strong>
                <%- toc(post.content) %>
              </div>
            <% } %>
        <%- post.content %>
      <% } %>
    </div>

上述代码中, 我去掉了if(!index && post.toc)中的第二个条件 因为在生成的md文件中toc属性总是为false, 暂时还没有找到解决办法,因此临时这样解决了问题.

  1. 到source/css/style.css文件中添加如下样式:
.toc-article {
    background: #eee;
    padding: 1em;
    position: relative;
    left:2em;
}

.toc-article .toc-title{
    padding-bottom: 0.8em;
    font-weight: bold;
}

#toc {
    line-height: 1.1em;
    font-size: 0.8em;
    float: right
}

#toc .toc {
    padding: 0
}

#toc li , .toc li {
    list-style-type: none
}

#toc ol {
    margin: 0;
}

#toc .toc-child {
    padding-left: 1.5em
}
修改于: 8/11/2022, 3:17:56 PM