美文网首页
hugo生成GitHub page博客

hugo生成GitHub page博客

作者: shameyou | 来源:发表于2017-12-03 17:02 被阅读217次

    一直觉得使用hexo太繁琐,使用频率不高的话去记忆相关的命令及步骤实在不划算,直到遇到hugo:命令、步骤的记忆成本相比于hexo实在是低太多。在Windows环境下只需要安装hugo.exe文件,就算完成大半了。这幸福来的太突然……

    零. 什么是hugo

    ugo是一个用Go语言编写的静态网站生成器,它使用起来非常简单,相对于Jekyll复杂的安装设置来说,Hugo仅需要一个二进制文件hugo(hugo.exe)即可轻松用于本地调试和生成静态页面。

    一.如何生成?

    1.下载hugo及基本配置

    1.1 Hugo windows客户端下载
    • Hugo官网下载window客户端,下载后解压指任意目录
    • 下载地址 https://github.com/gohugoio/hugo/releases
    • windows环境变量 path 添加 hugo.exe所在路径
    • 安装配置完命令行输入 hugo --help 会有输出 安装成功
    1.2 生成站点及页面
    • 站点生成命令 hugo new site 文件夹名/路径+文件夹名
    • 例如在git中:
      • $ hugo new site myiste #通过cd命令切换到mysite文件夹
      • $ hugo new site d:/mysite # 在d盘中的mysite文件夹下生成站点

    以下是生成的站点结构,config.toml是站点配置文件

    ▸ archetypes/
    ▸ content/
    ▸ layouts/
    ▸ static/
    config.toml

    • 页面生成命令: hugo new 页面名称,在content文件夹下生成.md内容页

    不过我们一般是在content文件夹下新建post文件夹(方便以后聚合内容)来放置.md内容页 :hugo new post/first.md

    这样我们已经生成了一个站点+一个页面了

    2.配置+下载主题

    • 在根目录下新建themes文件夹
    • 选择喜欢的主题,地址
    • 下载主题,例如mainroad主题: git clone https://themes.gohugo.io/mainroad/
    • 在config.toml中添加`theme: "mainroad"

    3.启动主题

    • hugo server
      在浏览器中输入:localhost:1313 即可查看生成站点
      其他方式:
    • hugo server --theme=hyde --buildDrafts
      --theme=主题名 ,如果是在config.toml文件中指定了,这个地方则不需要
      --buildDrafts 参数的意思是渲染所有的post包括 draft=true状态的

    4.其他配置

    • 在config.toml文件中配置baseUrl参数 baseUrl="https://名字.github.io"

    5.上传部署

    • 生成最终页面: hugo --theme=主题名 --baseUrl=https://名字.github.io
    • 所有静态页面都会生成到 public 目录下,将pubilc目录里所有文件 push 到刚创建的Repository的 master 分支
    • git命令
    $ cd public
    $ git init 
    $ git remote add origin https://github.com/名字/名字.github.io.git
    $ git add -A
    $ git commit -m "提交备注"
    $ git push -u origin master
    

    文章参考来源1:http://www.gohugo.org/
    文章参考来源2:https://gdzhu8023.github.io/post/buildblog/

    二.主题(theme)问题

    相关文章

      网友评论

          本文标题:hugo生成GitHub page博客

          本文链接:https://www.haomeiwen.com/subject/djgabxtx.html