HUGO

  • 新闻
  • 文档
  • 主题
  • 作品展示
  • 社区
  • GitHub
    • English
    • 中文

What's on this Page

  • 创建你的叉
  • 添加新内容
    • 添加新功能
  • 添加代码块
    • 标准语法
    • 代码块简码
    • code
  • 引用文字
  • 忠告
    • note 训诫
    • tip 训诫
    • warning Admonition
CONTRIBUTE

贡献Hugo文档

文档资料是任何开源项目的一个组成部分。Hugo文档都在,因为它试图覆盖源进步很多工作。

创建你的叉

It’s best to make changes to the Hugo docs on your local machine to check for consistent visual styling. Make sure you’ve created a fork of hugoDocs on GitHub and cloned the repository locally on your machine. For more information, you can see GitHub’s documentation on “forking” or follow along with Hugo’s development contribution guide.

You can then create a separate branch for your additions. Be sure to choose a descriptive branch name that best fits the type of content. The following is an example of a branch name you might use for adding a new website to the showcase:

git checkout -b jon-doe-showcase-addition

添加新内容

The Hugo docs make heavy use of Hugo’s archetypes feature. All content sections in Hugo documentation have an assigned archetype.

Adding new content to the Hugo docs follows the same pattern, regardless of the content section:

hugo new <DOCS-SECTION>/<new-content-lowercase>.md

添加新功能

Once you have cloned the Hugo repository, you can create a new function via the following command. Keep the file name lowercase.

hugo new functions/newfunction.md

The archetype for functions according to the Hugo docs is as follows:

archetypes/functions.md

---
linktitle: ""
description: ""
godocref: ""
publishdate: ""
lastmod: ""
categories: [functions]
tags: []
ns: ""
signature: []
workson: []
hugoversion: ""
aliases: []
relatedfuncs: []
toc: false
deprecated: false
---

新功能必填字段

Here is a review of the front matter fields automatically generated for you using hugo new functions/*:

title
this will be auto-populated in all lowercase when you use hugo new generator.
linktitle
the function’s actual casing (e.g., replaceRE rather than replacere).
description
a brief description used to populate the Functions Quick Reference.
categories
currently auto-populated with ‘functions` for future-proofing and portability reasons only; ignore this field.
tags
only if you think it will help end users find other related functions
signature
this is a signature/syntax definition for calling the function (e.g., apply SEQUENCE FUNCTION [PARAM...]).
workson
acceptable values include lists,taxonomies, terms, groups, and files.
hugoversion
the version of Hugo that will ship with this new function.
relatedfuncs
other [templating functions][] you feel are related to your new function to help fellow Hugo users.
{{.Content}}
an extended description of the new function; examples are not only welcomed but encouraged.

In the body of your function, expand the short description used in the front matter. Include as many examples as possible, and leverage the Hugo docs code shortcode. If you are unable to add examples but would like to solicit help from the Hugo community, add needsexample: true to your front matter.

添加代码块

Code blocks are crucial for providing examples of Hugo’s new features to end users of the Hugo docs. Whenever possible, create examples that you think Hugo users will be able to implement in their own projects.

标准语法

Across many pages on the Hugo docs, the typical triple-back-tick markdown syntax (```) is used. If you do not want to take the extra time to implement the following code block shortcodes, please use standard GitHub-flavored markdown. The Hugo docs use a version of highlight.js with a specific set of languages.

Your options for languages are xml/html, go/golang, md/markdown/mkd, handlebars, apache, toml, yaml, json, css, asciidoc, ruby, powershell/ps, scss, sh/zsh/bash/git, http/https, and javascript/js.

```
<h1>Hello world!</h1>
```

代码块简码

The Hugo documentation comes with a very robust shortcode for adding interactive code blocks.

With the code shortcodes, you must include triple back ticks and a language declaration. This was done by design so that the shortcode wrappers were easily added to legacy documentation and will be that much easier to remove if needed in future versions of the Hugo docs.

code

code is the Hugo docs shortcode you’ll use most often. code requires has only one named parameter: file. Here is the pattern:

{{% code file="smart/file/name/with/path.html" download="download.html" copy="true" %}}
A whole bunch of coding going on up in here!
{{% /code %}}

The following are the arguments passed into code:

file
the only required argument. file is needed for styling but also plays an important role in helping users create a mental model around Hugo’s directory structure. Visually, this will be displayed as text in the top left of the code block.
download
if omitted, this will have no effect on the rendered shortcode. When a value is added to download, it’s used as the filename for a downloadable version of the code block.
copy
a copy button is added automatically to all code shortcodes. If you want to keep the filename and styling of code but don’t want to encourage readers to copy the code (e.g., a “Do not do” snippet in a tutorial), use copy="false".

例 code 输入

This example HTML code block tells Hugo users the following:

  1. This file could live in layouts/_default, as demonstrated by layouts/_default/single.html as the value for file.
  2. This snippet is complete enough to be downloaded and implemented in a Hugo project, as demonstrated by download="single.html".
{{< code file="layouts/_default/single.html" download="single.html" >}}
{{ define "main" }}
<main>
    <article>
        <header>
            <h1>{{.Title}}</h1>
            {{with .Params.subtitle}}
            <span>{{.}}</span>
        </header>
        <div>
            {{.Content}}
        </div>
        <aside>
            {{.TableOfContents}}
        </aside>
    </article>
</main>
{{ end }}
{{< /code >}}
例 ‘code’ 显示

The output of this example will render to the Hugo docs as follows:

layouts/_default/single.html

{{ define "main" }}
<main>
    <article>
        <header>
            <h1>{{.Title}}</h1>
            {{with .Params.subtitle}}
            <span>{{.}}</span>
        </header>
        <div>
            {{.Content}}
        </div>
        <aside>
            {{.TableOfContents}}
        </aside>
    </article>
</main>
{{ end }}

引用文字

Blockquotes can be added to the Hugo documentation using typical Markdown blockquote syntax:

> Without the threat of punishment, there is no joy in flight.

The preceding blockquote will render as follows in the Hugo docs:

Without the threat of punishment, there is no joy in flight.

However, you can add a quick and easy <cite> element (added on the client via JavaScript) by separating your main blockquote and the citation with a hyphen with a single space on each side:

> Without the threat of punishment, there is no joy in flight. - [Kobo Abe](https://en.wikipedia.org/wiki/Kobo_Abe)

Which will render as follows in the Hugo docs:

Without the threat of punishment, there is no joy in flight. - Kobo Abe

Previous versions of Hugo documentation used blockquotes to draw attention to text. This is not the intended semantic use of <blockquote>. Use blockquotes when quoting. To note or warn your user of specific information, use the admonition shortcodes that follow.

忠告

Admonitions are common in technical documentation. The most popular is that seen in reStructuredText Directives. From the SourceForge documentation:

Admonitions are specially marked “topics” that can appear anywhere an ordinary body element can. They contain arbitrary body elements. Typically, an admonition is rendered as an offset block in a document, sometimes outlined or shaded, with a title matching the admonition type. - SourceForge

The Hugo docs contain three admonitions: note, tip, and warning.

note 训诫

Use the note shortcode when you want to draw attention to information subtly. note is intended to be less of an interruption in content than is warning.

例 note 输入

note-with-heading.md

{{% note %}}
Here is a piece of information I would like to draw your **attention** to.
{{% /note %}}

例 note 输出

note-with-heading.html


<aside class="admonition note">
	<div class="note-icon">
		
	</div>
	
	
	<div class="admonition-content"><p>Here is a piece of information I would like to draw your <strong>attention</strong> to.</p>
</div>
</aside>

例 note 显示

Here is a piece of information I would like to draw your attention to.

tip 训诫

Use the tip shortcode when you want to give the reader advice. tip, like note, is intended to be less of an interruption in content than is warning.

例 tip 输入

using-tip.md

{{% tip %}}
Here's a bit of advice to improve your productivity with Hugo.
{{% /tip %}}

例 tip 输出

tip-output.html


<aside class="admonition tip">
	<div class="tip-icon">
		
	</div>
	
	
	<div class="admonition-content"><p>Here&rsquo;s a bit of advice to improve your productivity with Hugo.</p>
</div>
</aside>

例 tip 显示

Here’s a bit of advice to improve your productivity with Hugo.

warning Admonition

Use the warning shortcode when you want to draw the user’s attention to something important. A good usage example is for articulating breaking changes in Hugo versions, known bugs, or templating “gotchas.”

Example warning Input

warning-admonition-input.md

{{% warning %}}
This is a warning, which should be reserved for *important* information like breaking changes.
{{% /warning %}}

Example warning Output

warning-admonition-output.html


<aside class="admonition warning">
	<div class="admonition-icon">
		
	</div>
	
	
	<div class="admonition-content"><p>This is a warning, which should be reserved for <em>important</em> information like breaking changes.</p>
</div>
</aside>

Example warning Display

This is a warning, which should be reserved for important information like breaking changes.

Similar to contributing to Hugo development, the Hugo team expects you to create a separate branch/fork when you make your contributions to the Hugo docs.

See Also

  • 添加您的Hugo主题到作品展示
  • 关于 Hugo
    • 概述
    • Hugo的安全模型
    • Hugo and GDPR
    • 什么是Hugo
    • Hugo 特征
    • 静态的好处
    • 证书
  • 入门
    • 入门概述
    • 快速开始
    • 安装 Hugo
    • 基本用法
    • 目录结构
    • 配置
    • 外部学习资源
  • Hugo 模块
    • Hugo 模块概述
    • 配置模块
    • 使用Hugo模块
    • 主题组件
  • 内容管理
    • 内容管理概述
    • 组织
    • 捆绑页
    • 内容格式
    • 前面的问题
    • 构建选项
    • 网页资源
    • 图像处理
    • 简码
    • 相关内容
    • 章节
    • 内容类型
    • 原型
    • 分类
    • 摘要
    • 链接和交叉引用
    • URL管理
    • 菜单
    • 目录
    • 静态文件
    • 注释
    • 多种语言 和 国际化
    • 语法高亮
  • 模板
    • 模板概述
    • 介绍
    • 模板查找顺序
    • 自定义输出格式
    • 基本模板和模块
    • 列表页面模板
    • 首页模板
    • 章节模板
    • 分类模板
    • 单页模板
    • 内容视图模板
    • 数据模板
    • 部件模板
    • 简码模板
    • 本地文件模板
    • 404页
    • 菜单模板
    • 分页
    • RSS 模板
    • 网站地图模板
    • Robots.txt
    • 内置模板
    • 另类模板
    • 模板调试
  • 函数
    • 函数快速参考
    • .AddDate
    • .Format
    • .Get
    • .GetPage
    • .HasMenuCurrent
    • .IsMenuCurrent
    • .Param
    • .Render
    • .RenderString
    • .Scratch
    • .Unix
    • absLangURL
    • absURL
    • after
    • anchorize
    • append
    • apply
    • base64
    • chomp
    • complement
    • cond
    • countrunes
    • countwords
    • dateFormat
    • default
    • delimit
    • dict
    • echoParam
    • emojify
    • eq
    • errorf and warnf
    • fileExists
    • findRE
    • first
    • float
    • ge
    • getenv
    • group
    • gt
    • hasPrefix
    • highlight
    • htmlEscape
    • htmlUnescape
    • hugo
    • humanize
    • i18n
    • in
    • index
    • int
    • intersect
    • isset
    • jsonify
    • lang.Merge
    • lang.NumFmt
    • last
    • le
    • lower
    • lt
    • markdownify
    • Math
    • md5
    • merge
    • ne
    • now
    • os.Stat
    • partialCached
    • path.Base
    • path.Dir
    • path.Ext
    • path.Join
    • path.Split
    • plainify
    • pluralize
    • print
    • printf
    • println
    • querify
    • range
    • readDir
    • readFile
    • ref
    • reflect.IsMap
    • reflect.IsSlice
    • relLangURL
    • relref
    • relURL
    • replace
    • replaceRE
    • safeCSS
    • safeHTML
    • safeHTMLAttr
    • safeJS
    • safeURL
    • seq
    • sha
    • shuffle
    • singularize
    • slice
    • slicestr
    • sort
    • split
    • string
    • strings.HasSuffix
    • strings.Repeat
    • strings.RuneCount
    • strings.TrimLeft
    • strings.TrimPrefix
    • strings.TrimRight
    • strings.TrimSuffix
    • substr
    • symdiff
    • templates.Exists
    • time
    • title
    • transform.Unmarshal
    • trim
    • truncate
    • union
    • uniq
    • upper
    • urlize
    • urls.Parse
    • where
    • with
    • 图片函数
  • 变量
    • 变量概述
    • 网站变量
    • 简码变量
    • 页面变量
    • 页面方法
    • 分类变量
    • 文件变量
    • 菜单项属性
    • Hugo 变量
    • Git的变量
    • 网站地图变量
  • Hugo 管道
    • Hugo 管道概述
    • Hugo 管道简介
    • SASS / SCSS
    • PostCSS
    • 资产压缩
    • Asset 捆绑
    • 指纹和SRI
    • 来自模板资源
    • 从字符串资源
  • CLI
  • 故障排除
    • 疑难解答
    • FAQ
    • 构建性能
  • 工具
    • 开发工具概述
    • 迁移
    • 入门套件
    • 前端
    • 编辑器插件
    • 搜索
    • 其他的项目
  • 托管和部署
    • 托管和部署概述
    • Hugo 部署
    • 使用Nanobox的主机无关部署
    • AWS Amplify托管
    • Netlify托管
    • Render托管
    • Firebase托管
    • GitHub托管
    • GitLab托管
    • KeyCDN托管
    • Bitbucket托管
    • 使用Wercker部署
    • 使用rsync部署
  • 贡献
    • 贡献Hugo
    • 开发
    • 文档
    • 主题
  • 保养
“贡献Hugo文档” was last updated: March 24, 2020: 翻译 (91f26d0)
Improve this page
By the Hugo Authors
Hugo Logo
  • File an Issue
  • Get Help
  • Discuss Source Code
  • @GoHugoIO
  • @spf13
  • @bepsays

Netlify badge

 
 

Hugo Sponsors

Logo for Forestry.io
Logo for Linode
Logo for eSolia
 

The Hugo logos are copyright © Steve Francia 2013–2020.

The Hugo Gopher is based on an original work by Renée French.

  • 新闻
  • 文档
  • 主题
  • 作品展示
  • 社区
  • GitHub
  • 关于 Hugo
  • 入门
  • Hugo 模块
  • 内容管理
  • 模板
  • 函数
  • 变量
  • Hugo 管道
  • CLI
  • 故障排除
  • 工具
  • 托管和部署
  • 贡献
  • 保养