hugo搭建个人博客托管到github

一、Mac环境下安装

brew install hugo
hugo version
//Hugo Static Site Generator v0.59.0/extended darwin/amd64 BuildDate: unknown

二、本地创建一个站点目录,(username为你的github账户名)

$ hugo new site username.github.io

可以查看有这些目录:

cd username.github.io
hugo搭建个人博客托管到github_第1张图片
image.png

安装主题

$ cd themes
$ git clone https://github.com/coderzh/hugo-pacman-theme.git --depth=1

这套主题感觉还是不错的,简单清爽的界面 hugo-pacman-theme

hugo搭建个人博客托管到github_第2张图片
image.png

打开 config.toml,做以下的配置

BaseURL = "https://username.github.io/blog"
LanguageCode = "zh-CN"
HasCJKLanguage = true
Title = "个人博客"
Theme = "hugo-pacman-theme"
pygmentsStyle = "default"
pygmentsUseClasses = true

[Author]
 Name = "username"

[outputs]
 home = [ "RSS", "HTML" ]

[outputFormats] 
 [outputFormats.RSS]
   mediatype = "application/rss"
   baseName = "feed"

[Params]

 BottomIntroduce = "个人微信"
 Subtitle = "Talk is cheap,show me code."
 Imglogo = "img/logo.jpg"
 AuthorImg = "img/wechat.jpg"
 DateFormat = "2019年10月24日"
 MonthFormat = "2019年10月"
 FancyBox = false

 [Params.Disqus]
   ShortName = "helloworld"

 [Params.Strings]
   Search = "搜索"
   PageNotFound = "你访问的页面不存在"
   ShowSideBar = "显示侧边栏"
   HideSideBar = "隐藏侧边栏"
   Categories = "分类"
   Archive = "归档"
   Tags = "标签"
   Rss = "RSS 订阅"
   TableOfContents = "文章目录"

[Menu]
 [[Menu.Main]]
   Name = "首页"
   URL = "/"
   Weight = 1
 [[Menu.Main]]
   Name = "关于"
   URL = "/about"
   Weight = 2

素材可以放在:

static
└── img
    ├── logo.jpg
    └── wechat.jpg

修改archetypes下面default.md

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: false
toc: false
categories: ["技术"]
tags: []
---

创建文章:

$ hugo new post/first.md

生成静态博客并在本地查看

hugo server

你的博客就可以在本地跑起来了,访问http://127.0.0.1:1313/你可以看到内容。

三、将本地的个人博客托管到github上面

1.首先需要生成public目录

$ hugo --baseUrl ="https://username.github.io/blog/"

2.github下面创建blog仓库,配置Github Pages


hugo搭建个人博客托管到github_第3张图片
image.png

hugo搭建个人博客托管到github_第4张图片
image.png

3.将public目录下面代码上传的你的github的blog仓库下:

git remote add origin https://github.com/username/blog.git
git add -A
git commit -m "first commit"
git push -u origin master

等待一会儿,在浏览其中访问:
https://username.github.io/blog

你可能感兴趣的:(hugo搭建个人博客托管到github)