How to Update or Publish (Chinese)
首先这是 hugo blog 的文件结构:
<root> (itsublog)
├── archetypes
├── assets
│ └── images
├── content
│ ├── en
│ │ ├── homepage
│ │ └── posts
│ └── zh
│ ├── homepage
│ └── posts
├── data
├── i18n
├── layouts
├── public
├── resources
├── static
└── themes
创建新文章
在<root>
下执行
hugo new posts/<post-name>/index.md
如果config.yaml
中设置了defaultContentLanguageInSubdir = true
,则会在content/<def_lang>/posts/<post-name>/
下生成index.md
文件;否则会在content/posts/<post-name>/
下生成index.md
文件。这里的<def_lang>
是config.yaml
中设置的默认语言:defaultContentLanguage
。
这样就在/en/
下生成了posts/<post-name>/index.md
文件,然后在content/en/posts/<post-name>/
下写文章。
对于其他语言,则复制到content/<lang>/posts/<post-name>/
即可;或者,可以在content/<lang>/posts/
下创建一个软链接指向content/en/posts/<post-name>/
:
(Linux)
cd content/<lang>/posts/
ln -s ../../en/posts/<post-name> posts/<post-name>
(Windows)
cd content\<lang>\posts\
mklink /D posts\<post-name> ..\..\en\posts\<post-name>
编辑
插入图片
Former Matter
就是markdown的头部信息,用于设置文章的元信息,如标题、日期、标签等。可以是yaml、json、toml格式。
目录中的预览
在content/<lang>/posts/<post-name>/index.md
中,可以插入<!--more-->
,这样在目录中就只会显示<!--more-->
之前的内容。
也可以直接在former matter中设置description
,这样在目录中就只会显示description
的内容。
TOC (Table of Contents)
文章的索引。可以直接在former matter中设置toc = true
,这样在文章中就会显示 TOC。
Theme: Eureka
本博客使用的主题是 Eureka,停止更新且有很多 bug;在编辑的时候,需要注意的是 <h1>
标题不会在 Table of Contents 中显示,所以在文章中不要使用 <h1>
标题。
部署与发布
本地预览整个网站
在<root>
下执行
hugo server -D
然后在浏览器中打开http://localhost:1313/
即可
端口号(此处为1313
)可以在config.yaml
中设置。
发布
在<root>
下执行
hugo
然后将public/
文件夹中的内容上传到服务器即可。
在这里,可以使用git
来管理public/
文件夹,这样就可以使用git
来发布网站。
cd public/
git add .
git commit -m "<commit message>"
git push
- 这一部分的内容参考了这里。