創建內容

內容是站點最基本,也是最核心的部分,本文將介紹內容的一些基本概念,以及如何創建內容。

內容結構§

 1tree content/blog 
 2content/blog
 3├── _index.md
 4├── hello.md
 5├── foo
 6|   ├── feature.png
 7│   ├── bar.md
 8│   └── index.md
 9├── posts
10│   ├── _index_.md
11│   ├── post-1.md
12│   └── post-2.md
sh

以上內容結構具有:

  • 四篇常規頁面blog/hello/, blog/foo/blog/posts/post-1/blog/posts/post-2/
  • 兩個 branch bundle (帶有 _index.md 的目錄):blogposts
  • 三篇 branch 內容:hello.mdposts/post-1.mdposts/post-2.md
  • 一個 leaf bundle (帶有 index.md 的目錄):foo。Leaf bundle 將作爲一篇常規頁面,其餘的內容將作爲其頁面資源,如 foo/bar.md 是一個頁面資源,而非單頁內容。

詳情請查閱 Content OrganizationPage Bundles

創建內容§

通過 hugo new 命令創建內容。

1hugo new blog/hello/index.md
sh

該命令將於 content 目錄下創建一個 blog/hello/index.md 的內容頁面,其初始內容類似如下:

1---
2title: "Hello"
3date: 2023-03-08T11:02:23+08:00
4draft: true
5---
markdown

內容原型§

內容原型是用於創建內容的模板,可以定義一些初始化的參數和內容,比如以下 notes 原型指定 typedocs 以使用 docs 佈局。

archetypes/notes.md
1---
2type: docs
3title: '{{ replace .Name "-" " " | title }}'
4date: {{ .Date }}
5draft: true
6---
yaml

當創建時,將會使用對應的模板生成初始內容。

1hugo new notes/foo.md   
2Content "content/notes/foo.md" created
sh
1cat content/notes/foo.md
2---
3type: docs
4title: 'Foo'
5date: 2023-04-12T14:35:35+08:00
6draft: true
7---
sh

詳情請查閱原型

內容組成§

每個內容頁面由前言和主體構成。

1FRONT MATTER
2
3CONTENT BODY
markdown

內容前言§

也就是 Front Matter,用於定義內容的參數,如標題、日期、標籤、分類等。

內容前言格式§

Hugo 支持三種前言格式:YAMLTOMLJSON

YAML 前言§

YAML 前言由 --- 包裹起來。

1---
2title: "Hello"
3---
markdown

TOML 前言§

TOML 前言由 +++ 包裹起來。

1+++
2title = "Hello"
3+++
markdown

JSON 前言§

JSON 前言由 {} 包裹起來,後跟一個新行。

1{
2  "title": "Hello"
3}
markdown

內容主體§

也就是字面上的內容本身,支持 Markdown 和短代碼編寫內容。

延伸閱讀§

  • 全部
  • English
  • 简体中文
  • 繁體中文
  • 最佳匹配
  • 最舊的
  • 最新的
  • 2020
  • 2022
  • 2023
  • HB Framework Authors
  • Hugo Authors
  • Banner
  • Build Tools
  • Comments
  • Configuration
  • Deployment
  • Develop
  • Footer
  • Header
  • Inline Frame
  • Installation
  • Look and Feel
  • Menus
  • Module
  • Modules
  • Shortcode
  • Sidebar
  • 侧边栏
  • 内容
  • 安装
  • 开发
  • 构建工具
  • 概览
  • 模块
  • 横幅
  • 短代码
  • 菜单
  • 观感
  • 评论
  • 部署
  • 配置
  • 页头
  • 页尾
  • 側邊欄
  • 內容
  • 安裝
  • 概覽
  • 構建工具
  • 模塊
  • 橫幅
  • 短代碼
  • 菜單
  • 觀感
  • 評論
  • 開發
  • 頁尾
  • 頁頭
  • Docs
  • Examples
  • Modules
  • News
  • Showcases
  • Themes
  • Tutorials
  • 教程
  • 文档
  • 新闻
  • 模块
  • 示例
  • 文檔
  • 新聞
  • 模塊
  • Alert
  • Animations
  • AOS
  • Applications
  • asciinema
  • Authors
  • Autoprefixer
  • Back to top
  • Background Image
  • beian
  • Bigger Picture
  • Bilibili
  • Blog
  • Bootstrap
  • Breadcrumb
  • Breakpoint
  • Classic
  • clean
  • Clearfix
  • Cloudflare Pages
  • Code Block Panel
  • CodePen
  • Comments
  • Comments Engine
  • Config Toggle
  • Contact
  • Contact Form
  • Content Panel
  • CSS
  • Dark Mode
  • defaultContentLanguageInSubdir
  • Diagrams
  • Disqus
  • Docker
  • Docs
  • DocSearch
  • Domain
  • Featured Image
  • Figure
  • Fonts
  • Footer
  • Footer Menus
  • frame
  • Gallery
  • GCSE
  • Giscus
  • Gist
  • Git
  • GitHub Pages
  • Go
  • Google
  • Google Fonts
  • graph
  • Header
  • Header Menus
  • Heading Sign
  • Highlight
  • HLS
  • Hooks
  • HTML
  • Hugo
  • Icon
  • iframe
  • Image
  • Image Link
  • Instagram
  • Introduction
  • JavaScript
  • JS
  • JSRun
  • KaTex
  • Language Picker
  • Lead
  • Light Mode
  • Markdown
  • Menus
  • Mermaid
  • Meta
  • Module
  • MPD
  • MPEG-DASH
  • Multilingual
  • NetEase Could Music
  • Netlify
  • News
  • Node.js
  • noscript
  • NPM
  • Pagination
  • Param
  • Picture
  • Pills
  • PostCSS
  • Posts
  • Profile
  • Progress Bar
  • PurgeCSS
  • PWA
  • Ratio
  • ref
  • Related Posts
  • relref
  • Return to top
  • RTLCSS
  • Scrollbar
  • Scrollspy
  • SCSS
  • Search
  • Search Engines
  • Slide
  • Social Links
  • Socials
  • Start Page
  • Staticman
  • Style Guide
  • Syntax Highlighting
  • Table of Contents
  • Taxonomies
  • Theme
  • Themes
  • tidy
  • ToC
  • Toggle
  • Tweet
  • Twikoo
  • TypeScript
  • Utterances
  • Videos
  • Vimeo
  • YouKu
  • YouTube
  • Front Matter
  • JSON
  • TOML
  • YAML
  • 主题
  • 代码块面板
  • 优酷
  • 作者
  • 元模块
  • 公告栏
  • 内容面板
  • 内容面板模块
  • 分类
  • 分页
  • 动画
  • 博客
  • 哔哩哔哩
  • 回到顶部
  • 图库
  • 图标
  • 图片
  • 图片链接
  • 图表
  • 域名
  • 备案
  • 多语言
  • 字体
  • 幻灯片
  • 搜索
  • 文档
  • 文章
  • 断点
  • 新闻
  • 标题链接
  • 浅色模式
  • 深色模式
  • 滚动条
  • 特色图片
  • 目录
  • 相关文章
  • 社交链接
  • 简介
  • 网易云音乐
  • 联系表单
  • 背景图片
  • 菜单
  • 视频
  • 评论
  • 评论引擎
  • 语法高亮
  • 语言选项
  • 谷歌
  • 谷歌字体
  • 返回顶部
  • 进度条
  • 钩子
  • 面包屑导航
  • 页头
  • 页头菜单
  • 页尾
  • 页尾菜单
  • 风格指南
  • 主題
  • 代碼塊面板
  • 備案
  • 優酷
  • 元模塊
  • 內容面板
  • 內容面板模塊
  • 公告欄
  • 分頁
  • 分類
  • 動畫
  • 嗶哩嗶哩
  • 回到頂部
  • 圖庫
  • 圖標
  • 圖片
  • 圖片鏈接
  • 圖表
  • 多語言
  • 字體
  • 幻燈片
  • 文檔
  • 新聞
  • 斷點
  • 標題鏈接
  • 淺色模式
  • 滾動條
  • 特色圖片
  • 目錄
  • 相關文章
  • 社交鏈接
  • 簡介
  • 網易雲音樂
  • 聯繫表單
  • 背景圖片
  • 菜單
  • 視頻
  • 評論
  • 評論引擎
  • 語法高亮
  • 語言選項
  • 谷歌字體
  • 返回頂部
  • 進度條
  • 鉤子
  • 頁尾
  • 頁尾菜單
  • 頁頭
  • 頁頭菜單
  • 風格指南
  • 麪包屑導航