在您准备 提交新的 PR 之前,建议先预览您的更改。通过预览,您可以发现构建错误或 Markdown 格式问题。
您可以构建网站的容器镜像,或者在本地运行 Hugo。构建容器镜像的速度较慢,但可以显示 Hugo 短代码,这对于调试很有帮助。
CONTAINER_ENGINE 环境变量来覆盖此行为。在本地构建容器镜像
仅在测试 Hugo 工具本身的更改时,才需要执行此步骤
# Run this in a terminal (if required)
make container-image
在您的本地仓库中获取子模块依赖
# Run this in a terminal
make module-init
在容器中启动 Hugo
# Run this in a terminal
make container-serve
在 Web 浏览器中,导航至 https://:1313。Hugo 会监控更改并根据需要重新构建网站。
要停止本地 Hugo 实例,请返回终端并输入 Ctrl+C,或关闭终端窗口。
或者,在您的计算机上安装并使用 hugo 命令
安装 Hugo (Extended edition) 以及 website/netlify.toml 中指定的 Node 版本。
安装任何依赖项
npm ci
在终端中,进入您的 Kubernetes 网站仓库并启动 Hugo 服务器
cd <path_to_your_repo>/website
make serve
如果您使用的是 Windows 计算机或无法运行 make 命令,请使用以下命令
hugo server --buildFuture
在 Web 浏览器中,导航至 https://:1313。Hugo 会监控更改并根据需要重新构建网站。
要停止本地 Hugo 实例,请返回终端并输入 Ctrl+C,或关闭终端窗口。
出于技术原因,Hugo 提供了两组二进制文件。当前网站仅运行在 Hugo Extended 版本上。在 发布页面 中,查找名称中包含 extended 的压缩包。若要确认,请运行 hugo version 并查看是否包含 extended 字样。
如果您在 macOS 上运行 make serve 并收到以下错误
ERROR 2020/08/01 19:09:18 Error: listen tcp 127.0.0.1:1313: socket: too many open files
make: *** [serve] Error 1
请尝试检查当前打开文件的限制
launchctl limit maxfiles
然后运行以下命令(改编自 https://gist.github.com/tombigel/d503800a282fcadbee14b537735d202c)
#!/bin/sh
# These are the original gist links, linking to my gists now.
# curl -O https://gist.githubusercontent.com/a2ikm/761c2ab02b7b3935679e55af5d81786a/raw/ab644cb92f216c019a2f032bbf25e258b01d87f9/limit.maxfiles.plist
# curl -O https://gist.githubusercontent.com/a2ikm/761c2ab02b7b3935679e55af5d81786a/raw/ab644cb92f216c019a2f032bbf25e258b01d87f9/limit.maxproc.plist
curl -O https://gist.githubusercontent.com/tombigel/d503800a282fcadbee14b537735d202c/raw/ed73cacf82906fdde59976a0c8248cce8b44f906/limit.maxfiles.plist
curl -O https://gist.githubusercontent.com/tombigel/d503800a282fcadbee14b537735d202c/raw/ed73cacf82906fdde59976a0c8248cce8b44f906/limit.maxproc.plist
sudo mv limit.maxfiles.plist /Library/LaunchDaemons
sudo mv limit.maxproc.plist /Library/LaunchDaemons
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
sudo chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
此方法同样适用于 Catalina 和 Mojave macOS 系统。
如果您运行 make container-serve 时看到此错误,这可能是因为您对 Makefile 中 $IMAGE_VERSION 所定义的文件进行了本地修改。
网站镜像版本控制包含一个哈希值,该值是根据所列文件的内容生成的。例如,如果这些文件的哈希值为 1b9242684415,则网站镜像将被命名为 k8s-website-hugo:v0.133.0-1b9242684415。执行 make container-serve 会尝试从 Kubernetes 网站的 GCR 拉取该镜像。如果它不是当前版本,您会看到一条报错信息,提示该镜像不存在。
如果您需要在这些文件中进行更改并预览网站,则必须构建自己的本地镜像,而不是拉取预构建的镜像。为此,请继续运行 make container-image。
如果您在本地运行网站和/或预览更改时遇到其他问题,请随时在 kubernetes/website GitHub 仓库中 提交议题。