Hugo安装与部署
hugo號稱是The world’s fastest framework for building websites,是由go語言編寫的,編譯速度和運(yùn)行速度都是杠杠的。不像hexo依賴于node.js,項目依賴模塊多,hexo g生成網(wǎng)頁也比較慢。
Hugo 依靠Go語言進(jìn)行開發(fā),號稱世界上最快的構(gòu)建網(wǎng)站工具,到底有多快?根據(jù)相關(guān)博主提供的數(shù)據(jù),他200篇左右的博文用Hexo 需要10分鐘去生成靜態(tài)網(wǎng)頁,而Hugo 只需要10秒。就我個人的體驗來說,Hugo確實大大加快了網(wǎng)頁生成的速度,平常增加一篇博文然后再生成渲染需要4秒左右,而Hugo基本上是1秒內(nèi)完成。正是依賴于Hugo 快速生成的特點,調(diào)試方便成了Hugo的第二大特點。基本上我在源文件處修改的內(nèi)容可以實時地顯示在網(wǎng)頁上,而不用再次敲代碼生成再預(yù)覽,這對于博主來說簡直就是一個福音。
Hugo 在傳播度上不及Hexo,相應(yīng)的搭建教程及bug修復(fù)上也沒有Hexo來的齊全,因此會要求用戶有一定的代碼能力和debug能力。此外,從Hexo遷移到Hugo會存在一定的時間成本,因為兩者的markdown文件中對于Front Matter 的格式定義不同,因此需要修改每篇博文的該部分(當(dāng)然用腳本去修改是最好的)。最后,是主題問題,Hugo上面還沒有像Next一樣完善成熟的主題,不過這也讓大家不會一窩蜂地選取同一個樣式(Hugo的主題樣式還是很多的,官網(wǎng)提供了將近300個主題,選擇猶豫癥慎入)。
Hugo安裝
Hugo的安裝有很多方式,Install Hugo | Hugo (gohugo.io),根據(jù)個人喜好可以自行安裝。
本人以windows 7 為例,使用Hugo前需要安裝Git和Go語言開發(fā)環(huán)境,點擊對應(yīng)網(wǎng)址下載安裝包即可。
在Hugo的官網(wǎng)中選擇想要的版本下載zip,將其中的hugo.exe文件解壓到想要的地方。比如C:Hugoin。
Releases · gohugoio/hugo (github.com)
將Hugo添加到Windows的環(huán)境變量PATH中。 計算機(jī)——>屬性——>高級系統(tǒng)設(shè)置——>環(huán)境變量——>系統(tǒng)變量——>Path.
打開Git Bash,輸入
go
說明go 語言安裝成功。
go version
查看go的版本信息
輸入
hugo version
顯示 hugo 版本信息,說明hugo安裝成功
hugo help
hugo 的幫助頁面,很多東西都是我們要學(xué)習(xí)的
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 https://gohugo.io/.
Usage:
hugo [flags]
hugo [command]
Available Commands:
check Contains some verification checks
config Print the site configuration
convert Convert your content to different formats
env Print Hugo version and environment info
gen A collection of several useful generators.
help Help about any command
import Import your site from others.
list Listing out various types of content
new Create new content for your site
server A high performance webserver
version Print the version number of Hugo
Flags:
-b, --baseURL string hostname (and path) to the root, e.g. https://spf13.com/
-D, --buildDrafts include content marked as draft
-E, --buildExpired include expired content
-F, --buildFuture include content with publishdate in the future
--cacheDir string filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/
--cleanDestinationDir remove files from destination not found in static directories
--config string config file (default is path/config.yaml|json|toml)
--configDir string config dir (default "config")
-c, --contentDir string filesystem path to content directory
--debug debug output
-d, --destination string filesystem path to write files to
--disableKinds strings disable different kind of pages (home, RSS etc.)
--enableGitInfo add Git revision, date and author info to the pages
-e, --environment string build environment
--forceSyncStatic copy all files when static is changed.
--gc enable to run some cleanup tasks (remove unused cache files) after the build
-h, --help help for hugo
--i18n-warnings print missing translations
--ignoreCache ignores the cache directory
-l, --layoutDir string filesystem path to layout directory
--log enable Logging
--logFile string log File path (if set, logging enabled automatically)
--minify minify any supported output format (HTML, XML etc.)
--noChmod don't sync permission mode of files
--noTimes don't sync modification time of files
--path-warnings print warnings on duplicate target paths etc.
--quiet build in quiet mode
--renderToMemory render to memory (only useful for benchmark testing)
-s, --source string filesystem path to read files relative from
--templateMetrics display metrics about template executions
--templateMetricsHints calculate some improvement hints when combined with --templateMetrics
-t, --theme strings themes to use (located in /themes/THEMENAME/)
--themesDir string filesystem path to themes directory
--trace file write trace to file (not useful in general)
-v, --verbose verbose output
--verboseLog verbose logging
-w, --watch watch filesystem for changes and recreate as needed
Use "hugo [command] --help" for more information about a command.
新建博客
在自己的目錄下建文件夾,如E盤,打開git bash (右鍵 git bash here),
輸入hugo new site "你的文件名字",便可以生成一個用于存放博客的文件夾。
hugo new site myblog
目錄結(jié)構(gòu):Directory Structure | Hugo (gohugo.io)
安裝主題
不同于hexo,hugo沒有自帶主題,所以建立完文件夾后要導(dǎo)入主題文件。導(dǎo)入主題方式和hexo相似,可以用git clone的方式,也可以到相應(yīng)主題的github中下載zip文件然后解壓到自己博客的themes文件夾中。
官網(wǎng)主題庫:Hugo Themes
Hugo配置文件放置在源文件下,并且支持三種格式:toml,yaml,yml。這個配置文件可以直接從主題文件中的exampleSite 里copy到博客文件夾下,然后進(jìn)行修改。
注意點1:有些主題沒有提供相應(yīng)的配置文件,得進(jìn)行自己修改,不建議選用這類主題。
注意點2:配置文件中要確保里面的主題名字和你themes文件夾中相應(yīng)的主題文件夾名字一樣,比如我的主題是pure,那么配置文件里的theme = pure,并且themes 文件夾中也有一個pure的文件夾。這是為了保證工具能依據(jù)名字找到相應(yīng)的主題文件。
生成博文
在 Git Bash 中輸入hugo new posts/xxxx.md,這時候就會在文件夾content/posts形成你要的markdown文件,打開進(jìn)行編輯即可。
渲染查看效果
在博客文件夾中打開Git Bash,輸入hugo server,然后打開http://localhost:1313/來查看效果。
注意,markdown文件中的front matter部分有一個draft參數(shù),如果draft設(shè)置為true則可正常渲染,如果設(shè)置為false則不予以渲染。相應(yīng)的如果想查看全部效果則輸入hugo server -D表示將草稿文件也進(jìn)行渲染。
淺談我為什么從 HEXO 遷移到 HUGO - 少數(shù)派 (sspai.com)
使用Hugo快速搭建個人博客 (qq.com)
總結(jié)
- 上一篇: 邪恶力量第一至九季/全集Supernat
- 下一篇: a标签伪类:visited下划线设置无效