logo
0
0
WeChat Login
Forkfromminihuber/hugo-docker, aheadmain3 commits, behindmain17 commits

Hugo(端口1313) 官方镜像 ghcr.io/gohugoio/hugo

Hugo 是一个用 Go 编写的静态 HTML 和 CSS 网站生成器,号称是世界上最快的网站构建框架

https://gohugo.io/ The world's fastest framework for building websites Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again. 1.创建项目目录并挂载到容器 强制指定 Hugo 将站点生成到挂载的 /arc目录 创建一个新的 Hugo 站点(GitHub.io镜像)

HUGO_PATH=/data/hugo

mkdir -p $HUGO_PATH/site
cd $HUGO_PATH/site
chmod 777 $HUGO_PATH/site

docker run --rm -it \
-v $HUGO_PATH/site:/src \
-w /src \
bailangvvking/hugo \
new site .

2.下载主题 需要宿主机安装了git

HUGO_PATH=/data/hugo
# 主题
cd $HUGO_PATH/site
git init
git submodule add --depth 1 https://gh-proxy.org/https://github.com/adityatelange/hugo-PaperMod themes/PaperMod
# echo 'theme = "PaperMod"' >> hugo.toml

3.下载配置模板

HUGO_PATH=/data/hugo
mv $HUGO_PATH/site/hugo.toml $HUGO_PATH/site/hugo.toml.bak
wget -O $HUGO_PATH/site/hugo.yaml "https://r2.lovelyy.eu.org/raw/docker/hugo/PaperMod/hugo.yaml"

mkdir -p $HUGO_PATH/site/content/categories
cat > $HUGO_PATH/site/content/categories/_index.md <<EOF
---
title: 分类
layout: categories
---
EOF

mkdir -p $HUGO_PATH/site/content/tags
cat > $HUGO_PATH/site/content/tags/_index.md <<EOF
---
title: 标签
layout: tags
---
EOF

cat > $HUGO_PATH/site/content/archives.md <<EOF
---
title: 归档
layout: archives
---
EOF

cat > $HUGO_PATH/site/content/search.md <<EOF
---
title: "搜索"
layout: "search"
---
EOF

cat > $HUGO_PATH/site/archetypes/default.md <<EOF
---
title: {{ replace .File.ContentBaseName "-" " " | title }}
published: {{ .Date }}
summary: "文章简介"
cover:
  image: "文章封面图。也支持HTTPS"
tags: [标签1, 标签2]
categories: '文章所处的分类'
draft: false 
lang: ''
---
EOF

4:新建某篇文章(以hello.md举例)

HUGO_PATH=/data/hugo
docker run --rm -it \
-v $HUGO_PATH/site:/src \
-w /src \
bailangvvking/hugo \
new content/posts/hello.md

5.启动 Hugo 服务器(主机网络模式 监听V4 V6 端口以1313举例)可以添加-d后台运行

--renderToMemory --templateMetrics --bind=0.0.0.0 --bind :: --port 1313 --buildDrafts --noBuildLock --watch

(运行) 预览开发时临时!本地!调试的(一定要改最后的网址) --buildDrafts关闭草稿模式 注意要改成访问域名

HUGO_PATH=/data/hugo
docker run -it -d \
--name hugo \
-v $HUGO_PATH/site:/src \
-w /src \
--network=host \
--restart always \
bailangvvking/hugo \
server --bind=0.0.0.0 --bind=:: --port=1313 \
--renderToMemory --templateMetrics --buildDrafts --noBuildLock --watch \
--baseURL=http://你的网站:端口/

Tips:

(构建站点)写入文件(默认 server运行的是内存版本 没有写入到文件中)

HUGO_PATH=/data/hugo

docker run --rm -it -d \
--name hugo \
-v $HUGO_PATH/site:/src \
-w /src \
--network=host \
bailangvvking/hugo \
--bind=0.0.0.0 --bind=:: \
--port=1313 \
--buildDrafts \
--baseURL=http://ipv6.lovelyy.eu.org:1313/

创建首页

HUGO_PATH=/data/hugo

docker run --rm -it \
-v $HUGO_PATH/site:/src \
-w /src \
bailangvvking/hugo \
new content/_index.md

在主机上查看 Hugo 自动构建的页面 URL 以及可以访问的网址

HUGO_PATH=/data/hugo

docker run --rm -it \
-v $HUGO_PATH/site:/src \
-w /src \
bailangvvking/hugo \
list all
  1. hugo 命令 用于生成静态网站。

hugo [options] Shell 常用参数 参数

说明

-D, --buildDrafts 构建草稿文章(draft: true)

-E, --buildExpired 构建过期文章(expiryDate 过期的文章)

-F, --buildFuture 构建未来发布的文章(publishDate 在未来的文章)

--cleanDestinationDir 在生成站点前清理 public/ 目录

--minify 生成的 HTML/CSS/JS 进行压缩优化

--destination DIR, -d DIR 指定生成的静态文件存放目录(默认 public/)

--gc 清理无用文件(垃圾回收)

--templateMetrics 显示模板渲染性能指标

  1. hugo server 命令 用于本地开发,开启 Hugo 内置服务器。

hugo server [options] Pgsql 常用参数 参数

说明

-D, --buildDrafts 显示草稿文章

--bind 绑定监听的 IP(默认 127.0.0.1)

--port 端口号(默认 1313)

--baseURL 指定网站访问的 URL

--disableFastRender 关闭 Hugo 的快速渲染模式(可解决某些页面未刷新问题)

--watch 监听文件变更,自动重新加载(默认开启)

--minify 启用 HTML/CSS/JS 压缩

--navigateToChanged 在浏览器自动跳转到最近修改的页面

--noHTTPCache 禁用浏览器缓存

--renderToDisk 直接写入磁盘,而不是内存

--panicOnWarning 任何警告都视为错误,终止执行

About

No description, topics, or website provided.
Language
Dockerfile100%