mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-25 15:58:53 +00:00
Make further improvements to Go Template Primer
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
title: Amber Templating
|
||||
linktitle:
|
||||
description:
|
||||
godocref: https://godoc.org/github.com/eknkc/amber
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
@@ -19,12 +20,11 @@ Amber templates are another template type which Hugo supports, in addition to [G
|
||||
|
||||
For template documentation, follow the links from the [Amber project][].
|
||||
|
||||
* Amber templates must be named with the amber-suffix, e.g. `list.amber`
|
||||
* Amber templates must be named with the Amber suffix; e.g., `list.amber`
|
||||
* Partials in Amber or HTML can be included with the Amber template syntax:
|
||||
* `import ../partials/test.html `
|
||||
* `import ../partials/test_a.amber `
|
||||
|
||||
[Ace templates]: /templates/ace-templating/
|
||||
[Amber project]: https://github.com/eknkc/amber
|
||||
[Go templates]: /templates/go-template-primer/
|
||||
|
||||
[Go templates]: /templates/go-template-primer/
|
||||
@@ -2,6 +2,7 @@
|
||||
title: Go Template Primer
|
||||
linktitle:
|
||||
description:
|
||||
godocref: https://golang.org/pkg/html/template/
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
@@ -11,6 +12,468 @@ categories: [templates]
|
||||
draft: false
|
||||
slug:
|
||||
aliases: [/templates/go-templates/]
|
||||
toc: false
|
||||
toc: true
|
||||
notes:
|
||||
---
|
||||
---
|
||||
|
||||
Hugo uses the excellent [Go html/template][] library, an extremely lightweight engine that provides just the right amount of logic to be able to create a good static website. If you have used other template systems from different languages or frameworks, you will find a lot of similarities in Go templates.
|
||||
|
||||
This document is a brief primer on using Go templates. The [Go docs][gohtmltemplate] go into more depth and cover features that aren't mentioned here.
|
||||
|
||||
## Introduction to Go Templates
|
||||
|
||||
Go templates provide an extremely simple template language. It adheres to the belief that only the most basic of logic belongs in the template or view layer. One consequence of this simplicity is that Go templates parse very quickly.
|
||||
|
||||
A unique characteristic of Go templates is they are content aware. Variables and content will be sanitized depending on the context of where they are used. More details can be found in the [Go docs][gohtmltemplate].
|
||||
|
||||
## Basic Syntax
|
||||
|
||||
Golang templates are HTML files with the addition of [variables][variablesparams] and
|
||||
[functions][].
|
||||
|
||||
**Go variables and functions are accessible within {{ }}**
|
||||
|
||||
Accessing a predefined variable "foo":
|
||||
|
||||
```golang
|
||||
{{ foo }}
|
||||
```
|
||||
|
||||
**Parameters are separated using spaces**
|
||||
|
||||
Calling the `add` function with input of 1, 2:
|
||||
|
||||
```golang
|
||||
{{ add 1 2 }}
|
||||
```
|
||||
|
||||
**Methods and fields are accessed via dot notation**
|
||||
|
||||
Accessing the Page Parameter "bar"
|
||||
|
||||
```golang
|
||||
{{ .Params.bar }}
|
||||
```
|
||||
|
||||
**Parentheses can be used to group items together**
|
||||
|
||||
```golang
|
||||
{{ if or (isset .Params "alt") (isset .Params "caption") }} Caption {{ end }}
|
||||
```
|
||||
|
||||
## Variables
|
||||
|
||||
Each Go template has a struct (object) made available to it. In Hugo, each
|
||||
template is passed page struct. More details are available in the [variables and params section][variablesparams].
|
||||
|
||||
A variable is accessed by referencing the variable name.
|
||||
|
||||
```golang
|
||||
<title>{{ .Title }}</title>
|
||||
```
|
||||
|
||||
Variables can also be defined and referenced.
|
||||
|
||||
```golang
|
||||
{{ $address := "123 Main St."}}
|
||||
{{ $address }}
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
Go template ships with a few functions which provide basic functionality. The Go template system also provides a mechanism for applications to extend the
|
||||
available functions with their own. [Hugo template functions][] provide some additional functionality we believe are useful for building websites. Functions are called by using their name followed by the required parameters separated by spaces. Template functions cannot be added without recompiling Hugo.
|
||||
|
||||
**Example 1: Adding numbers**
|
||||
|
||||
```golang
|
||||
{{ add 1 2 }}
|
||||
```
|
||||
|
||||
**Example 2: Comparing numbers**
|
||||
|
||||
```golang
|
||||
{{ lt 1 2 }}
|
||||
```
|
||||
|
||||
{{% note "Additional Boolean Operators" %}}
|
||||
There are more boolean operators than those listed in the Hugo docs in the [Golang template documentation](http://golang.org/pkg/text/template/#hdr-Functions).
|
||||
{{% /note %}}
|
||||
|
||||
## Includes
|
||||
|
||||
When including another template, you will pass to it the data it will be
|
||||
able to access. To pass along the current context, please remember to
|
||||
include a trailing dot. The templates location will always be starting at
|
||||
the /layout/ directory within Hugo.
|
||||
|
||||
**Example:**
|
||||
|
||||
{{ template "partials/header.html" . }}
|
||||
|
||||
And, starting with Hugo v0.12, you may also use the `partial` call
|
||||
for [partial templates](/templates/partials/):
|
||||
|
||||
{{ partial "header.html" . }}
|
||||
|
||||
|
||||
## Logic
|
||||
|
||||
Go templates provide the most basic iteration and conditional logic.
|
||||
|
||||
### Iteration
|
||||
|
||||
Just like in Go, the Go templates make heavy use of `range` to iterate over
|
||||
a map, array or slice. The following are different examples of how to use
|
||||
range.
|
||||
|
||||
**Example 1: Using Context**
|
||||
|
||||
```golang
|
||||
{{ range array }}
|
||||
{{ . }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
**Example 2: Declaring value variable name**
|
||||
|
||||
```golang
|
||||
{{range $element := array}}
|
||||
{{ $element }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
**Example 2: Declaring key and value variable name**
|
||||
|
||||
```golang
|
||||
{{range $index, $element := array}}
|
||||
{{ $index }}
|
||||
{{ $element }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
### Conditionals
|
||||
|
||||
`if`, `else`, `with`, `or` & `and` provide the framework for handling conditional logic in Go Templates. Like `range`, each statement is closed with an `{{end}}`.
|
||||
|
||||
Go Templates treat the following values as false:
|
||||
|
||||
* false
|
||||
* 0
|
||||
* any array, slice, map, or string of length zero
|
||||
|
||||
**Example 1: `if`**
|
||||
|
||||
```golang
|
||||
{{ if isset .Params "title" }}<h4>{{ index .Params "title" }}</h4>{{ end }}
|
||||
```
|
||||
|
||||
**Example 2: `if` … `else`**
|
||||
|
||||
```golang
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{else}}
|
||||
{{ index .Params "caption" }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
**Example 3: `and` & `or`**
|
||||
|
||||
```golang
|
||||
{{ if and (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}}
|
||||
```
|
||||
|
||||
**Example 4: `with`**
|
||||
|
||||
An alternative way of writing "`if`" and then referencing the same value
|
||||
is to use "`with`" instead. `with` rebinds the context `.` within its scope,
|
||||
and skips the block if the variable is absent.
|
||||
|
||||
The first example above could be simplified as:
|
||||
|
||||
{{ with .Params.title }}<h4>{{ . }}</h4>{{ end }}
|
||||
|
||||
**Example 5: `if` … `else if`**
|
||||
|
||||
```golang
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{ else if isset .Params "caption" }}
|
||||
{{ index .Params "caption" }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
## Pipes
|
||||
|
||||
One of the most powerful components of Go templates is the ability to stack actions one after another. This is done by using pipes. Borrowed from Unix pipes, the concept is simple, each pipeline's output becomes the input of the following pipe.
|
||||
|
||||
Because of the very simple syntax of Go templates, the pipe is essential to being able to chain together function calls. One limitation of the pipes is that they only can work with a single value and that value becomes the last parameter of the next pipeline.
|
||||
|
||||
A few simple examples should help convey how to use the pipe.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```golang
|
||||
{{ shuffle (seq 1 5) }}
|
||||
```
|
||||
|
||||
is the same as
|
||||
|
||||
```golang
|
||||
{{ (seq 1 5) | shuffle }}
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```golang
|
||||
{{ index .Params "disqus_url" | html }}
|
||||
```
|
||||
|
||||
Access the page parameter called "disqus_url" and escape the HTML.
|
||||
|
||||
The `index` function is a built in to [Go][] built-in. [You can read more about `index` in the Godocs][]. The Godocs have the following to say about`index`:
|
||||
|
||||
> ...returns the result of indexing its first argument by the following arguments. Thus "index x 1 2 3" is, in Go syntax, `x[1][2][3]`. Each indexed item must be a map, slice, or array.
|
||||
|
||||
**Example 3:**
|
||||
|
||||
{{ if or (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr") }}
|
||||
Stuff Here
|
||||
{{ end }}
|
||||
|
||||
Could be rewritten as
|
||||
|
||||
{{ if isset .Params "caption" | or isset .Params "title" | or isset .Params "attr" }}
|
||||
Stuff Here
|
||||
{{ end }}
|
||||
|
||||
### Internet Explorer conditional comments using Pipes
|
||||
|
||||
By default, Go Templates remove HTML comments from output. This has the unfortunate side effect of removing Internet Explorer conditional comments. As a workaround, use something like this:
|
||||
|
||||
{{ "<!--[if lt IE 9]>" | safeHTML }}
|
||||
<script src="html5shiv.js"></script>
|
||||
{{ "<![endif]-->" | safeHTML }}
|
||||
|
||||
Alternatively, use the backtick (`` ` ``) to quote the IE conditional comments, avoiding the tedious task of escaping every double quotes (`"`) inside, as demonstrated in the [examples](http://golang.org/pkg/text/template/#hdr-Examples) in the Go text/template documentation, e.g.:
|
||||
|
||||
```
|
||||
{{ `<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]-->` | safeHTML }}
|
||||
```
|
||||
|
||||
## Context (a.k.a. the dot)
|
||||
|
||||
The most easily overlooked concept to understand about Go templates is that `{{ . }}`
|
||||
always refers to the current context. In the top level of your template, this
|
||||
will be the data set made available to it. Inside of a iteration, however, it will have
|
||||
the value of the current item. When inside of a loop, the context has changed:
|
||||
`{{ . }}` will no longer refer to the data available to the entire page. If you need
|
||||
to
|
||||
access this from within the loop, you will likely want to do one of the following:
|
||||
|
||||
1. Set it to a variable instead of depending on the context. For example:
|
||||
|
||||
{{% input "range-through-tags-w-variable.html" %}}
|
||||
```html
|
||||
{{ $title := .Site.Title }}
|
||||
<ul class="tags">
|
||||
{{ range .Params.tags }}
|
||||
<li>
|
||||
<a href="{{ $baseURL }}/tags/{{ . | urlize }}">{{ . }}</a>
|
||||
- {{ $title }}
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
{{% /input %}}
|
||||
|
||||
{{% note %}}
|
||||
Notice how once we have entered the loop, the value of `{{ . }}` has changed. We have defined a variable outside of the loop (`{{$title}}`) so we have access to it from within the loop.
|
||||
{{% /note %}}
|
||||
|
||||
2. Use `$.` to access the global context from anywhere.
|
||||
Here is an equivalent example:
|
||||
|
||||
{{% input "range-through-tags-w-global.html" %}}
|
||||
```html
|
||||
<ul class="tags">
|
||||
{{ range .Params.tags }}
|
||||
<li>
|
||||
<a href="{{ $baseURL }}/tags/{{ . | urlize }}">{{ . }}</a>
|
||||
- {{ $.Site.Title }}
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
{{% /input %}}
|
||||
|
||||
This is because `$`, a special variable, is set to the starting value of `.` ("the dot") by default. This is a [documented feature of Go text/template][].
|
||||
|
||||
{{% warning "Don't Redefine the Dot" %}}
|
||||
The built-in magic of `$` would cease to work if someone were to mischievously redefine the special character; e.g. `{{ $ := .Site }}`. *Don't do it.* You may, of course, recover from this mischief by using `{{ $ := . }}` in a global context to reset `$` to its default value.
|
||||
{{% /warning %}}
|
||||
|
||||
## Whitespace
|
||||
|
||||
Go 1.6 includes the ability to trim the whitespace from either side of a Go tag by including a hyphen (`-`) and space immediately beside the corresponding `{{` or `}}` delimiter.
|
||||
|
||||
For instance, the following Go template:
|
||||
|
||||
```html
|
||||
<div>
|
||||
{{ .Title }}
|
||||
</div>
|
||||
```
|
||||
|
||||
will include the newlines and horizontal tab in its HTML output:
|
||||
|
||||
```html
|
||||
<div>
|
||||
Hello, World!
|
||||
</div>
|
||||
```
|
||||
|
||||
whereas using
|
||||
|
||||
```html
|
||||
<div>
|
||||
{{- .Title -}}
|
||||
</div>
|
||||
```
|
||||
|
||||
in that case will output simply
|
||||
|
||||
```html
|
||||
<div>Hello, World!</div>
|
||||
```
|
||||
|
||||
Go considers the following characters as whitespace:
|
||||
|
||||
* <kbd>space</kbd>
|
||||
* horizontal <kbd>tab</kbd>
|
||||
* carriage <kbd>return</kbd>
|
||||
* newline
|
||||
|
||||
## Hugo Parameters
|
||||
|
||||
Hugo provides the option of passing values to the template language
|
||||
through the site configuration (for sitewide values), or through the meta
|
||||
data of each specific piece of content. You can define any values of any
|
||||
type (supported by your front matter/config format) and use them however
|
||||
you want to inside of your templates.
|
||||
|
||||
|
||||
## Using Content (page) Parameters
|
||||
|
||||
In each piece of content, you can provide variables to be used by the
|
||||
templates. This happens in the [front matter](/content/front-matter/).
|
||||
|
||||
An example of this is used in this documentation site. Most of the pages
|
||||
benefit from having the table of contents provided. Sometimes the TOC just
|
||||
doesn't make a lot of sense. We've defined a variable in our front matter
|
||||
of some pages to turn off the TOC from being displayed.
|
||||
|
||||
Here is the example front matter:
|
||||
|
||||
```
|
||||
---
|
||||
title: "Permalinks"
|
||||
lastmod: 2015-11-30
|
||||
date: "2013-11-18"
|
||||
aliases:
|
||||
- "/doc/permalinks/"
|
||||
groups: ["extras"]
|
||||
groups_weight: 30
|
||||
notoc: true
|
||||
---
|
||||
```
|
||||
|
||||
Here is the corresponding code inside of the template:
|
||||
|
||||
```html
|
||||
{{ if not .Params.notoc }}
|
||||
<div id="toc" class="well col-md-4 col-sm-6">
|
||||
{{ .TableOfContents }}
|
||||
</div>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
## Using Site (config) Parameters
|
||||
|
||||
In your top-level configuration file (e.g., `config.yaml`) you can define site
|
||||
parameters, which are values which will be available to you in partials.
|
||||
|
||||
For instance, you might declare:
|
||||
|
||||
```yaml
|
||||
params:
|
||||
CopyrightHTML: "Copyright © 2013 John Doe. All Rights Reserved."
|
||||
TwitterUser: "spf13"
|
||||
SidebarRecentLimit: 5
|
||||
```
|
||||
|
||||
Within a footer layout, you might then declare a `<footer>` which is only
|
||||
provided if the `CopyrightHTML` parameter is provided, and if it is given,
|
||||
you would declare it to be HTML-safe, so that the HTML entity is not escaped
|
||||
again. This would let you easily update just your top-level config file each
|
||||
January 1st, instead of hunting through your templates.
|
||||
|
||||
```
|
||||
{{if .Site.Params.CopyrightHTML}}<footer>
|
||||
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHTML}}</div>
|
||||
</footer>{{end}}
|
||||
```
|
||||
|
||||
An alternative way of writing the "`if`" and then referencing the same value
|
||||
is to use "`with`" instead. With rebinds the context `.` within its scope,
|
||||
and skips the block if the variable is absent:
|
||||
|
||||
```
|
||||
{{with .Site.Params.TwitterUser}}<span class="twitter">
|
||||
<a href="https://twitter.com/{{.}}" rel="author">
|
||||
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}"
|
||||
alt="Twitter"></a>
|
||||
</span>{{end}}
|
||||
```
|
||||
|
||||
Finally, if you want to pull "magic constants" out of your layouts, you can do
|
||||
so, such as in this example:
|
||||
|
||||
```
|
||||
<nav class="recent">
|
||||
<h1>Recent Posts</h1>
|
||||
<ul>{{range first .Site.Params.SidebarRecentLimit .Site.Pages}}
|
||||
<li><a href="{{.RelPermalink}}">{{.Title}}</a></li>
|
||||
{{end}}</ul>
|
||||
</nav>
|
||||
```
|
||||
|
||||
## Template example: Show only upcoming events
|
||||
|
||||
Go allows you to do more than what's shown here. Using Hugo's [`where` function][] and Go built-ins, we can list only the items from `content/events/` whose date (set in the front matter) is in the future:
|
||||
|
||||
{{% input "show-upcoming-dates.html" %}}
|
||||
```golang
|
||||
<h4>Upcoming Events</h4>
|
||||
<ul class="upcoming-events">
|
||||
{{ range where .Data.Pages.ByDate "Section" "events" }}
|
||||
{{ if ge .Date.Unix .Now.Unix }}
|
||||
<li><span class="event-type">{{ .Type | title }} —</span>
|
||||
{{ .Title }}
|
||||
on <span class="event-date">
|
||||
{{ .Date.Format "2 January at 3:04pm" }}</span>
|
||||
at {{ .Params.place }}
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
{{% /input %}}
|
||||
|
||||
[documented feature of Go text/template]: http://golang.org/pkg/text/template/#hdr-Variables
|
||||
[Go html/template]: http://golang.org/pkg/html/template/ "Godocs references for Golang's html templating"
|
||||
[gohtmltemplate]: http://golang.org/pkg/html/template/ "Godocs references for Golang's html templating"
|
||||
[Hugo template functions]: /functions/ "Link to section for Hugo's templating functions"
|
||||
[You can read more about `index` in the Godocs]: http://golang.org/pkg/text/template/ "Godocs page for index function"
|
||||
[variablesparams]: /variables-and-params/ "Link to the list page for the Variables and Params section of the site."
|
||||
[`where` function]: /functions/where/
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,6 +1,7 @@
|
||||
---
|
||||
linktitle:
|
||||
description: ""
|
||||
godocref: ""
|
||||
publishdate: ""
|
||||
lastmod: ""
|
||||
categories: []
|
||||
@@ -10,5 +11,5 @@ draft: true
|
||||
slug: ""
|
||||
aliases: []
|
||||
toc: false
|
||||
notes: Categories are not required metadata as of February 2017.
|
||||
notes: "Categories are not required metadata as of February 2017.""
|
||||
---
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
linktitle: ""
|
||||
expirydate: ""
|
||||
description: ""
|
||||
godocref: ""
|
||||
publishdate: ""
|
||||
lastmod: ""
|
||||
description: ""
|
||||
draft: false
|
||||
tags: []
|
||||
categories: ["functions"]
|
||||
aliases: []
|
||||
categories: [functions]
|
||||
toc: false
|
||||
notes: Some notes on this function.
|
||||
draft: false
|
||||
aliases: []
|
||||
notes:
|
||||
---
|
||||
@@ -1,5 +1,6 @@
|
||||
// Keywords and other highlight in this script have been modified for better selection of Hugo-specific keywords
|
||||
/*! highlight.js v9.9.0 | BSD3 License | git.io/hljslicense */ ! function(e) {
|
||||
/*! highlight.js v9.9.0 | BSD3 License | git.io/hljslicense */
|
||||
! function(e) {
|
||||
var n = "object" == typeof window && window || "object" == typeof self && self;
|
||||
"undefined" != typeof exports ? e(exports) : n && (n.hljs = e({}), "function" == typeof define && define.amd && define([], function() {
|
||||
return n.hljs
|
||||
@@ -268,6 +269,10 @@ hljs.registerLanguage("xml", function(s) {
|
||||
t = { eW: !0, i: /</, r: 0, c: [{ cN: "attr", b: e, r: 0 }, { b: /=\s*/, r: 0, c: [{ cN: "string", endsParent: !0, v: [{ b: /"/, e: /"/ }, { b: /'/, e: /'/ }, { b: /[^\s"'=<>`]+/ }] }] }] };
|
||||
return { aliases: ["html", "xhtml", "rss", "atom", "xjb", "xsd", "xsl", "plist"], cI: !0, c: [{ cN: "meta", b: "<!DOCTYPE", e: ">", r: 10, c: [{ b: "\\[", e: "\\]" }] }, s.C("<!--", "-->", { r: 10 }), { b: "<\\!\\[CDATA\\[", e: "\\]\\]>", r: 10 }, { b: /<\?(php)?/, e: /\?>/, sL: "php", c: [{ b: "/\\*", e: "\\*/", skip: !0 }] }, { cN: "tag", b: "<style(?=\\s|>|$)", e: ">", k: { name: "style" }, c: [t], starts: { e: "</style>", rE: !0, sL: ["css", "xml"] } }, { cN: "tag", b: "<script(?=\\s|>|$)", e: ">", k: { name: "script" }, c: [t], starts: { e: "</script>", rE: !0, sL: ["actionscript", "javascript", "handlebars", "xml"] } }, { cN: "meta", v: [{ b: /<\?xml/, e: /\?>/, r: 10 }, { b: /<\?\w+/, e: /\?>/ }] }, { cN: "tag", b: "</?", e: "/?>", c: [{ cN: "name", b: /[^\/><\s]+/, r: 0 }, t] }] }
|
||||
});
|
||||
hljs.registerLanguage("go", function(e) {
|
||||
var t = { keyword: "break default func interface select case map struct chan else goto package switch const fallthrough if range end type continue for import return var go defer bool byte complex64 complex128 float32 float64 int8 int16 int32 int64 string uint8 uint16 uint32 uint64 int uint uintptr rune id autoplay Get", literal: "true false iota nil Pages with", built_in: "append cap close complex copy imag len make new panic print println real recover delete Site Data tweet speakerdeck youtube ref relref vimeo instagram gist figure innershortcode" };
|
||||
return { aliases: ["golang"], k: t, i: "</", c: [e.CLCM, e.CBCM, { cN: "string", v: [e.QSM, { b: "'", e: "[^\\\\]'" }, { b: "`", e: "`" }] }, { cN: "number", v: [{ b: e.CNR + "[dflsi]", r: 1 }, e.CNM] }, { b: /:=/ }, { cN: "function", bK: "func", e: /\s*\{/, eE: !0, c: [e.TM, { cN: "params", b: /\(/, e: /\)/, k: t, i: /["']/ }] }] }
|
||||
});
|
||||
hljs.registerLanguage("markdown", function(e) {
|
||||
return { aliases: ["md", "mkdown", "mkd"], c: [{ cN: "section", v: [{ b: "^#{1,6}", e: "$" }, { b: "^.+?\\n[=-]{2,}$" }] }, { b: "<", e: ">", sL: "xml", r: 0 }, { cN: "bullet", b: "^([*+-]|(\\d+\\.))\\s+" }, { cN: "strong", b: "[*_]{2}.+?[*_]{2}" }, { cN: "emphasis", v: [{ b: "\\*.+?\\*" }, { b: "_.+?_", r: 0 }] }, { cN: "quote", b: "^>\\s+", e: "$" }, { cN: "code", v: [{ b: "^```w*s*$", e: "^```s*$" }, { b: "`.+?`" }, { b: "^( {4}| )", e: "$", r: 0 }] }, { b: "^[-\\*]{3,}", e: "$" }, { b: "\\[.+?\\][\\(\\[].*?[\\)\\]]", rB: !0, c: [{ cN: "string", b: "\\[", e: "\\]", eB: !0, rE: !0, r: 0 }, { cN: "link", b: "\\]\\(", e: "\\)", eB: !0, eE: !0 }, { cN: "symbol", b: "\\]\\[", e: "\\]", eB: !0, eE: !0 }], r: 10 }, { b: /^\[[^\n]+\]:/, rB: !0, c: [{ cN: "symbol", b: /\[/, e: /\]/, eB: !0, eE: !0 }, { cN: "link", b: /:\s*/, e: /$/, eB: !0 }] }] }
|
||||
});
|
||||
@@ -288,10 +293,6 @@ hljs.registerLanguage("css", function(e) {
|
||||
t = { b: /[A-Z\_\.\-]+\s*:/, rB: !0, e: ";", eW: !0, c: [{ cN: "attribute", b: /\S/, e: ":", eE: !0, starts: { eW: !0, eE: !0, c: [{ b: /[\w-]+\(/, rB: !0, c: [{ cN: "built_in", b: /[\w-]+/ }, { b: /\(/, e: /\)/, c: [e.ASM, e.QSM] }] }, e.CSSNM, e.QSM, e.ASM, e.CBCM, { cN: "number", b: "#[0-9A-Fa-f]+" }, { cN: "meta", b: "!important" }] } }] };
|
||||
return { cI: !0, i: /[=\/|'\$]/, c: [e.CBCM, { cN: "selector-id", b: /#[A-Za-z0-9_-]+/ }, { cN: "selector-class", b: /\.[A-Za-z0-9_-]+/ }, { cN: "selector-attr", b: /\[/, e: /\]/, i: "$" }, { cN: "selector-pseudo", b: /:(:)?[a-zA-Z0-9\_\-\+\(\)"'.]+/ }, { b: "@(font-face|page)", l: "[a-z-]+", k: "font-face page" }, { b: "@", e: "[{;]", i: /:/, c: [{ cN: "keyword", b: /\w+/ }, { b: /\s/, eW: !0, eE: !0, r: 0, c: [e.ASM, e.QSM, e.CSSNM] }] }, { cN: "selector-tag", b: c, r: 0 }, { b: "{", e: "}", i: /\S/, c: [e.CBCM, t] }] }
|
||||
});
|
||||
hljs.registerLanguage("go", function(e) {
|
||||
var t = { keyword: "break default func interface select case map struct chan else goto package switch const fallthrough if range end type continue for import return var go defer bool byte complex64 complex128 float32 float64 int8 int16 int32 int64 string uint8 uint16 uint32 uint64 int uint uintptr rune id autoplay Get", literal: "true false iota nil Pages with", built_in: "append cap close complex copy imag len make new panic print println real recover delete Site Data tweet speakerdeck youtube ref relref vimeo instagram gist figure innershortcode" };
|
||||
return { aliases: ["golang"], k: t, i: "</", c: [e.CLCM, e.CBCM, { cN: "string", v: [e.QSM, { b: "'", e: "[^\\\\]'" }, { b: "`", e: "`" }] }, { cN: "number", v: [{ b: e.CNR + "[dflsi]", r: 1 }, e.CNM] }, { b: /:=/ }, { cN: "function", bK: "func", e: /\s*\{/, eE: !0, c: [e.TM, { cN: "params", b: /\(/, e: /\)/, k: t, i: /["']/ }] }] }
|
||||
});
|
||||
hljs.registerLanguage("asciidoc", function(e) {
|
||||
return { aliases: ["adoc"], c: [e.C("^/{4,}\\n", "\\n/{4,}$", { r: 10 }), e.C("^//", "$", { r: 0 }), { cN: "title", b: "^\\.\\w.*$" }, { b: "^[=\\*]{4,}\\n", e: "\\n^[=\\*]{4,}$", r: 10 }, { cN: "section", r: 10, v: [{ b: "^(={1,5}) .+?( \\1)?$" }, { b: "^[^\\[\\]\\n]+?\\n[=\\-~\\^\\+]{2,}$" }] }, { cN: "meta", b: "^:.+?:", e: "\\s", eE: !0, r: 10 }, { cN: "meta", b: "^\\[.+?\\]$", r: 0 }, { cN: "quote", b: "^_{4,}\\n", e: "\\n_{4,}$", r: 10 }, { cN: "code", b: "^[\\-\\.]{4,}\\n", e: "\\n[\\-\\.]{4,}$", r: 10 }, { b: "^\\+{4,}\\n", e: "\\n\\+{4,}$", c: [{ b: "<", e: ">", sL: "xml", r: 0 }], r: 10 }, { cN: "bullet", b: "^(\\*+|\\-+|\\.+|[^\\n]+?::)\\s+" }, { cN: "symbol", b: "^(NOTE|TIP|IMPORTANT|WARNING|CAUTION):\\s+", r: 10 }, { cN: "strong", b: "\\B\\*(?![\\*\\s])", e: "(\\n{2}|\\*)", c: [{ b: "\\\\*\\w", r: 0 }] }, { cN: "emphasis", b: "\\B'(?!['\\s])", e: "(\\n{2}|')", c: [{ b: "\\\\'\\w", r: 0 }], r: 0 }, { cN: "emphasis", b: "_(?![_\\s])", e: "(\\n{2}|_)", r: 0 }, { cN: "string", v: [{ b: "``.+?''" }, { b: "`.+?'" }] }, { cN: "code", b: "(`.+?`|\\+.+?\\+)", r: 0 }, { cN: "code", b: "^[ \\t]", e: "$", r: 0 }, { b: "^'{3,}[ \\t]*$", r: 10 }, { b: "(link:)?(http|https|ftp|file|irc|image:?):\\S+\\[.*?\\]", rB: !0, c: [{ b: "(link|image:?):", r: 0 }, { cN: "link", b: "\\w", e: "[^\\[]+", r: 0 }, { cN: "string", b: "\\[", e: "\\]", eB: !0, eE: !0, r: 0 }], r: 10 }] }
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ aside#toc {
|
||||
max-width: 280px;
|
||||
min-width: 200px;
|
||||
overflow-y: scroll;
|
||||
max-height: calc(100vh - #{$site-header-height} - 40px);
|
||||
padding: {
|
||||
left: .5em;
|
||||
right: .5em;
|
||||
@@ -46,7 +47,6 @@ aside#toc {
|
||||
min-height: calc(100vh - #{$site-header-height});
|
||||
max-height: calc(100vh - #{$site-header-height});
|
||||
transform: scale(1);
|
||||
overflow-y: scroll;
|
||||
border-left: 1px solid $hugo-gray-light;
|
||||
border-radius: 0px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user