hexo

hexo+github pages 生成个人网站。不知道hexo我还愿意用几年。

估计下次更新就变成使用hugo了,尽管我还没写几篇,等写到100篇的时候换hugo吧

prework

  1. nodejs安装以及相关安装配置
  2. git能登录

hexo

安装

  1. npm i hexo-cli -g
  2. D:\conf\nodejs\node-v20.17.0-win-x64\node-global加入环境变量Path
  3. hexo -v验证

使用

  1. 空文件夹里执行hexo init
  2. hexo g 生成
  3. hexo s 预览网页
  4. 还有个hexo d,但是需要先托管到github再执行。

托管到github

  1. 新建一个名为用户名.github.io的仓库
  2. 在刚刚建好的文件夹里修改_config.yml最后的deploy
    1
    2
    3
    4
    deploy:
    type: git
    repository: git@github.com:用户名/用户名.github.io
    branch: main
  3. 安装git插件npm install hexo-deployer-git --save
  4. 确认git账号登陆了,执行hexo d

域名配置(可选)

  1. 不设置的话可以在https://用户名.github.io/看到整个网站
  2. 仓库-settings-pages,Custom domain填入自己的域名
  3. 域名另外设置一下
  4. /source文件夹里要新建一个CNAME的文件,填上域名

使用

文稿

使用

  1. hexo new draft xxx 生成草稿
  2. 修改后再hexo p xxx转换成post可见
  3. 也可以直接hexo n xxx

模板

对/scaffolds中的md文件修改

主题

默认的landscape

next

  1. 参考主题仓库
  2. 参考主题配置文件
  3. 下载git clone https://github.com/next-theme/hexo-theme-next themes/next
  4. 修改_config.yml文件中更改theme:theme: next

其它配置

显示

  1. 首页里面放的正文太多了:使用<!--more-->,可以直接放在模板里面。
  2. 修改_config.yml:修改author、语言、标题等
  3. 按更新顺序排:修改源目录下,_modules-generator-index.js,改成
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    'use strict';
    var pagination = require('hexo-pagination');
    module.exports = function(locals){
    var config = this.config;
    var posts = locals.posts.sort('-updated'); //修改这里! 原代码为var posts = locals.posts.sort('-date');
    var paginationDir = config.pagination_dir || 'page';

    return pagination('', posts, {
    perPage: config.index_generator.per_page,
    layout: ['index', 'archive'],
    format: paginationDir + '/%d/',
    data: {
    __index: true
    }
    });
    };

bug及解决方案

  1. fatal: Could not read from remote repository.
    1. 挂了梯子
    2. git账号没有配置好
      1. 执行ssh-keygen –t rsa –C "git仓库邮箱",重新生成密钥;
      2. 执行git config --global user.name "git用户名",重新配置本地用户名;
      3. 执行git config --global user.email "git登录邮箱",重新配置本地邮箱;
      4. 之后将生成在C:.ssh文件夹下的id_rsa.pub文件打开后复制到Git仓库设置—SSH配置—Key配置的地方粘贴即可
  2. 尝试hexo d出现ERROR Deployer not found: git:npm install hexo-deployer-git --save

多平台同步source

  1. 新建一个仓库
  2. 把theme.git文件删了,代码推上去(不然非要submodule,有点麻烦,我暂时也不想更新next,先不搞)
  3. 其它设备上写之前先git pull
  4. 但我在其他设备上也只编辑source,不需要生成网页page,其实只要upload source那部分就够了

提示:warning: in the working copy of 'tags/reading/index.html', LF will be replaced by CRLF the next time Git touches it

windows平台的问题

域名不对劲,怎么跳到别的网站了 1. 我记得是阿里云,登录 2. 控制台,域名-解析 3. 需要有两个记录 1. 类型:A;主机记录@;解析线路默认;记录值:ping user.github.io得到的ip地址 2. 类型:CNAME;主机记录www;解析线路默认;记录值:user.github.io

在仓库pages里面设置,说域名已经被占用 https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/verifying-your-custom-domain-for-github-pages 参考这个 In the upper-right corner of any page on GitHub, click your profile picture, then click Settings. 在GitHub上任何页面的右上角,单击您的个人资料图片,然后单击设置。

In the "Code, planning, and automation" section of the sidebar, click Pages. 在侧边栏的“代码、规划和自动化”部分,单击Pages。

On the right, click Add a domain. 在右侧,单击“添加域”。

Under "What domain would you like to add?," enter the domain you wish to verify and select Add domain. 在“您要添加什么域?”下,“输入您要验证的域并选择添加域 按照“添加DNS TXT记录”下的说明使用您的域托管服务创建TXT记录。

然后verify

github pages里面再填一下

完成