基于hexo的博客搭建


<!-- more -->

1安装nodejs

  1. Hexo是基于nodeJS编写的,所以需要安装一下nodeJs和里面的npm工具。

    windows:nodejs选择LTS版本就行了。

    Mac:nodejs选择LTS版本就行了。

  2. 网址

  https://nodejs.org/en/download/
  1. 打开终端检查

    windows:win+R,cmd进入

    Mac: command+空格,进入输入终端(terminal),进入root用户,输入sudo su

  2. 查看node版本和包管理器版本

    windows / Mac:

  node -v
npm -v

 

2安装hexo博客框架

  1. 由于国内镜像源速度慢,这里先安装淘宝的镜像源

    npm install -g cnpm --registry=https://registry.npm.taobao.org

    检查版本

    windows /Mac:

    cnpm -v
  2. 安装博客框架

    windows / Mac:

    npm install -g hexo-cli

    检查版本

    windows / Mac:

    hexo -v

 

 

3建立一个文件夹

  1. 可以在终端里建也可以直接去目标盘建,下面在终端里建

    windows / Mac:

    mkdir blog

    这时你的目标盘文件夹就生产了blog文件夹,下面操作基本都在blog文件夹里

    进入blog

    windows / Mac:

    cd blog

    接下来初始化一下hexo博客

    windows / Mac:

    sudo hexo init   #windows去掉sudo
  2. 启动博客

    windows / Mac:

    hexo s

    打开hexo的服务,在浏览器输入localhost:4000就可以看到你生成的博客了,现在就完成了博客在本地的使用。

 

 

 

4生成SSH添加到GitHub

  1. 回到你的git bash中

    git config --global user.name "你的GitHub用户名"
    git config --global user.email "你的GitHub的邮箱"

    然后创建SSH,一路回车

    ssh-keygen -t rsa -C "youremail"

    这个时候它会告诉你已经生成了.ssh的文件夹。在你的电脑中找到这个文件夹。

    有三个文件夹

    id_rsa
    id_rsa.pub
    known-hosts

    然后在GitHub的setting中,找到SSH keys的设置选项,点击New SSH key 把你的id_rsa.pub里面的信息复制进去

 

 

 

5将博客部署到GitHub上

  1. 创建登录GitHub,新建仓库

    GitHub.com
  2. 去终端blog目录下安装插件

    windows / Mac:

    cnpm install --save hexo-deployer-git
  3. 打开blog文件夹下_config.yml文件夹更改最后几行

    # Deployment
    ## Docs: https://hexo.io/docs/one-command-deployment
    deploy:
    type: 'git' #冒号后有空格
    repo: https://github.com/wxxzjl/wxxzjl.github.io.git #冒号后有空格
    branch: master #冒号后有空格
  4. 然后输入

    hexo clean
    hexo g
    hexo s
    hexo d

    输入账号密码

    如果不可以输入密码就在git bash命令窗口输入

    git config --global user.name "你的GitHub用户名"
    git config --global user.email "你的GitHub邮箱"
  5. 推送完毕就可以在http://yourname.github.io 这个网站看到你的博客了

 

6安装主题

  1. 以下为yilia主题为例介绍如何安装主题

  2. 打开终端到blog目录下

    git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia
  3. 打开blog文件夹下_config.yml文件夹更改主题

    # Extensions
    ## Plugins: https://hexo.io/plugins/
    ## Themes: https://hexo.io/themes/
    theme: yilia
  4. 然后输入

    hexo clean
    hexo g
    hexo s
    hexo d
  5. 刷新一下主题就改变了,文章就这样结束了。

     

     

     

     

     

     

     

     

     

     

  6.  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2023-01-02 20:48  张彧520  阅读(44)  评论(0)    收藏  举报