linux安装hexo

安装hexo

  • 安装git
  • 安装nodejs
  • 安装brrew(非root用户安装)
    • 安装必要依赖
      sudo apt-get install build-essential procps curl filegit
    • 安装brew
      1
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • 运行它建议的二条命令
    • 验证安装 brew doctor
  • 用brew安装hexo brew install hexo
  • 初始化博客 hexo init myblong
  • 安装next主题 npm install hexo-theme-next@latest
  • 安装一键部署插件 npm install hexo-deployer-git --save

配置hexo

  • 拷贝主题配置文件至博客要目录 cp node_modules/hexo-theme-next/_config.yml _config.next.yml
  • 配置github用户名和邮箱
    • git config --global user.email "you@example.com"
    • git config --global user.name "Your Name"
  • 配置hexo配置文件中的github连接
  • 新建标签页面 hexo new page tags 并配置内容
    1
    2
    3
    title: tags
    date: 2024-07-23 19:10:43
    type: "tags"
  • 新建分类页面 hexo new categories 并配置内容
    1
    2
    3
    title: categories
    date: 2024-07-23 19:10:43
    type: "categories"
  • 配置搜索
    • 安装插件 npm install hexo-generator-searchdb
    • hexo配置文件中添加以下内容
      1
      2
      3
      4
      5
      search:
      path: search.xml
      field: post
      content: true
      format: html
    • next配置文件中修改
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      # Local search
      # Dependencies: https://github.com/next-theme/hexo-generator-searchdb
      local_search:
      enable: true
      # Show top n results per article, show all results by setting to -1
      top_n_per_article: 1
      # Unescape html strings to the readable one.
      unescape: false
      # Preload the search data when the page loads.
      preload: false
  • 配置阅读进度
    • 修改主题配置文件
    • 搜索back2top
      1
      2
      3
      4
      5
      6
      back2top:
      enable: true # 开启 back to top 按钮
      # Back to top in sidebar.
      sidebar: true # true 表示在侧边栏显示,false则在侧下角
      # Scroll percent label in b2t button.
      scrollpercent: true # 开启进度百分比

备份与恢复

  • 备份用的gitee,因为github速度感人,首先生成ssh-key

    1
    ssh-keygen -t rsa -C 'xxxxx@qq.com' -f ~/.ssh/gitee_id_rsa

    输入命令后无脑下一步即可,会生成密钥文件

  • gitee_id_rsa.pubvim打开,把里面的密钥填到Gitee的SSH公钥里

  • 在 ~/.ssh 目录下新建一个config文件,添加如下内容(其中Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径)

    1
    2
    3
    4
    5
    # gitee
    Host gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/gitee_id_rsa
  • 用ssh命令测试

    1
    ssh -T git@gitee.com
  • 在Gitee新建仓库,并勾选readme

  • 获取.git文件夹
    原始的博客文件夹只有.deploy_git,是没有.git文件夹的,于是我们先去~/家目录,把刚刚在gitee创建的hexo备份分支给clone下来。然后剪切出里面的.git文件夹,复制到现在的博客文件夹中。

    1
    git clone git@gitee.com:shuainana/hexo.git
  • 创建.gitignore
    用来在上传时候忽略一些文件,即不上传.gitignore中忽略的文件。有就不用管了,没有的话自己手动添加。

    1
    2
    3
    4
    5
    6
    7
    8
    .DS_Store
    Thumbs.db
    db.json
    *.log
    node_modules/
    public/
    .deploy*/
    1234567

    注意,如果你之前克隆过theme中的主题文件,那么应该把主题文件中的.git文件夹删掉,因为git不能嵌套上传,最好是显示隐藏文件,检查一下有没有,否则上传的时候会出错,导致你的主题文件无法上传,这样你的配置在别的电脑上就用不了了。

  • 备份
    通过如下命令将本地文件备份到Gitee上。
    在hexo博客的根目录下执行

    1
    2
    3
    git add .
    git commit -m "backup" (注:“backup”里面换成你需要,如“first commit”)
    git push -u origin master (注:此操作目的是把本地仓库push到gitee上面,如果没有使用密钥此步骤需要你输入帐号和密码)

    可以回去GITEE去验证一下上传是否成功

  • 日常备份

    1
    2
    3
    4
    5
    6
    hexo c
    git add .
    git commit -m "Backup"
    git push
    hexo g
    hexo d
  • 恢复博客
    首先把本地Hexo博客的基础环境搭好:比如安装git、nodejs、hexo安装…

  • 克隆项目到本地

    1
    2
    git clone https://gitee.com/muzihuaner/hexo.git
    //https://gitee.com/muzihuaner/hexo.git换成你的
  • 恢复博客
    在clone下来的那个文件夹里面执行

    1
    2
    3
    npm install hexo-cli
    npm install
    npm install hexo-deployer-git

    在此不需要执行hexo init这条指令,因为不是从零搭建起新博客。

  • 然后就完成了,你如果想也可以

    1
    2
    3
    hexo clean
    hexo g
    hexo d
  • 相关链接