這幾天研究了用hugo搭建個人博客。
簡單的整理了一下。
1.安裝hugo(windows 請查看官網介紹 https://gohugo.io/getting-started/installing/)
$ brew install hugo
之后檢查版本
$ hugo version
Hugo Static Site Generator v0.37.1 darwin/amd64 BuildDate:
2.創建hugo 項目
$ hugo new site my-blog Congratulations! Your new Hugo site is created in /Users/limingxie/Projects/my-blog. 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.
3.添加主題
$ cd my-blog $ git init $ git submodule add https://github.com/keichi/vienna.git themes/vienna
4.添加內容(content目錄下執行。例:/Users/limingxie/Projects/my-blog/content)
$ hugo new xxx/my-first-blog.md
編輯:my-first-blog.md
5.運行調試
$ hugo server -D | EN +------------------+----+ Pages | 16 Paginator pages | 0 Non-page files | 0 Static files | 14 Processed images | 0 Aliases | 1 Sitemaps | 1 Cleaned | 0 Total in 26 ms Watching for changes in /Users/limingxie/Projects/pangpang/pangpang-blog/{content,data,layouts,static,themes} Serving pages from memory Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender Web Server is available at //localhost:1313/ (bind address 127.0.0.1) Press Ctrl+C to stop
訪問[
http://localhost:1313/]調試~
6.Theme的設定
打開config.toml
baseURL = "https://limingxie.github.io/" //這baseURL是部署后的訪問地址。 languageCode = "en-us" title = "My New Hugo Site" theme = "vienna" // 你使用的theme 名稱
查看[vienna Theme]說明的話還可以做很多設置。
7.部署到GitHub
1)首先在GitHub上創建一個Repository,命名為:limingxie.github.io (這要和你的baseURL一致。)
2)在/Users/limingxie/Projects/my-blog目錄下執行以下命令
$ hugo --theme=vienna --buildDrafts --baseUrl="https://limingxie.github.io/" | EN +------------------+----+ Pages | 16 Paginator pages | 0 Non-page files | 0 Static files | 14 Processed images | 0 Aliases | 1 Sitemaps | 1 Cleaned | 0 Total in 28 ms
--buildDrafts 不加會生成無內容的網站
--baseUrl要和config.toml的地址一致。
順利的話會創建public文件(里面的內容就是你要上傳的靜態網站的文件。)
$ cd public $ git init $ git remote add origin https://github.com/limingxie/limingxie.github.io.git $ git add -A $ git commit -m "first commit" $ git push -u origin master
### 瀏覽器里訪問:https://limingxie.github.io/ 就可以訪問你的博客了
----------------------------------------------
歡迎大家的意見和交流
email: li_mingxie@163.com
博客:https://limingxie.github.io/