mirror of
https://github.com/dillonzq/LoveIt.git
synced 2024-11-12 18:06:17 +01:00
Minor changes
This commit is contained in:
parent
0396b84fe6
commit
b5ac0e87dc
11 changed files with 474 additions and 76 deletions
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Giuseppe Pignataro.
|
||||
Copyright (c) 2018 LIUZHICHAO.COM
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
|
|
@ -15,9 +15,7 @@ To see this theme in action, Here is a live [demo site](https://www.fsb01.com)
|
|||
* A More coerent style beetwen page and sections
|
||||
* Multilanguage support.
|
||||
* Added configuration file for use on [Netlify](https://www.netlify.com)
|
||||
* Reading Time
|
||||
* Dark/Light mode
|
||||
* Word Count
|
||||
* Dark/Light mode
|
||||
* Wrap Image with Figure Tag without Shortcode. Thanks [Junian.Net](https://www.junian.net/hugo-image-figure-wrap/)
|
||||
* Load images with Lazy Load By [lazysizes](https://github.com/aFarkas/lazysizes)
|
||||
* Automatically highlighting code By [Google code-prettify](https://github.com/google/code-prettify), Customizable styles via CSS. See the [themes gallery](https://rawgit.com/google/code-prettify/master/styles/index.html).
|
||||
|
|
|
@ -4,9 +4,7 @@ date: {{ .Date }}
|
|||
draft: true
|
||||
description:
|
||||
categories:
|
||||
-
|
||||
tags:
|
||||
-
|
||||
-
|
||||
featured_image:
|
||||
author: ""
|
||||
---
|
||||
---
|
|
@ -38,6 +38,11 @@ googleAnalytics = ""
|
|||
url = "/categories/"
|
||||
weight = 3
|
||||
|
||||
[[menu.main]]
|
||||
name = "About"
|
||||
url = "/about"
|
||||
weight = 4
|
||||
|
||||
[params]
|
||||
since = 2012
|
||||
author = "Fastbyte01" # Author's name
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
+++
|
||||
title = "About Hugo"
|
||||
title = "About"
|
||||
date = "2014-04-09"
|
||||
menu = "main"
|
||||
aliases = ["about-us","about-hugo","contact"]
|
||||
[ author ]
|
||||
name = "Hugo Authors"
|
||||
+++
|
||||
|
||||
Hugo is the **world’s fastest framework for building websites**. It is written in Go.
|
||||
|
|
17
exampleSite/content/posts/creating-a-new-theme.md
Executable file → Normal file
17
exampleSite/content/posts/creating-a-new-theme.md
Executable file → Normal file
|
@ -1,11 +1,18 @@
|
|||
---
|
||||
title: Creating a New Theme
|
||||
author: "Michael Henderson"
|
||||
tags: ["Theme", "Hugo"]
|
||||
categories: ["Uncategorized"]
|
||||
author:
|
||||
name: "Michael Henderson"
|
||||
date: 2014-09-28
|
||||
linktitle: Creating a New Theme
|
||||
type:
|
||||
- post
|
||||
- posts
|
||||
title: Creating a New Theme
|
||||
weight: 10
|
||||
series:
|
||||
- Hugo 101
|
||||
---
|
||||
|
||||
|
||||
## Introduction
|
||||
|
||||
This tutorial will show you how to create a simple theme in Hugo. I assume that you are familiar with HTML, the bash command line, and that you are comfortable using Markdown to format content. I'll explain how Hugo uses templates and how you can organize your templates to create a theme. I won't cover using CSS to style your theme.
|
||||
|
@ -22,7 +29,7 @@ $ echo this is a command
|
|||
this is a command
|
||||
|
||||
## edit the file
|
||||
$vi foo.md
|
||||
$ vi foo.md
|
||||
+++
|
||||
date = "2014-09-28"
|
||||
title = "creating a new theme"
|
||||
|
|
352
exampleSite/content/posts/goisforlovers.fr.md
Normal file
352
exampleSite/content/posts/goisforlovers.fr.md
Normal file
|
@ -0,0 +1,352 @@
|
|||
+++
|
||||
categories = ["Go"]
|
||||
date = "2014-04-02"
|
||||
description = ""
|
||||
featured = "pic02.jpg"
|
||||
featuredalt = ""
|
||||
featuredpath = "date"
|
||||
linktitle = ""
|
||||
slug = "Introduction aux modeles Hugo"
|
||||
title = "Introduction aux modèles (Hu)go"
|
||||
type = ["posts","post"]
|
||||
[ author ]
|
||||
name = "Michael Henderson"
|
||||
+++
|
||||
|
||||
Hugo utilise l'excellente librairie [go][] [html/template][gohtmltemplate] pour
|
||||
son moteur de modèles. c'est un moteur extrêmement léger qui offre un très petit
|
||||
nombre de fonctions logiques. À notre expérience, c'est juste ce qu'il faut pour
|
||||
créer un bon site web statique. Si vous avez déjà utilisé d'autre moteurs de
|
||||
modèles pour différents langages ou frameworks, vous allez retrouver beaucoup de
|
||||
similitudes avec les modèles go.
|
||||
|
||||
Ce document est une introduction sur l'utilisation de Go templates. La
|
||||
[documentation go][gohtmltemplate] fourni plus de détails.
|
||||
|
||||
## Introduction aux modèles Go
|
||||
|
||||
Go templates fournit un langage de modèles très simple. Il adhère à la
|
||||
conviction que les modèles ou les vues doivent avoir une logique des plus
|
||||
élémentaires. L'une des conséquences de cette simplicité est que les modèles
|
||||
seront plus rapides a être analysés.
|
||||
|
||||
Une caractéristique unique de Go templates est qu'il est conscient du contenu.
|
||||
Les variables et le contenu va être nettoyé suivant le contexte d'utilisation.
|
||||
Plus de détails sont disponibles dans la [documentation go][gohtmltemplate].
|
||||
|
||||
## Syntaxe basique
|
||||
|
||||
Les modèles en langage Go sont des fichiers HTML avec l'ajout de variables et
|
||||
fonctions.
|
||||
|
||||
**Les variables Go et les fonctions sont accessibles avec {{ }}**
|
||||
|
||||
|
||||
Accès à une variable prédéfinie "foo":
|
||||
|
||||
{{ foo }}
|
||||
|
||||
**Les paramètres sont séparés par des espaces**
|
||||
|
||||
Appel de la fonction add avec 1 et 2 en argument**
|
||||
|
||||
{{ add 1 2 }}
|
||||
|
||||
**Les méthodes et les champs sont accessibles par un point**
|
||||
|
||||
Accès au paramètre de la page "bar"
|
||||
|
||||
{{ .Params.bar }}
|
||||
|
||||
**Les parenthèses peuvent être utilisées pour grouper des éléments ensemble**
|
||||
```
|
||||
{{ if or (isset .Params "alt") (isset .Params "caption") }} Caption {{ end }}
|
||||
```
|
||||
|
||||
## Variables
|
||||
|
||||
Chaque modèle go a une structure (objet) mis à sa disposition. Avec Hugo, à
|
||||
chaque modèle est passé soit une page, soit une structure de nœud, suivant quel
|
||||
type de page vous rendez. Plus de détails sont disponibles sur la page des
|
||||
[variables](/layout/variables).
|
||||
|
||||
Une variable est accessible par son nom.
|
||||
|
||||
<title>{{ .Title }}</title>
|
||||
|
||||
Les variables peuvent également être définies et appelées.
|
||||
|
||||
{{ $address := "123 Main St."}}
|
||||
{{ $address }}
|
||||
|
||||
|
||||
## Functions
|
||||
|
||||
Go templace est livré avec quelques fonctions qui fournissent des
|
||||
fonctionnalités basiques. Le système de Go template fourni également un
|
||||
mécanisme permettant aux applications d'étendre les fonctions disponible. Les
|
||||
[fonctions de modèle Hugo](/layout/functions) fourni quelques fonctionnalités
|
||||
supplémentaires que nous espérons qu'elles seront utiles pour vos sites web.
|
||||
Les functions sont appelées en utilisant leur nom suivi par les paramètres
|
||||
requis séparés par des espaces. Des fonctions de modèles ne peuvent pas être
|
||||
ajoutées sans recompiler Hugo.
|
||||
|
||||
**Exemple:**
|
||||
|
||||
{{ add 1 2 }}
|
||||
|
||||
## Inclusions
|
||||
|
||||
Lorsque vous incluez un autre modèle, vous devez y passer les données qu'il sera
|
||||
en mesure d'accèder. Pour passer le contexte actuel, pensez à ajouter un point.
|
||||
La localisation du modèle sera toujours à partir du répertoire /layout/ dans
|
||||
Hugo.
|
||||
|
||||
**Exemple:**
|
||||
|
||||
{{ template "chrome/header.html" . }}
|
||||
|
||||
|
||||
## Logique
|
||||
|
||||
Go templates fourni les itérations et la logique conditionnèle des plus basique.
|
||||
|
||||
### Itération
|
||||
|
||||
Comme en go, les modèles go utilisent fortement *range* pour itérer dans une
|
||||
map, un array ou un slice. Les exemples suivant montre différentes façons
|
||||
d'utiliser *range*
|
||||
|
||||
**Exemple 1: En utilisant le context**
|
||||
|
||||
{{ range array }}
|
||||
{{ . }}
|
||||
{{ end }}
|
||||
|
||||
**Exemple 2: En déclarant un nom de variable**
|
||||
|
||||
{{range $element := array}}
|
||||
{{ $element }}
|
||||
{{ end }}
|
||||
|
||||
**Exemple 2: En déclarant un nom de varialbe pour la clé et la valeur**
|
||||
|
||||
{{range $index, $element := array}}
|
||||
{{ $index }}
|
||||
{{ $element }}
|
||||
{{ end }}
|
||||
|
||||
### Conditions
|
||||
|
||||
*If*, *else*, *with*, *or*, *&*, *and* fournissent la base pour la logique
|
||||
conditionnelle avec Go templates. Comme *range*, chaque déclaration est fermé
|
||||
avec `end`.
|
||||
|
||||
Go templates considère les valeurs suivante comme *false* :
|
||||
|
||||
* false
|
||||
* 0
|
||||
* tout array, slice, map ou chaine d'une longueur de zéro
|
||||
|
||||
**Exemple 1: If**
|
||||
|
||||
{{ if isset .Params "title" }}<h4>{{ index .Params "title" }}</h4>{{ end }}
|
||||
|
||||
**Exemple 2: If -> Else**
|
||||
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{else}}
|
||||
{{ index .Params "caption" }}
|
||||
{{ end }}
|
||||
|
||||
**Exemple 3: And & Or**
|
||||
```
|
||||
{{ if and (or (isset .Params "title") (isset .Params "caption"))
|
||||
(isset .Params "attr")}}
|
||||
```
|
||||
**Exemple 4: With**
|
||||
|
||||
Une manière alternative d'écrire un "if" et de référencer cette même valeur est
|
||||
d'utiliser "with". Cela permet de remplacer le contexte `.` par cet valeur et
|
||||
saute le bloc si la variable est absente.
|
||||
|
||||
Le premier exemple peut être simplifié à ceci :
|
||||
|
||||
{{ with .Params.title }}<h4>{{ . }}</h4>{{ end }}
|
||||
|
||||
**Exemple 5: If -> Else If**
|
||||
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{ else if isset .Params "caption" }}
|
||||
{{ index .Params "caption" }}
|
||||
{{ end }}
|
||||
|
||||
## *Pipes*
|
||||
|
||||
L'un des composants le plus puissant de Go templates est la capacité d'empiler
|
||||
les action l'une après l'autre. Cela est fait en utilisant les *pipes*.
|
||||
Empruntés aux *pipes* unix, le concept est simple. Chaque sortie de *pipeline*
|
||||
devient l'entrée du *pipe* suivant.
|
||||
|
||||
À cause de la syntaxe très simple de Go templates, le *pipe* est essentiel pour
|
||||
être capable d'enchainer les appels de fonctions. Une limitation des *pipes*
|
||||
est qu'il ne peuvent fonctionner seulement avec une seule valeur et cette valeur
|
||||
devient le dernier paramètre du prochain *pipeline*.
|
||||
|
||||
Quelques exemples simple devrait vous aider à comprendre comment utiliser les
|
||||
*pipes*.
|
||||
|
||||
**Exemple 1 :**
|
||||
|
||||
{{ if eq 1 1 }} Same {{ end }}
|
||||
|
||||
est identique à
|
||||
|
||||
{{ eq 1 1 | if }} Same {{ end }}
|
||||
|
||||
|
||||
Il semble étrange de placer le *if* à la fin, mais il fournit une bonne
|
||||
illustration de la façon d'utiliser les tuyaux.
|
||||
|
||||
**Exemple 2 :**
|
||||
|
||||
{{ index .Params "disqus_url" | html }}
|
||||
|
||||
Accès au paramètre de page nommé "disqus_url" et échappement du HTML
|
||||
|
||||
**Exemple 3 :**
|
||||
```
|
||||
{{ if or (or (isset .Params "title") (isset .Params "caption"))
|
||||
(isset .Params "attr")}}
|
||||
Stuff Here
|
||||
{{ end }}
|
||||
```
|
||||
Peut être réécrit en
|
||||
|
||||
```
|
||||
{{ isset .Params "caption" | or isset .Params "title" |
|
||||
or isset .Params "attr" | if }}
|
||||
Stuff Here
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
## Contexte (alias. le point)
|
||||
|
||||
Le concept le plus facilement négligé pour comprendre les modèles go est que
|
||||
{{ . }} fait toujours référence au contexte actuel. Dans le plus haut niveau de
|
||||
votre modèle, ce sera l'ensemble des données mis à votre disposition. Dans une
|
||||
itération, ce sera la valeur de l'élément actuel. Enfin, dans une boucle, le
|
||||
contexte change. . ne fera plus référence aux données disponibles dans la page
|
||||
entière. Si vous avez besoin y d'accèder depuis l'intérieur d'une boucle, il est
|
||||
judicieux d'y définir comme variable au lieu de dépendre du contexte.
|
||||
|
||||
**Exemple:**
|
||||
```
|
||||
{{ $title := .Site.Title }}
|
||||
{{ range .Params.tags }}
|
||||
<li> <a href="{{ $baseurl }}/tags/{{ . | urlize }}">
|
||||
{{ . }}</a> - {{ $title }} </li>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
Notez que, une fois que nous sommes entrés dans la boucle, la valeur de
|
||||
{{ . }} a changée. Nous avons défini une variable en dehors de la boucle, afin
|
||||
d'y avoir accès dans la boucle.
|
||||
|
||||
# Les Paramètres d'Hugo
|
||||
|
||||
Hugo fournit l'option de passer des valeurs au modèle depuis la configuration du
|
||||
site, ou depuis les métadonnées de chaque partie du contenu. Vous pouvez définir
|
||||
n'importe quelle valeur de n'importe quel type (supporté par votre section
|
||||
liminaire / format de configuration) et les utiliser comme vous le souhaitez
|
||||
dans votre modèle.
|
||||
|
||||
## Utiliser les paramètres de contenu (page)
|
||||
|
||||
Dans chaque partie du contenu, vous pouvez fournir des variables pour être
|
||||
utilisées par le modèle. Cela se passe dans la
|
||||
[section liminaire](/content/front-matter).
|
||||
|
||||
Un exemple de cela est utilisé par ce site de documentation. La plupart des
|
||||
pages bénéficient de la présentation de la table des matières. Quelques fois,
|
||||
la table des matières n'a pas beaucoup de sens. Nous avons défini une variable
|
||||
dans notre section liminaire de quelques pages pour désactiver la table des
|
||||
matières.
|
||||
|
||||
Ceci est un exemple de section liminaire :
|
||||
|
||||
```
|
||||
---
|
||||
title: "Permalinks"
|
||||
date: "2013-11-18"
|
||||
aliases:
|
||||
- "/doc/permalinks/"
|
||||
groups: ["extras"]
|
||||
groups_weight: 30
|
||||
notoc: true
|
||||
---
|
||||
```
|
||||
|
||||
Ceci est le code correspondant dans le modèle :
|
||||
|
||||
{{ if not .Params.notoc }}
|
||||
<div id="toc" class="well col-md-4 col-sm-6">
|
||||
{{ .TableOfContents }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
|
||||
|
||||
## Utiliser les paramètres de site (config)
|
||||
|
||||
Dans votre configuration de plus haut niveau (ex `config.yaml`), vous pouvez
|
||||
définir des paramètres de site, dont les valeurs vous seront accessibles.
|
||||
|
||||
Pour les instances, vous pourriez délarer :
|
||||
|
||||
```yaml
|
||||
params:
|
||||
CopyrightHTML: "Copyright © 2013 John Doe. All Rights Reserved."
|
||||
TwitterUser: "spf13"
|
||||
SidebarRecentLimit: 5
|
||||
```
|
||||
|
||||
Avec un pied de page, vous devriez déclarer un `<footer>` qui est affiché
|
||||
seulement si le paramètre `CopyrightHTML` est déclaré, et si il l'est, vous
|
||||
devriez le déclarer comme HTML-safe, afin d'éviter d'échapper les entités HTML.
|
||||
Cela vous permettra de le modifier facilement dans votre configuration au lieu
|
||||
de le chercher dans votre modèle.
|
||||
|
||||
```
|
||||
{{if .Site.Params.CopyrightHTML}}<footer>
|
||||
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHtml}}</div>
|
||||
</footer>{{end}}
|
||||
```
|
||||
Une alternative au "if" et d'appeler la même valeur est d'utiliser "with". Cela
|
||||
modifiera le contexte et passera le bloc si la variable est absente :
|
||||
|
||||
```
|
||||
{{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}}
|
||||
```
|
||||
|
||||
Enfin, si vous souhaitez extraire des "constantes magiques" de vos mises en
|
||||
page, vous pouvez le faire comme dans l'exemple suivant :
|
||||
|
||||
```
|
||||
<nav class="recent">
|
||||
<h1>Recent Posts</h1>
|
||||
<ul>{{range first .Site.Params.SidebarRecentLimit .Site.Recent}}
|
||||
<li><a href="{{.RelPermalink}}">{{.Title}}</a></li>
|
||||
{{end}}</ul>
|
||||
</nav>
|
||||
```
|
||||
|
||||
|
||||
[go]: <http://golang.org/>
|
||||
[gohtmltemplate]: <http://golang.org/pkg/html/template/>
|
104
exampleSite/content/posts/goisforlovers.md
Executable file → Normal file
104
exampleSite/content/posts/goisforlovers.md
Executable file → Normal file
|
@ -1,34 +1,48 @@
|
|||
---
|
||||
title: (Hu)go Template Primer
|
||||
tags: ["go", "golang", "templates", "themes", "development"]
|
||||
categories: ["Uncategorized"]
|
||||
date: 2014-07-28
|
||||
---
|
||||
+++
|
||||
title = "(Hu)go Template Primer"
|
||||
description = ""
|
||||
type = ["posts","post"]
|
||||
tags = [
|
||||
"go",
|
||||
"golang",
|
||||
"templates",
|
||||
"themes",
|
||||
"development",
|
||||
]
|
||||
date = "2014-04-02"
|
||||
categories = [
|
||||
"Development",
|
||||
"golang",
|
||||
]
|
||||
series = ["Hugo 101"]
|
||||
[ author ]
|
||||
name = "Hugo Authors"
|
||||
+++
|
||||
|
||||
Hugo uses the excellent [go][] [html/template][gohtmltemplate] library for
|
||||
Hugo uses the excellent [Go][] [html/template][gohtmltemplate] library for
|
||||
its template engine. It is an extremely lightweight engine that provides a very
|
||||
small amount of logic. In our experience that it is 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.
|
||||
similarities in Go templates.
|
||||
|
||||
This document is a brief primer on using go templates. The [go docs][gohtmltemplate]
|
||||
This document is a brief primer on using Go templates. The [Go docs][gohtmltemplate]
|
||||
provide more details.
|
||||
|
||||
## 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.
|
||||
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
|
||||
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].
|
||||
details can be found in the [Go docs][gohtmltemplate].
|
||||
|
||||
## Basic Syntax
|
||||
|
||||
Go lang templates are html files with the addition of variables and
|
||||
functions.
|
||||
Golang templates are HTML files with the addition of variables and
|
||||
functions.
|
||||
|
||||
**Go variables and functions are accessible within {{ }}**
|
||||
|
||||
|
@ -55,7 +69,7 @@ Accessing the Page Parameter "bar"
|
|||
|
||||
## Variables
|
||||
|
||||
Each go template has a struct (object) made available to it. In hugo each
|
||||
Each Go template has a struct (object) made available to it. In hugo each
|
||||
template is passed either a page or a node struct depending on which type of
|
||||
page you are rendering. More details are available on the
|
||||
[variables](/layout/variables) page.
|
||||
|
@ -72,7 +86,7 @@ Variables can also be defined and referenced.
|
|||
|
||||
## Functions
|
||||
|
||||
Go template ship with a few functions which provide basic functionality. The go
|
||||
Go template ship 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](/layout/functions) provide some additional functionality we believe
|
||||
|
@ -100,50 +114,50 @@ the /layout/ directory within Hugo.
|
|||
|
||||
Go templates provide the most basic iteration and conditional logic.
|
||||
|
||||
### Iteration
|
||||
### Iteration
|
||||
|
||||
Just like in go, the go templates make heavy use of range to iterate over
|
||||
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**
|
||||
|
||||
{{ range array }}
|
||||
{{ range array }}
|
||||
{{ . }}
|
||||
{{ end }}
|
||||
|
||||
**Example 2: Declaring value variable name**
|
||||
|
||||
{{range $element := array}}
|
||||
{{ $element }}
|
||||
{{range $element := array}}
|
||||
{{ $element }}
|
||||
{{ end }}
|
||||
|
||||
**Example 2: Declaring key and value variable name**
|
||||
|
||||
{{range $index, $element := array}}
|
||||
{{ $index }}
|
||||
{{ $element }}
|
||||
{{ $index }}
|
||||
{{ $element }}
|
||||
{{ end }}
|
||||
|
||||
### Conditionals
|
||||
### Conditionals
|
||||
|
||||
If, else, with, or, & and provide the framework for handling conditional
|
||||
logic in Go Templates. Like range, each statement is closed with `end`.
|
||||
|
||||
|
||||
Go Templates treat the following values as false:
|
||||
Go Templates treat the following values as false:
|
||||
|
||||
* false
|
||||
* 0
|
||||
* 0
|
||||
* any array, slice, map, or string of length zero
|
||||
|
||||
**Example 1: If**
|
||||
|
||||
{{ if isset .Params "title" }}<h4>{{ index .Params "title" }}</h4>{{ end }}
|
||||
|
||||
**Example 2: If -> Else**
|
||||
**Example 2: If -> Else**
|
||||
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{else}}
|
||||
{{ index .Params "caption" }}
|
||||
|
@ -163,9 +177,9 @@ The first example above could be simplified as:
|
|||
|
||||
{{ with .Params.title }}<h4>{{ . }}</h4>{{ end }}
|
||||
|
||||
**Example 5: If -> Else If**
|
||||
**Example 5: If -> Else If**
|
||||
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{ else if isset .Params "caption" }}
|
||||
{{ index .Params "caption" }}
|
||||
|
@ -173,15 +187,15 @@ The first example above could be simplified as:
|
|||
|
||||
## Pipes
|
||||
|
||||
One of the most powerful components of go templates is the ability to
|
||||
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.
|
||||
input of the following pipe.
|
||||
|
||||
Because of the very simple syntax of go templates, the pipe is essential
|
||||
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.
|
||||
becomes the last parameter of the next pipeline.
|
||||
|
||||
A few simple examples should help convey how to use the pipe.
|
||||
|
||||
|
@ -189,7 +203,7 @@ A few simple examples should help convey how to use the pipe.
|
|||
|
||||
{{ if eq 1 1 }} Same {{ end }}
|
||||
|
||||
is the same as
|
||||
is the same as
|
||||
|
||||
{{ eq 1 1 | if }} Same {{ end }}
|
||||
|
||||
|
@ -208,16 +222,16 @@ Access the page parameter called "disqus_url" and escape the HTML.
|
|||
Stuff Here
|
||||
{{ end }}
|
||||
|
||||
Could be rewritten as
|
||||
Could be rewritten as
|
||||
|
||||
{{ isset .Params "caption" | or isset .Params "title" | or isset .Params "attr" | if }}
|
||||
Stuff Here
|
||||
Stuff Here
|
||||
{{ end }}
|
||||
|
||||
|
||||
## Context (aka. the dot)
|
||||
|
||||
The most easily overlooked concept to understand about go templates is that {{ . }}
|
||||
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 it will have
|
||||
the value of the current item. When inside of a loop the context has changed. .
|
||||
|
@ -236,24 +250,24 @@ Notice how once we have entered the loop the value of {{ . }} has changed. We
|
|||
have defined a variable outside of the loop so we have access to it from within
|
||||
the loop.
|
||||
|
||||
# Hugo Parameters
|
||||
# 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.
|
||||
you want to inside of your templates.
|
||||
|
||||
|
||||
## Using Content (page) Parameters
|
||||
## 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).
|
||||
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.
|
||||
of some pages to turn off the TOC from being displayed.
|
||||
|
||||
Here is the example front matter:
|
||||
|
||||
|
@ -329,5 +343,5 @@ so, such as in this example:
|
|||
```
|
||||
|
||||
|
||||
[go]: <http://golang.org/>
|
||||
[gohtmltemplate]: <http://golang.org/pkg/html/template/>
|
||||
[go]: https://golang.org/
|
||||
[gohtmltemplate]: https://golang.org/pkg/html/template/
|
||||
|
|
38
exampleSite/content/posts/hugoisforlovers.md
Executable file → Normal file
38
exampleSite/content/posts/hugoisforlovers.md
Executable file → Normal file
|
@ -1,19 +1,31 @@
|
|||
---
|
||||
title: Getting Started with Hugo
|
||||
cover: "/img/cover.jpg"
|
||||
tags: ["go", "golang", "hugo", "development"]
|
||||
categories: ["Uncategorized"]
|
||||
date: "2014-04-02"
|
||||
---
|
||||
+++
|
||||
title = "Getting Started with Hugo"
|
||||
description = ""
|
||||
type = ["posts","post"]
|
||||
tags = [
|
||||
"go",
|
||||
"golang",
|
||||
"hugo",
|
||||
"development",
|
||||
]
|
||||
date = "2014-04-02"
|
||||
categories = [
|
||||
"Development",
|
||||
"golang",
|
||||
]
|
||||
series = ["Hugo 101"]
|
||||
[ author ]
|
||||
name = "Hugo Authors"
|
||||
+++
|
||||
|
||||
## Step 1. Install Hugo
|
||||
|
||||
Goto [hugo releases](https://github.com/spf13/hugo/releases) and download the
|
||||
appropriate version for your os and architecture.
|
||||
Go to [Hugo releases](https://github.com/spf13/hugo/releases) and download the
|
||||
appropriate version for your OS and architecture.
|
||||
|
||||
Save it somewhere specific as we will be using it in the next step.
|
||||
|
||||
More complete instructions are available at [installing hugo](/overview/installing/)
|
||||
More complete instructions are available at [Install Hugo](https://gohugo.io/getting-started/installing/)
|
||||
|
||||
## Step 2. Build the Docs
|
||||
|
||||
|
@ -22,7 +34,7 @@ you are reading right now.
|
|||
|
||||
Follow the following steps:
|
||||
|
||||
1. Clone the [hugo repository](http://github.com/spf13/hugo)
|
||||
1. Clone the [Hugo repository](http://github.com/spf13/hugo)
|
||||
2. Go into the repo
|
||||
3. Run hugo in server mode and build the docs
|
||||
4. Open your browser to http://localhost:1313
|
||||
|
@ -42,7 +54,7 @@ Once you've gotten here, follow along the rest of this page on your local build.
|
|||
|
||||
## Step 3. Change the docs site
|
||||
|
||||
Stop the Hugo process by hitting ctrl+c.
|
||||
Stop the Hugo process by hitting Ctrl+C.
|
||||
|
||||
Now we are going to run hugo again, but this time with hugo in watch mode.
|
||||
|
||||
|
@ -72,7 +84,7 @@ Change and save this file.. Notice what happened in your terminal.
|
|||
|
||||
Refresh the browser and observe that the typo is now fixed.
|
||||
|
||||
Notice how quick that was. Try to refresh the site before it's finished building.. I double dare you.
|
||||
Notice how quick that was. Try to refresh the site before it's finished building. I double dare you.
|
||||
Having nearly instant feedback enables you to have your creativity flow without waiting for long builds.
|
||||
|
||||
## Step 4. Have fun
|
||||
|
|
14
exampleSite/content/posts/migrate-from-jekyll.md
Executable file → Normal file
14
exampleSite/content/posts/migrate-from-jekyll.md
Executable file → Normal file
|
@ -1,7 +1,17 @@
|
|||
---
|
||||
title: Migrate to Hugo from Jekyll
|
||||
author:
|
||||
name: "Hugo Authors"
|
||||
date: 2014-03-10
|
||||
categories: ["Uncategorized"]
|
||||
linktitle: Migrating from Jekyll
|
||||
title: Migrate to Hugo from Jekyll
|
||||
type:
|
||||
- post
|
||||
- posts
|
||||
weight: 10
|
||||
series:
|
||||
- Hugo 101
|
||||
aliases:
|
||||
- /blog/migrate-from-jekyll/
|
||||
---
|
||||
|
||||
## Move static content to `static`
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<span class="author" itemprop="copyrightHolder"><a href="{{ .Site.BaseURL }}">{{ .Site.Params.author }}</a> | </span>
|
||||
{{ end }}
|
||||
|
||||
<span>Developed with ❤️ with <a href="https://gohugo.io" target="_blank" rel="external nofollow noopener noreffer">Hugo</a> & <a href="https://github.com/Fastbyte01/KeepIt" target="_blank" rel="external nofollow noopener noreffer">KeepIt</a></span>
|
||||
<span>Crafted with ❤️ by <a href="https://fsb01.com" target="_blank" rel="external nofollow noopener noreffer">Fastbyte01</a> & <a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreffer">Hugo</a></span>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
|
Loading…
Reference in a new issue