Skip to content

Latest commit

 

History

History
75 lines (50 loc) · 2.1 KB

File metadata and controls

75 lines (50 loc) · 2.1 KB

How To Startup

这份文档说明当前仓库在本地如何预览和构建博客。

推荐方式

当前内容里有一部分图片源文件放在 content/**/_assets/**。 为了保证本地预览时这些图片能正常访问,启动 hugo 之前先同步一次资源。

Windows PowerShell:

powershell -ExecutionPolicy Bypass -File .\scripts\sync-content-assets.ps1
hugo server --environment development --port 1414

Git Bash / WSL:

bash scripts/sync-content-assets.sh
hugo server --environment development --port 1414

启动后访问:

http://localhost:1414/

仓库启动脚本

如果你想少输一点命令,可以直接用仓库根目录的启动脚本。

Git Bash / WSL:

sh startup.sh

Windows PowerShell:

powershell -ExecutionPolicy Bypass -File .\startup.ps1

这两个脚本都会先同步资源,再启动 hugo server --port 1414

本地构建

如果你要在本地检查最终生成结果,建议先同步资源,再执行完整构建。

Windows PowerShell:

powershell -ExecutionPolicy Bypass -File .\scripts\sync-content-assets.ps1
hugo --cleanDestinationDir

Git Bash / WSL:

bash scripts/sync-content-assets.sh
hugo --cleanDestinationDir

构建结果输出到 public/

说明

  • 图片源目录统一使用 content/**/_assets/**,文章内也可以继续使用相对路径 ./_assets/... 方便本地写作。
  • 图片最终发布路径以文章 front matter 里的 url 为准,而不是以 markdown 所在目录层级为准,所以多级目录文章也可以正常发布图片。
  • 裸跑 hugo serverhugo --cleanDestinationDir 仍然可以执行,但不会先同步 content/**/_assets/** 里的资源。
  • 同步脚本会把 content/**/_assets/** 发布到页面对应的 assets/ 路径。
  • Hugo 渲染阶段会把文章里的 ./_assets/... 自动改写成页面实际访问的 ./assets/...,所以本地写作和最终发布可以共存。
  • 如果文章里用了 ./_assets/... 图片引用,建议使用上面的“先同步再构建”命令。