使用Hugo/Github搭建Commcocoa网站

事先准备

安装Hugo

在Windows上安装Hugo,直接在Github上下载hugo.exe,需注意修改环境变量,安装完成后查询hugo help若反馈如下则表明安装成功.

	$ hugo help
	hugo is the main command, used to build your Hugo site.

	Hugo is a Fast and Flexible Static Site Generator
	built with love by spf13 and friends in Go.

	Complete documentation is available at http://gohugo.io/.

安装Git(非必要)

在Windows上安装Git,若产生Git Bash则安装成功.

安装Notepad++(非必要)

在Windows上安装Notepad++,用于编辑网页,VIM将在Linux环境下使用而NPP将在Windows下使用.

注意: 透过使用*Hugo new XXX.md*生成的markdown文件是ANSI编码,需要转换为UTF-8编码才能正确显示中文字符.

新建网站

按照Hugo官网Quick Start的instruction下新建网站.

  • 前往安装目录,新建Commcocoa:
	$ hugo new site commcocoa
	Congratulations! Your new Hugo site is created in E:\XX\Commcocoa                .

	Just a few more steps and you're ready to go:

	1. Download a theme into the same-named folder.
	   Choose a theme from https://themes.gohugo.io/, or
	   create your own with the "hugo new theme <THEMENAME>" command.
	2. Perhaps you want to add some content. You can add single files
	   with "hugo new <SECTIONNAME>\<FILENAME>.<FORMAT>".
	3. Start the built-in live server via "hugo server".

	Visit https://gohugo.io/ for quickstart guide and full documentation.
  • 查询Commcocoa下自动生成的文件内容:
	$ ls -al
	total 5
	drwxr-xr-x 1 Ryan Shu 197121  0 Jan 17 14:42 ./
	drwxr-xr-x 1 Ryan Shu 197121  0 Jan 17 14:42 ../
	drwxr-xr-x 1 Ryan Shu 197121  0 Jan 17 14:42 archetypes/
	-rw-r--r-- 1 Ryan Shu 197121 82 Jan 17 14:42 config.toml
	drwxr-xr-x 1 Ryan Shu 197121  0 Jan 17 14:42 content/
	drwxr-xr-x 1 Ryan Shu 197121  0 Jan 17 14:42 data/
	drwxr-xr-x 1 Ryan Shu 197121  0 Jan 17 14:42 layouts/
	drwxr-xr-x 1 Ryan Shu 197121  0 Jan 17 14:42 static/
	drwxr-xr-x 1 Ryan Shu 197121  0 Jan 17 14:42 themes/
  • 下载主题,使用事先选定的主题Icarus 如果没有主题则会出现build error. 下载方式可使用Git,如下:
	$ cd themes
	git clone https://github.com/digitalcraftsman/hugo-icarus-theme
  • 下载的主题会在theme文件夹下,则将其examplesSite内容拷贝并覆盖到Commcocoa目录下

$ cp -av ~/commcocoa/themes/hugo-icarus-theme/exampleSite/* ~/commcocoa/

  • 使用Hugo build,需返回到commcocoa目录下
	$ hugo server -t hugo-icarus-theme -D

如果有其他主题,使用下面命令来切换不同的主题,比如切换到robust主题

	$ hugo server --theme=hugo_theme_robust --buildDrafts
  • build pass后会产生如下打印消息:
	$ hugo server -t hugo-icarus-theme -D
	Started building sites ...
	Built site for language en:
	0 draft content
	0 future content
	0 expired content
	6 regular pages created
	4 other pages created
	0 non-page files copied
	3 paginator pages created
	0 tags created
	1 categories created
	total in 65 ms
	Watching for changes in E:\Ryan_Shu\Commcocoa\commcocoa\{data,content,layouts,static,themes}
	Serving pages from memory
	Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
	Press Ctrl+C to stop

配置开关

  • 使用Tags来增加标签
	tags = []
  • 使用categories来增减目录
	categories = []
  • widgits
	recent_articles = false
    categories = true
    tags = true
    tag_cloud = true

部署

  • 使用Hugo命令生成public: Started building sites ... Built site for language en: 0 draft content 0 future content 0 expired content 6 regular pages created 4 other pages created 0 non-page files copied 3 paginator pages created 0 tags created 1 categories created total in 78 ms

Tips

  • 目前标题中不能够出现“+”,否则无法索引到,怀疑需要转义.
  • 使用Hugo new page.md 一定要注意编码格式,UTF-8否则容易出现中文字符无法显示.
  • ```的使用注意前后段落回车
分享到