部署准备 
根据官网提示快速入门 |雨 果 (gohugo.io)   选定windows终端 
 
如果您是 Windows 用户:
不要使用命令提示符 
不要使用 Windows PowerShell 
从 PowerShell  或 Linux 终端(如 WSL 或 Git Bash)运行这些命令 
 
PowerShell 和 Windows PowerShell 是不同的应用程序 。
本机装好git 
 
开始部署 hugo文档有三种部署方式 ,选用Package managers 部署比较简单
Package managers 中有 Chocolatey、Scoop、Winget 三种命令,前两个需要格外安装,第三种自带,选用第三种,运行
1 winget install Hugo.Hugo.Extended 
 
安装的是hugo的扩展版(Extended),方便以后安装模板。
创建站点 运行这些命令以创建具有 Ananke  主题的 Hugo 站点。
1 2 3 4 5 6 hugo new site quickstart  ## quickstart为创建的站点文件夹,可随意改名称 cd quickstart  ##打开文件 git init   ## ./git git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke  ##添加主题 可直接改成自己想要的主题 echo "theme = 'ananke'" >> hugo.toml  ##在hugo.toml中加上主题和名称 可手动加 hugo server  ##本地运行服务 
 
通过终端中显示的 URL 查看您的网站。按下可停止 Hugo 的开发服务器。Ctrl + C
根据快速入门 |雨 果 (gohugo.io) 
添加文章 向您的网站添加一个新页面。
1 hugo new content content/posts/my-first-post.md 
 
Hugo 在目录中创建了该文件。使用编辑器打开文件。content/posts
1 2 3 4 5 +++ title = 'My First Post' date = 2024-01-14T07:07:07+01:00 draft = true   ##发布改成false +++ 
 
请注意,前面的值 是 。默认情况下,当您构建站点时,Hugo不会发布草稿内容。详细了解草稿内容、未来内容和过期内容 。
用markdown编辑后保存文件,然后启动 Hugo 的开发服务器以查看该站点。您可以运行以下任一命令来包含草稿内容。
1 2 hugo server --buildDrafts hugo server -D 
 
通过终端中显示的 URL 查看网站。
修改主题 1 2 git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke  ##改成想要的主题 echo "theme = 'ananke'" >> hugo.toml  ##在hugo.toml中加上主题和名称  
 
主题配置可根据主题文档来修改
github创建一个新仓库 创建好后有一个…or create a new repository on the command line 
 
具体用户名和仓库名根据自己创建的 
1 2 3 4 5 6 7 echo "# test" >> README.md  ##省略 git init  ##前面运行过 不需要再运行 git add README.md  ##不需要运行 改成 git add . git commit -m "first commit" git branch -M main git remote add origin git@github.com:user/test.git   git push -u origin main 
 
运行之后访问 GitHub 仓库。从主菜单中选择“设置 ”>“页面 ” 把 Source 部分改成GitHub Actions 
在本地存储库中创建一个空文件。 
 
1 .github/workflows/hugo.yaml 
 
将下面的 YAML 复制并粘贴到您创建的文件中。根据需要更改分支名称和 Hugo 版本。 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 name:  Deploy  Hugo  site  to  Pages on:      push:      branches:        -  main       workflow_dispatch:  permissions:   contents:  read    pages:  write    id-token:  write  concurrency:   group:  "pages"    cancel-in-progress:  false  defaults:   run:      shell:  bash  jobs:      build:      runs-on:  ubuntu-latest      env:        HUGO_VERSION:  0.128 .0      steps:        -  name:  Install  Hugo  CLI          run:  |            wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \           && sudo dpkg -i ${{ runner.temp }}/hugo.deb              -  name:  Install  Dart  Sass         run:  sudo  snap  install  dart-sass        -  name:  Checkout          uses:  actions/checkout@v4          with:            submodules:  recursive            fetch-depth:  0        -  name:  Setup  Pages          id:  pages          uses:  actions/configure-pages@v5        -  name:  Install  Node.js  dependencies          run:  "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"        -  name:  Build  with  Hugo          env:            HUGO_CACHEDIR:  ${{  runner.temp  }}/hugo_cache            HUGO_ENVIRONMENT:  production            TZ:  America/Los_Angeles          run:  |            hugo \             --gc \             --minify \             --baseURL "${{ steps.pages.outputs.base_url }}/"              -  name:  Upload  artifact         uses:  actions/upload-pages-artifact@v3          with:            path:  ./public       deploy:      environment:        name:  github-pages        url:  ${{  steps.deployment.outputs.page_url  }}      runs-on:  ubuntu-latest      needs:  build      steps:        -  name:  Deploy  to  GitHub  Pages          id:  deployment          uses:  actions/deploy-pages@v4  
 
后续文章提交 在本地写完 运行
1 2 3 git add . git commit -m "add first post"  ##first post 就是之前上面创建的第一遍文章 git push -u origin main