使用GITHUB建立自己的博客

我的第一个个人博客

一直以来都是使用CSDN发布自己的博客,最近学习linux,发现有人使用github建立自己的博客,于是也想尝试一下。

安装Hugo

  1. 二进制安装(推荐:简单、快速)
    到 Hugo Releases 下载对应的操作系统版本的Hugo二进制文件(hugo或者hugo.exe)

Mac下直接使用 Homebrew 安装:

brew install hugo
  1. 源码安装
    源码编译安装,首先安装好依赖的工具:
    Git
    Mercurial
    Go 1.3+ (Go 1.4+ on Windows)
    设置好 GOPATH 环境变量,获取源码并编译:
$ export GOPATH=$HOME/go
$ go get -v github.com/spf13/hugo

源码会下载到 $GOPATH/src 目录,二进制在 $GOPATH/bin/

如果需要更新所有Hugo的依赖库,增加 -u 参数:

$ go get -u -v github.com/spf13/hugo

生成站点
使用Hugo快速生成站点,比如希望生成到 /path/to/site 路径:

$ hugo new site /path/to/site

这样就在 /path/to/site 目录里生成了初始站点,进去目录:

$ cd /path/to/site

站点目录结构:

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

创建文章
创建一个 about 页面:

$ hugo new about.md

about.md 自动生成到了 content/about.md ,打开 about.md 看下:

+++
date = "2015-10-25T08:36:54-07:00"
draft = true
title = "about"

+++

正文内容
内容是 Markdown 格式的,+++ 之间的内容是 TOML 格式的,根据你的喜好,你可以换成 YAML 格式(使用 — 标记)或者 JSON 格式。

创建第一篇文章,放到 post 目录,方便之后生成聚合页面。

$ hugo new post/first.md

打开编辑 post/first.md :

---
date: "2015-10-25T08:36:54-07:00"
title: "first"
 
---

### Hello Hugo

 1. aaa
 1. bbb
 1. ccc

安装皮肤
到 皮肤列表 挑选一个心仪的皮肤,比如你觉得 Hyde 皮肤不错,找到相关的 GitHub 地址,创建目录 themes,在 themes 目录里把皮肤 git clone 下来:

创建 themes 目录

$ cd themes
$ git clone https://github.com/spf13/hyde.git

运行Hugo
在你的站点根目录执行 Hugo 命令进行调试:

$ hugo server --theme=hyde --buildDrafts
(注明:v0.15 版本之后,不再需要使用 --watch 参数了)

浏览器里打开: http://localhost:1313

部署
假设你需要部署在 GitHub Pages 上,首先在GitHub上创建一个Repository,命名为:coderzh.github.io (coderzh替换为你的github用户名)。

在站点根目录执行 Hugo 命令生成最终页面:

$ hugo --theme=hyde --baseUrl="http://coderzh.github.io/"

(注意,以上命令并不会生成草稿页面,如果未生成任何文章,请去掉文章头部的 draft=true 再重新生成。)

如果一切顺利,所有静态页面都会生成到 public 目录,将pubilc目录里所有文件 push 到刚创建的Repository的 master 分支。

$ cd public
$ git init
$ git remote add origin https://github.com/coderzh/coderzh.github.io.git
$ git add -A
$ git commit -m "first commit"
$ git push -u origin master

上面的内容已经可以建一个博客了,但是我之前发布之后,一直看不到主题。

#查看版本
hugo version
#创建一个quickstart项目
hugo new site quickstart
cd quickstart
#增加模板样式
git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
#修改 配置文件制定模板是 ananke
echo 'theme = "ananke"' >> config.toml

#创建一个新博客
hugo new posts/my-first-post.md
#启动服务
hugo server -D

用上诉办法就行
效果如下:
在这里插入图片描述
然后就是创建博客
在这里插入图片描述
使用CSDN的编辑器
将左侧内容全部拷贝
在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值