hugo使用
- windows安装chocolatey过程中报错
警告: An existing Chocolatey installation was detected. Installation will not continue.
For security reasons, this script will not overwrite existing installations.
Please use choco upgrade chocolatey to handle upgrades of Chocolatey itself.
- 解决方案
# 删除C:\ProgramData\chocolatey该目录
# 重新执行安装命令
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
- windows安装chocolatey报错:
set-ExecutionPolicy不是内部或外部命令
# 管理员身份打开powershell,执行如下命令
# 输入 A 回车
# 再输入 get-ExecutionPolicy 回车
# 出现 RemoteSigned 表示成功
- 安装hugo
# 设置环境变量
SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
# 安装hugo
choco install hugo -confirm
# 验证是否安装成功
hugo version
# 例如我们在D盘打开cmd,使用hugo创建一个文件夹hugo作为本地博客目录
hugo new site hugo
# 进入themes文件夹
# 选择主题:https://themes.gohugo.io/
# 使用git将主题克隆到themes文件夹,删除.git文件
# 将C:\hugo\themes\hugo-theme-pixyll\exampleSite目录中的config.toml克隆到本地博客根路径
# 使用vscode打开本地博客根路径的config.toml
# 修改为themes文件夹中的主题文件夹名称
theme = "hugo-theme-pixyll"
# 如果有如下需注释
themesDir = "../.."
# cmd进入本地博客根目录,启动本地服务,浏览器访问http://localhost:1313/
hugo server
- 本地博客根路径config.toml完整配置
languageCode = "en-us"
contentdir = "content"
publishdir = "public"
builddrafts = false
baseUrl = "https://chniny.github.io"
canonifyurls = true
title = "当时故里"
author = "chniny"
theme = "hugo-theme-pixyll"
disqusShortname = "sitename"
[indexes]
category = "categories"
tag = "tags"
- 新建文章
hugo new post/文章名称.md
# 本地博客\content\post目录下会生成一篇文章
# 新生成的文章中开头有一个属性,需改为false,否则本地启动服务后不会显示
draft: true # 表示文章是否草稿,草稿内容不会被发布
# 打开md文件编辑后
# 启动
hugo server -D
- 显示摘要
<!--more-->
- 设置标签
tags:
- Hugo
- 插入图片
# 在本地博客根路径\static路径下新建一个文件夹images,将图片放到该路径下
# 在文章中插入图片

# 如下为测试插入图片
-
由于hugo-theme-pixyll主题不知道怎么设置密码
-
更换主题
tale-hugo
# 进入themes文件夹
git clone https://github.com/EmielH/tale-hugo.git
# 配置文档
https://themes.gohugo.io/themes/tale-hugo/
- 本地博客根路径config.toml
baseURL = 'https://chniny.github.io'
languageCode = 'en-us'
title = '当时故里'
theme = "tale-hugo"
- 设置文章加密 -> 参考
# 进入本地博客根路径\themes\tale-hugo\layouts\_default
# 编辑single.html,添加如下
<div class="post-password">
{{ if ( .Params.password | default "" ) }}
<script>
(function(){
if (prompt('请输入文章密码') != {{ .Params.password }}){
alert('密码错误!');
if (history.length === 1) {
window.opener = null;
window.open('', '_self');
window.close();
} else {
history.back();
}
}
})();
</script>
{{ end }}
</div>
# 文章头配置如下
password: 123456
- 使用命令 hugo server 并没有在public文件夹生成静态文件