Hugo Doc - Using Hugo

確保 Hugo 已經(jīng) 加入 PATH 環(huán)境變量.

$ hugo help

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

Usage:
  hugo [flags]
  hugo [command]

Available Commands:
  server          Hugo runs its own webserver to render the files
  version         Print the version number of Hugo
  config          Print the site configuration
  check           Check content in the source directory
  benchmark       Benchmark hugo by building a site a number of times
  new             Create new content for your site
  undraft         Undraft changes the content's draft status from 'True' to 'False'
  genautocomplete Generate shell autocompletion script for Hugo
  gendoc          Generate Markdown documentation for the Hugo CLI.
  help            Help about any command

Flags:
  -b, --baseURL="": hostname (and path) to the root, e.g. http://spf13.com/
  -D, --buildDrafts=false: include content marked as draft
  -F, --buildFuture=false: include content with publishdate in the future
      --cacheDir="": filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/
      --config="": config file (default is path/config.yaml|json|toml)
  -d, --destination="": filesystem path to write files to
      --disableRSS=false: Do not build RSS files
      --disableSitemap=false: Do not build Sitemap file
      --editor="": edit new content with this editor, if provided
  -h, --help=false: help for hugo
      --ignoreCache=false: Ignores the cache directory for reading but still writes to it
      --log=false: Enable Logging
      --logFile="": Log File path (if set, logging enabled automatically)
      --noTimes=false: Don't sync modification time of files
      --pluralizeListTitles=true: Pluralize titles in lists using inflect
  -s, --source="": filesystem path to read files relative from
      --stepAnalysis=false: display memory and timing of different steps of the program
  -t, --theme="": theme to use (located in /themes/THEMENAME/)
      --uglyURLs=false: if true, use /filename.html instead of /filename/
  -v, --verbose=false: verbose output
      --verboseLog=false: verbose logging
  -w, --watch=false: watch filesystem for changes and recreate as needed


Additional help topics:
 hugo convert         Convert will modify your content to different formats hugo list            Listing out various types of content

Use "hugo help [command]" for more information about a command.

簡單的例子

最常見的例子應(yīng)該是在你當(dāng)前的項(xiàng)目目錄下運(yùn)行 hugo :

$ hugo
0 draft content
0 future content
99 pages created
0 paginator pages created
16 tags created
0 groups created
in 120 ms

這將生成網(wǎng)站到 public/ 目錄下, 即可部署到服務(wù)器.

在開發(fā)網(wǎng)站的時(shí)候快速響應(yīng)

當(dāng)你在開發(fā)的時(shí)候, Hugo 會監(jiān)聽文件變化, 快速重構(gòu)出新的網(wǎng)站.

$ hugo -s ~/Code/hugo/docs
0 draft content
0 future content
99 pages created
0 paginator pages created
16 tags created
0 groups created
in 120 ms
Watching for changes in /Users/spf13/Code/hugo/docs/content
Press Ctrl+C to stop

Hugo 同時(shí)可以啟動(dòng)一個(gè) web 服務(wù)實(shí)時(shí)預(yù)覽. Hugo 實(shí)現(xiàn)了 LiveReload 技術(shù)來自動(dòng)刷新在支持 javascript的瀏覽器中打開的頁面.

這是非常容易并且十分通用的開發(fā) Hugo 網(wǎng)站的方式.

$ hugo server -ws ~/Code/hugo/docs
0 draft content
0 future content
99 pages created
0 paginator pages created
16 tags created
0 groups created
in 120 ms
Watching for changes in /Users/spf13/Code/hugo/docs/content
Serving pages from /Users/spf13/Code/hugo/docs/public
Web Server is available at http://localhost:1313/
Press Ctrl+C to stop

部署你的網(wǎng)站

在本地使用 hugo server 完成網(wǎng)站開發(fā)后, 你需要運(yùn)行 hugo 來重建你的網(wǎng)站. 然后你可以通過拷貝 publick/ 目錄來部署你的網(wǎng)站(使用 FTP, SFTP, webDAV, Rsync, git push 等等)

因?yàn)?Hugo 生成的是靜態(tài)文件, 你的可以在任何地方部署到任何站點(diǎn), Heroku, GoDaddy, DreamHost, GitHub Pages, Amazon S3CloudFront, 以及任何便宜和免費(fèi)的靜態(tài)服務(wù)站點(diǎn).
Apache, nginx, IIS… 任何web 服務(wù)軟件都可以支持.

部署注意事項(xiàng)
運(yùn)行 hugo 不會刪除之前生成的文件. 也就是說你需要在運(yùn)行 hugo 命令之前手動(dòng)刪除 public/ 目錄(或者你通過 -d/--destination 手動(dòng)指定的目錄), 否則有問題的文件(比如 草稿或者之后的帖子)可能會生成到站點(diǎn)里.

一個(gè)簡單的解決方法是為開發(fā)環(huán)境和生產(chǎn)環(huán)境指定不同的目錄.

在啟動(dòng)服務(wù)構(gòu)建草稿內(nèi)容(有利于編輯)的時(shí)候, 你可以指定不同的地址, 比如 dev/ 目錄.

$ hugo server -wDs ~/Code/hugo/docs -d dev

當(dāng)內(nèi)容可以發(fā)布的時(shí)候, 使用 publick/ 目錄:

$ hugo -s ~/Code/hugo/docs

這將有效地避免發(fā)布還沒準(zhǔn)備發(fā)布的內(nèi)容.

另一種選擇, 使用 Hugo 的 web 服務(wù)!

沒錯(cuò), Hugo 在構(gòu)建網(wǎng)站和提供 web 服務(wù)都快如閃電 (感謝 支持高并發(fā)和多線程設(shè)計(jì)的 Go 特性), 一些用戶更喜歡在生產(chǎn)環(huán)境中使用 Hugo 自身的 web服務(wù)!

所以其他 web 服務(wù)(Apache, nginx, IIS…)就不是那么必要了.

命令如下:

$ hugo server --baseURL=http://yoursite.org/ \
              --port=80 \
              --appendPort=false \
              --bind=87.245.198.50

注意 bind 選項(xiàng), 這是你服務(wù)器的 ip 地址(默認(rèn)的為大部分開發(fā)著使用的 127.0.0.1). 但是某些主機(jī), 比如 Amazon 的服務(wù)器的 ip 地址是轉(zhuǎn)化來的甚至有時(shí)候不能確定真正的 ip 地址. 使用 --bind=0.0.0.0 將會綁定所有的接口.

使用 Hugo 的做生產(chǎn)環(huán)境的服務(wù), 你只需要發(fā)布源文件, Hugo 在服務(wù)器上將飛速地構(gòu)建你的網(wǎng)站并提供 web 服務(wù).

如果你不在你的網(wǎng)頁中加入 提供 LiveReload 服務(wù)的 Javascript 代碼.你可以使用 --disableLiveReload=true 選項(xiàng).

感興趣嗎? 這有一些 Hugo 用戶提供的非常棒的教程:

Last revision: December 23, 2015
Hugo v0.15 documentation

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,351評論 25 708
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,697評論 19 139
  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,853評論 18 399
  • 短短幾年光陰,逝去的往事已經(jīng)經(jīng)不起細(xì)細(xì)回憶。2013年我蝸居在羅湖一個(gè)幾平米的房間里企圖再次創(chuàng)造產(chǎn)后逆襲的奇跡。那...
    女遐雪漠閱讀 1,879評論 22 24
  • 之前跟可樂合作了一個(gè)小故事,我告訴他,“你的故事很棒,有叔叔找你借穿越水晶一用,借嗎?” 他又得意又害羞:“媽媽,...
    Iamrola閱讀 631評論 0 3

友情鏈接更多精彩內(nèi)容