0%

hexo静态博客搭建及部署

hexo静态博客

博客搭建部署hexo+github.io

安装初始化

1
2
3
npm install -g hexo-cli
hexo init blog
cd blog

创建新博客

1
hexo new title

监视生成静态资源

  • 修改完成前监听,保存自动更新静态资源
    1
    hexo generate -w

启动

  • 另起一个终端,开启服务,一边监视生成静态资源,一边loalhost:4000查看效果
    1
    2
    hexo server
    访问localhost:4000

    部署到git

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    配置_config.yml:
    deploy:
    type: 'git'
    repo: git@github.com:alittlegit/alittlegit.github.io.git
    安装部署工具:
    npm install hexo-deployer-git --save
    执行
    hexo deploy // 不更新则使用下面的命令
    hexo deploy --generate

    hexo generate --deploy

更换主题

  • github搜索hexo theme
    1
    2
    3
    4
    cd source/themes
    git clone https://github.com/theme-next/hexo-theme-next themes/next
    更改配置文件:
    theme: next

hexo-next使用

设置分类

  • next主题, _config.yml中开启相关设置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    menu:
    home: / || home
    #about: /about/ || user
    #tags: /tags/ || tags
    categories: /categories/ || th
    archives: /archives/ || archive
    #schedule: /schedule/ || calendar
    #sitemap: /sitemap.xml || sitemap
    #commonweal: /404/ || heartbeat
  • 按文档说明添加分类页面
    1
    2
    3
    hexo new page categories
    设置type类型
    type: "categories"


markdown图片配置

  • 使用typro+Front Matter
  • 设置typro根目录为typro-root-url: ./,也可以在编辑-图片工具-设置根目录里设置后生成
  • 设置图片插入时复制到指定目录: 自定义 : ./images
  • 根目录在images上一级,便可以得到想要的图片路径: /images/xxx.jpg

博客部署hexo+服务器(非docker和docker)

github+git静态博客

hexo静态博客部署到服务器:hexo+node+webhook

hexo静态博客部署到服务器:hexo+node(docker)+webhook

workflow

  • 本地hexo更新文章==>hexo deploy上传git,更新静态资源==>alittlegit.github.io 文章更新
  • 本地hexo更新文章==>hexo deploy上传git,更新静态资源==>webhook==>服务器git pull==>http://onepiece.suprise.top/ 文章更新
  • 本地hexo更新文章==>hexo deploy上传git,更新静态资源==>webhook==>服务器git pull+”resbulid docker”==>http://onepiece.suprise.top/ 文章更新

其他

  • 服务器/docker/webhook分别使用一个端口,nginx转发,webhook是设置在项目的setting中的
  • 注意docker build的路径,可以指定context,ADD/COPY 文件不能超出context