目录结构
站点骨架
当你创建一个新站点时,Hugo 会生成项目骨架。例如,这个命令
hugo new site my-site
创建如下目录结构
my-site/
├── archetypes/
│ └── default.md
├── assets/
├── content/
├── data/
├── i18n/
├── layouts/
├── static/
├── themes/
└── hugo.toml <-- site configuration
根据需要,你可能希望将站点配置组织到子目录中
my-site/
├── archetypes/
│ └── default.md
├── assets/
├── config/ <-- site configuration
│ └── _default/
│ └── hugo.toml
├── content/
├── data/
├── i18n/
├── layouts/
├── static/
└── themes/
当你构建站点时,Hugo 会创建一个 public
目录,通常还会创建一个 resources
目录
my-site/
├── archetypes/
│ └── default.md
├── assets/
├── config/
│ └── _default/
│ └── hugo.toml
├── content/
├── data/
├── i18n/
├── layouts/
├── public/ <-- created when you build your site
├── resources/ <-- created when you build your site
├── static/
└── themes/
目录
每个子目录都为站点的贡献内容、结构、行为或展示。
archetypes
archetypes
目录包含用于新内容的模板。请参阅详情。
assets
assets
目录包含通常通过资源管道传递的全局资源。这包括诸如图片、CSS、Sass、JavaScript 和 TypeScript 等资源。请参阅详情。
config
config
目录包含你的站点配置,可能拆分为多个子目录和文件。对于配置最少或在不同环境中不需要不同行为的项目,项目根目录中名为 hugo.toml
的单个配置文件就足够了。请参阅详情。
content
content
目录包含构成站点内容的标记文件(通常是 Markdown)和页面资源。请参阅详情。
data
data
目录包含用于增强内容、配置、本地化和导航的数据文件(JSON、TOML、YAML 或 XML)。请参阅详情。
i18n
i18n
目录包含多语言站点的翻译表。请参阅详情。
layouts
layouts
目录包含将内容、数据和资源转换为完整网站的模板。请参阅详情。
public
public
目录包含发布的网站,在运行 hugo
或 hugo server
命令时生成。Hugo 会根据需要重新创建此目录及其内容。请参阅详情。
resources
resources
目录包含 Hugo 资源管道的缓存输出,这些输出是在您运行 hugo
或 hugo server
命令时生成的。默认情况下,此缓存目录包含 CSS 和图像。Hugo 会根据需要重新创建此目录及其内容。
static
static
目录包含在您构建网站时将被复制到 public
目录的文件。例如:favicon.ico
、robots.txt
和用于验证网站所有权的文件。在引入 页面包 和 资源管道 之前,static
目录也用于存放图像、CSS 和 JavaScript。
themes
themes
目录包含一个或多个主题,每个主题都有自己的子目录。
联合文件系统
Hugo 创建一个联合文件系统,允许您将两个或多个目录挂载到同一位置。例如,假设您的主目录包含一个目录中的 Hugo 项目,以及另一个目录中的共享内容
home/
└── user/
├── my-site/
│ ├── content/
│ │ ├── books/
│ │ │ ├── _index.md
│ │ │ ├── book-1.md
│ │ │ └── book-2.md
│ │ └── _index.md
│ ├── themes/
│ │ └── my-theme/
│ └── hugo.toml
└── shared-content/
└── films/
├── _index.md
├── film-1.md
└── film-2.md
您可以在构建网站时使用挂载来包含共享内容。在您的网站配置中
module:
mounts:
- source: content
target: content
- source: /home/user/shared-content
target: content
[module]
[[module.mounts]]
source = 'content'
target = 'content'
[[module.mounts]]
source = '/home/user/shared-content'
target = 'content'
{
"module": {
"mounts": [
{
"source": "content",
"target": "content"
},
{
"source": "/home/user/shared-content",
"target": "content"
}
]
}
}
挂载后,联合文件系统具有以下结构
home/
└── user/
└── my-site/
├── content/
│ ├── books/
│ │ ├── _index.md
│ │ ├── book-1.md
│ │ └── book-2.md
│ ├── films/
│ │ ├── _index.md
│ │ ├── film-1.md
│ │ └── film-2.md
│ └── _index.md
├── themes/
│ └── my-theme/
└── hugo.toml
您可以将目录挂载到 archetypes
、assets
、content
、data
、i18n
、layouts
和 static
。请参阅详细信息。
您还可以使用 Hugo 模块从 Git 存储库挂载目录。请参阅详细信息。
主题骨架
当您创建新主题时,Hugo 会生成一个功能齐全的主题骨架。例如,此命令
hugo new theme my-theme
创建此目录结构(未显示子目录)
my-theme/
├── archetypes/
├── assets/
├── content/
├── data/
├── i18n/
├── layouts/
├── static/
├── LICENSE
├── README.md
├── hugo.toml
└── theme.toml
使用上面描述的联合文件系统,Hugo 将每个目录挂载到项目中对应的位置。当两个文件具有相同的路径时,项目目录中的文件具有更高的优先级。这允许您,例如,通过将副本放置在项目目录中的相同位置来覆盖主题的模板。
如果您同时使用来自两个或多个主题或模块的组件,并且存在路径冲突,则第一个挂载具有更高的优先级。