Hugo Doc - Using Hugo 簡單的例子 在開發網站的時候快速響應 部署你的網站 另一種選擇, 使用 Hugo 的 web 服務!

確保 Hugo 已經 加入 PATH 環境變量.

$ 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.

簡單的例子

最常見的例子應該是在你當前的項目目錄下運行 hugo :

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

這將生成網站到 public/ 目錄下, 即可部署到服務器.

在開發網站的時候快速響應

當你在開發的時候, Hugo 會監聽文件變化, 快速重構出新的網站.

$ 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 同時可以啓動一個 web 服務實時預覽. Hugo 實現了 LiveReload 技術來自動刷新在支持 javascript的瀏覽器中打開的頁面.

這是非常容易並且十分通用的開發 Hugo 網站的方式.

$ 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

部署你的網站

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

因爲 Hugo 生成的是靜態文件, 你的可以在任何地方部署到任何站點, Heroku, GoDaddy, DreamHost, GitHub Pages, Amazon S3CloudFront, 以及任何便宜和免費的靜態服務站點.
Apache, nginx, IIS… 任何web 服務軟件都可以支持.

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

一個簡單的解決方法是爲開發環境和生產環境指定不同的目錄.

在啓動服務構建草稿內容(有利於編輯)的時候, 你可以指定不同的地址, 比如 dev/ 目錄.

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

當內容可以發佈的時候, 使用 publick/ 目錄:

$ hugo -s ~/Code/hugo/docs

這將有效地避免發佈還沒準備發佈的內容.

另一種選擇, 使用 Hugo 的 web 服務!

沒錯, Hugo 在構建網站和提供 web 服務都快如閃電 (感謝 支持高併發和多線程設計的 Go 特性), 一些用戶更喜歡在生產環境中使用 Hugo 自身的 web服務!

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

命令如下:

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

注意 bind 選項, 這是你服務器的 ip 地址(默認的爲大部分開發着使用的 127.0.0.1). 但是某些主機, 比如 Amazon 的服務器的 ip 地址是轉化來的甚至有時候不能確定真正的 ip 地址. 使用 --bind=0.0.0.0 將會綁定所有的接口.

使用 Hugo 的做生產環境的服務, 你只需要發佈源文件, Hugo 在服務器上將飛速地構建你的網站並提供 web 服務.

如果你不在你的網頁中加入 提供 LiveReload 服務的 Javascript 代碼.你可以使用 --disableLiveReload=true 選項.

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

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章