日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

Hugo安装与部署

發布時間:2023/12/13 综合教程 35 生活家
生活随笔 收集整理的這篇文章主要介紹了 Hugo安装与部署 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

hugo號稱是The world’s fastest framework for building websites,是由go語言編寫的,編譯速度和運行速度都是杠杠的。不像hexo依賴于node.js,項目依賴模塊多,hexo g生成網頁也比較慢。

Hugo 依靠Go語言進行開發,號稱世界上最快的構建網站工具,到底有多快?根據相關博主提供的數據,他200篇左右的博文用Hexo 需要10分鐘去生成靜態網頁,而Hugo 只需要10秒。就我個人的體驗來說,Hugo確實大大加快了網頁生成的速度,平常增加一篇博文然后再生成渲染需要4秒左右,而Hugo基本上是1秒內完成。正是依賴于Hugo 快速生成的特點,調試方便成了Hugo的第二大特點。基本上我在源文件處修改的內容可以實時地顯示在網頁上,而不用再次敲代碼生成再預覽,這對于博主來說簡直就是一個福音。

Hugo 在傳播度上不及Hexo,相應的搭建教程及bug修復上也沒有Hexo來的齊全,因此會要求用戶有一定的代碼能力和debug能力。此外,從Hexo遷移到Hugo會存在一定的時間成本,因為兩者的markdown文件中對于Front Matter 的格式定義不同,因此需要修改每篇博文的該部分(當然用腳本去修改是最好的)。最后,是主題問題,Hugo上面還沒有像Next一樣完善成熟的主題,不過這也讓大家不會一窩蜂地選取同一個樣式(Hugo的主題樣式還是很多的,官網提供了將近300個主題,選擇猶豫癥慎入)。

Hugo安裝

Hugo的安裝有很多方式,Install Hugo | Hugo (gohugo.io),根據個人喜好可以自行安裝。

本人以windows 7 為例,使用Hugo前需要安裝Git和Go語言開發環境,點擊對應網址下載安裝包即可。

在Hugo的官網中選擇想要的版本下載zip,將其中的hugo.exe文件解壓到想要的地方。比如C:Hugoin

Releases · gohugoio/hugo (github.com)

將Hugo添加到Windows的環境變量PATH中。 計算機——>屬性——>高級系統設置——>環境變量——>系統變量——>Path.

打開Git Bash,輸入

go

  

說明go 語言安裝成功。

 go version

  查看go的版本信息

輸入

hugo version

  

顯示 hugo 版本信息,說明hugo安裝成功

hugo help

hugo 的幫助頁面,很多東西都是我們要學習的  

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

  

目錄結構:Directory Structure | Hugo (gohugo.io)

安裝主題

不同于hexo,hugo沒有自帶主題,所以建立完文件夾后要導入主題文件。導入主題方式和hexo相似,可以用git clone的方式,也可以到相應主題的github中下載zip文件然后解壓到自己博客的themes文件夾中。

官網主題庫:Hugo Themes

Hugo配置文件放置在源文件下,并且支持三種格式:toml,yaml,yml。這個配置文件可以直接從主題文件中的exampleSite 里copy到博客文件夾下,然后進行修改。

注意點1:有些主題沒有提供相應的配置文件,得進行自己修改,不建議選用這類主題。
注意點2:配置文件中要確保里面的主題名字和你themes文件夾中相應的主題文件夾名字一樣,比如我的主題是pure,那么配置文件里的theme = pure,并且themes 文件夾中也有一個pure的文件夾。這是為了保證工具能依據名字找到相應的主題文件。

生成博文

在 Git Bash 中輸入hugo new posts/xxxx.md,這時候就會在文件夾content/posts形成你要的markdown文件,打開進行編輯即可。

渲染查看效果

在博客文件夾中打開Git Bash,輸入hugo server,然后打開http://localhost:1313/來查看效果。

注意,markdown文件中的front matter部分有一個draft參數,如果draft設置為true則可正常渲染,如果設置為false則不予以渲染。相應的如果想查看全部效果則輸入hugo server -D表示將草稿文件也進行渲染。

淺談我為什么從 HEXO 遷移到 HUGO - 少數派 (sspai.com)

使用Hugo快速搭建個人博客 (qq.com)

總結

以上是生活随笔為你收集整理的Hugo安装与部署的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。