Merge commit '6efb279bfacbd7304cef994be8181c6f804e7dd4'

This commit is contained in:
Bjørn Erik Pedersen 2024-02-07 20:46:41 +01:00
commit b8d5090452
No known key found for this signature in database
29 changed files with 435 additions and 569 deletions

View file

@ -105,6 +105,7 @@
"doas",
"eopkg",
"gitee",
"gohugoio",
"goldmark",
"KaTeX",
"kubuntu",

View file

@ -18,9 +18,9 @@ jobs:
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: "javascript"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3

View file

@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v4
- name: Lint Code Base
uses: super-linter/super-linter/slim@v5
uses: super-linter/super-linter/slim@v6
env:
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -1,56 +1,20 @@
<a href="https://gohugo.io/"><img src="https://raw.githubusercontent.com/gohugoio/gohugoioTheme/master/static/images/hugo-logo-wide.svg?sanitize=true" alt="Hugo" width="565"></a>
A fast and flexible static site generator built with love by [bep], [spf13], and [friends] in [Go].
---
[![Netlify Status](https://api.netlify.com/api/v1/badges/e0dbbfc7-34f1-4393-a679-c16e80162705/deploy-status)](https://app.netlify.com/sites/gohugoio/deploys)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://gohugo.io/contribute/documentation/)
# Hugo Docs
This is the repository for the [Hugo](https://github.com/gohugoio/hugo) documentation site.
Documentation site for [Hugo](https://github.com/gohugoio/hugo), the very fast and flexible static site generator built with love in Go.
Please see the [contributing] section for guidelines, examples, and process.
## Contributing
We welcome contributions to Hugo of any kind including documentation, suggestions, bug reports, pull requests etc. Also check out our [contribution guide](https://gohugo.io/contribute/documentation/). We would love to hear from you.
Note that this repository contains solely the documentation for Hugo. For contributions that aren't documentation-related please refer to the [hugo](https://github.com/gohugoio/hugo) repository.
*Pull requests shall **only** contain changes to the actual documentation. However, changes on the codebase of Hugo **and** the documentation shall be a single, atomic pull request in the [hugo](https://github.com/gohugoio/hugo) repository.*
Spelling fixes are most welcomed, and if you want to contribute longer sections to the documentation, it would be great if you had the following criteria in mind when writing:
* Short is good. People go to the library to read novels. If there is more than one way to _do a thing_ in Hugo, describe the current _best practice_ (avoid "… but you can also do …" and "… in older versions of Hugo you had to …".
* For example, try to find short snippets that teaches people about the concept. If the example is also useful as-is (copy and paste), then great. Don't list long and similar examples just so people can use them on their sites.
* Hugo has users from all over the world, so easy to understand and [simple English](https://simple.wikipedia.org/wiki/Basic_English) is good.
## Edit the theme
If you want to do docs-related theme changes, the simplest way is to have both `hugoDocs` and `gohugoioTheme` cloned as sibling directories, and then run:
```sh
HUGO_MODULE_WORKSPACE=hugo.work hugo server --ignoreVendorPaths "**"
```
## Branches
* The `master` branch is where the site is automatically built from, and is the place to put changes relevant to the current Hugo version.
* The `next` branch is where we store changes that are related to the next Hugo release. This can be previewed here: https://next--gohugoio.netlify.com/
## Build
To view the documentation site locally, you need to clone this repository:
```sh
git clone https://github.com/gohugoio/hugoDocs.git
```
Also note that the documentation version for a given version of Hugo can also be found in the `/docs` sub-folder of the [Hugo source repository](https://github.com/gohugoio/hugo).
Then to view the docs in your browser, run Hugo and open up the link:
```sh
▶ hugo server
Started building sites ...
.
.
Serving pages from memory
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
```
[bep]: https://github.com/bep
[spf13]: https://github.com/spf13
[friends]: https://github.com/gohugoio/hugo/graphs/contributors
[go]: https://go.dev/
[contributing]: https://gohugo.io/contribute/documentation

View file

@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html
class="no-js"
lang="{{ with $.Site.LanguageCode }}
@ -98,7 +98,8 @@
{{ partial "gtag.html" . }}
{{ end }}
{{ if .Param "math" }}
{{ $hasMath := .Param "math" }}
{{ if $hasMath }}
{{ partialCached "math.html" . }}
{{ end }}
@ -107,7 +108,7 @@
<body
class="ma0 sans-serif bg-primary-color-light{{ with getenv "HUGO_ENV" }}
{{ . }}
{{ end }}">
{{ end }} {{ if $hasMath }}{{ print " dn" }}{{ end }}">
{{ partial "hooks/after-body-start.html" . }}
{{ block "nav" . }}{{ partial "site-nav.html" . }}{{ end }}
{{ block "header" . }}{{ end }}

View file

@ -1,32 +1,42 @@
{{ $author := .context.Params.author }}
{{ if $author }}
<aside class="mw5 center bg-white br3 pa3 pa4-ns mv3 ba b--black-10 nested-links">
{{ $urlPre := "https://api.github.com" }}
{{ $user_json := getJSON $urlPre "/users/" $author }}
{{ $data := "" }}
{{ $url := urls.JoinPath "https://api.github.com/users" $author }}
{{ with resources.GetRemote $url }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ $data = . | transform.Unmarshal }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
<div class="tc">
{{ with $data }}
{{ if $user_json.avatar_url }}
<a href="{{ $user_json.html_url }}" class="link hover-bg-light-gray pa1 br-100">
<img src="{{ $user_json.avatar_url }}&size={{ .size }}" alt="" class="br-100 ba b--light-gray">
</a>
{{ end }}
{{ if $user_json.name }}
<h3 class="f4">
<a href="{{ $user_json.html_url }}" class="link dim">
{{ $user_json.name }}
{{ with .avatar_url }}
<a href="{{ . }}" class="link hover-bg-light-gray pa1 br-100">
<img src="{{ . }}&size={{ $.size }}" alt="" class="br-100 ba b--light-gray">
</a>
</h3>
<hr class="mw3 bb bw1 b--black-10">
{{ end }}
{{ end }}
{{ with .name }}
<h3 class="f4">
<a href="{{ $data.html_url }}" class="link dim">
{{ . | htmlEscape }}
</a>
</h3>
<hr class="mw3 bb bw1 b--black-10">
{{ end }}
{{ with .bio }}
<p class="lh-copy measure center f6 black-70">
{{ . | htmlEscape }}
</p>
{{ end }}
{{ if $user_json.bio }}
<p class="lh-copy measure center f6 black-70">
{{ $user_json.bio }}
</p>
{{ end }}
</div>
</aside>

View file

@ -1,21 +1,36 @@
{{ $author := .context.Params.author }}
{{ if $author }}
<aside class="mw5 br3 mv3 nested-links">
{{ $urlPre := "https://api.github.com" }}
{{ $user_json := getJSON $urlPre "/users/" $author }}
{{ if $user_json.name }}
<h3 class="f4 dib">
{{ $user_json.name | htmlEscape }}
</h3>
{{ $data := "" }}
{{ $url := urls.JoinPath "https://api.github.com/users" $author }}
{{ with resources.GetRemote $url }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ $data = . | transform.Unmarshal }}
{{ end }}
{{ if $user_json.bio }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
{{ with $data }}
{{ with .name }}
<h3 class="f4 dib">
{{ . | htmlEscape }}
</h3>
{{ end }}
{{ with .bio }}
<p class="lh-copy measure center mt0 f6 black-60">
{{ $user_json.bio | htmlEscape }}
{{ . | htmlEscape }}
</p>
{{ end }}
<a href="{{ $user_json.html_url }}" class="link dim v-mid dib">
{{ partial "svg/github-squared.svg" (dict "fill" "gray" "width" "16" "height" "18") }}
</a>
{{ with .html_url }}
<a href="{{ . }}" class="link dim v-mid dib">
{{ partial "svg/github-squared.svg" (dict "fill" "gray" "width" "16" "height" "18") }}
</a>
{{ end }}
{{ end }}
</aside>
{{ end }}

View file

@ -14,11 +14,11 @@
<a href="{{ .Permalink }}">{{ .Title }}</a>
</td>
<td class="pv2 ph3">
<a href="{{.Site.Params.ghrepo}}blob/master/content/{{.Lang }}/{{.File.Path}}">
<a href="{{ .Site.Params.ghrepo }}blob/master/content/{{ .Language.Lang }}/{{ .File.Path }}">
{{ with .GitInfo }}{{ .Subject }}{{ else }}Source{{ end }}
</a>
</td>
</tr>
{{ end }}
</tbody>
</table>
</table>

View file

@ -2,8 +2,15 @@
<script>
MathJax = {
tex: {
displayMath: [['\\[', '\\]'], ['$$', '$$']], // block
inlineMath: [['\\(', '\\)']] // inline
inlineMath: [['$', '$'], ['\\(', '\\)']], // inline
displayMath: [['$$', '$$'], ['\\[', '\\]']] // block
},
startup: {
pageReady: () => {
return MathJax.startup.defaultPageReady().then(() => {
document.body.classList.remove("dn");
});
}
}
};
</script>

View file

@ -1,3 +1,3 @@
<a href="{{.Site.Params.ghrepo}}edit/master/content/{{ .Lang }}/{{.File.Path}}" class="
<a href="{{.Site.Params.ghrepo }}edit/master/content/{{ .Language.Lang }}/{{ .File.Path }}" class="
f6 ph3 pv1 br2 dib tc ttu mv3 bg-primary-color white hover-bg-green link
">Improve this page</a>

View file

@ -1 +1 @@
# github.com/gohugoio/gohugoioTheme v0.0.0-20240126181647-31e47d550511
# github.com/gohugoio/gohugoioTheme v0.0.0-20240201183016-8e648a3b5342

View file

@ -131,9 +131,6 @@ videos
weight
: used for [ordering your content in lists][ordering]. Lower weight gets higher precedence. So content with lower weight will come first. If set, weights should be non-zero, as 0 is interpreted as an *unset* weight.
taxonomies
: Field name of the *plural* form of the index. See `tags` and `categories` in the above front matter examples. *Note that the plural form of user-defined taxonomies cannot be the same as any of the predefined front matter variables.*
{{% note %}}
If neither `slug` nor `url` is present and [permalinks are not configured otherwise in your site configuration file](/content-management/urls/#permalinks), Hugo will use the file name of your content to create the output URL. See [Content Organization](/content-management/organization) for an explanation of paths in Hugo and [URL Management](/content-management/urls/) for ways to customize Hugo's default behaviors.
{{% /note %}}
@ -190,7 +187,7 @@ Any of the above can be omitted.
{{% note %}}
When making a site that supports multiple languages, defining a `[[cascade]]` is recommended to be done in [Site Config](../../getting-started/configuration/#cascade) to prevent duplication.
If you instea define a `[[cascade]]` in front matter for multiple languages, an `content/XX/foo/_index.md` file needs to be made on a per-language basis, with `XX` the glob pattern matching the Page's language. In this case, the **lang** keyword is ignored.
If you instead define a `[[cascade]]` in front matter for multiple languages, an `content/XX/foo/_index.md` file needs to be made on a per-language basis, with `XX` the glob pattern matching the Page's language. In this case, the **lang** keyword is ignored.
{{% /note %}}
### Example

View file

@ -1,9 +1,9 @@
---
title: Mathematics in markdown
linkTitle: Mathematics
description: Include mathematical equations and expressions in your markdown using LaTeX or TeX typsetting syntax.
description: Include mathematical equations and expressions in your markdown using LaTeX or TeX typesetting syntax.
categories: [content management]
keywords: [chemical,chemistry,latex,math,mathjax,tex,typsetting]
keywords: [chemical,chemistry,latex,math,mathjax,tex,typesetting]
menu:
docs:
parent: content-management
@ -45,7 +45,7 @@ The approach described below avoids reliance on platform-specific features like
## Setup
Follow these instructions to include mathematical equations and expressions in your markdown using LaTeX or TeX typsetting syntax.
Follow these instructions to include mathematical equations and expressions in your markdown using LaTeX or TeX typesetting syntax.
###### Step 1
@ -122,7 +122,7 @@ The example above loads the partial template if you have set the `math` paramete
###### Step 4
Include mathematical equations and expressions in your markdown using LaTeX or TeX typsetting syntax.
Include mathematical equations and expressions in your markdown using LaTeX or TeX typesetting syntax.
{{< code file=content/math-examples.md copy=true >}}
This is an inline \(a^*=x-b^*\) equation.

View file

@ -11,420 +11,138 @@ weight: 20
toc: true
---
## Introduction
Hugo is an open-source project and lives by the work of its [contributors]. There are plenty of [open issues][issues], and we need your help to make Hugo even more awesome. You don't need to be a Go guru to contribute to the project's development.
You can contribute to the Hugo project by:
## Assumptions
- Answering questions on the [forum]
- Improving the [documentation]
- Monitoring the [issue queue]
- Creating or improving [themes]
- Squashing [bugs]
This contribution guide takes a step-by-step approach in hopes of helping newcomers. Therefore, we only assume the following:
Please submit documentation issues and pull requests to the [documentation repository].
* You are new to Git or open-source projects in general
* You are a fan of Hugo and enthusiastic about contributing to the project
If you have an idea for an enhancement or new feature, create a new topic on the [forum] in the "Feature" category. This will help you to:
- Determine if the capability already exists
- Measure interest
- Refine the concept
If there is sufficient interest, [create a proposal]. Do not submit a pull request until the project lead accepts the proposal.
For a complete guide to contributing to Hugo, see the [Contribution Guide].
[bugs]: https://github.com/gohugoio/hugo/issues?q=is%3Aopen+is%3Aissue+label%3ABug
[contributing]: CONTRIBUTING.md
[create a proposal]: https://github.com/gohugoio/hugo/issues/new?labels=Proposal%2C+NeedsTriage&template=feature_request.md
[documentation repository]: https://github.com/gohugoio/hugoDocs
[documentation]: https://gohugo.io/documentation
[forum]: https://discourse.gohugo.io
[issue queue]: https://github.com/gohugoio/hugo/issues
[themes]: https://themes.gohugo.io/
[contribution guide]: https://github.com/gohugoio/hugo/blob/master/CONTRIBUTING.md
## Prerequisites
To build the extended edition of Hugo from source you must:
1. Install [Git]
1. Install [Go] version 1.20 or later
1. Install a C compiler, either [GCC] or [Clang]
1. Update your `PATH` environment variable as described in the [Go documentation]
[Clang]: https://clang.llvm.org/
[GCC]: https://gcc.gnu.org/
[Git]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
[Go documentation]: https://go.dev/doc/code#Command
[Go]: https://go.dev/doc/install
{{% note %}}
If you're struggling at any point in this contribution guide, reach out to the Hugo community in [Hugo's Discussion forum](https://discourse.gohugo.io).
See these [detailed instructions](https://discourse.gohugo.io/t/41370) to install GCC on Windows.
{{% /note %}}
## Install Go
The installation of Go should take only a few minutes. You have more than one option to get Go up and running on your machine.
If you are having trouble following the installation guides for Go, check out [Go Bootcamp, which contains setups for every platform][gobootcamp] or reach out to the Hugo community in the [Hugo Discussion Forums][forums].
### Install Go from source
[Download the latest stable version of Go][godl] and follow the official [Go installation guide][goinstall].
Once you're finished installing Go, let's confirm everything is working correctly. Open a terminal---or command line under Windows--and type the following:
```txt
go version
```
You should see something similar to the following written to the console. Note that the version here reflects the most recent version of Go as of the last update for this page:
```txt
go version go1.12 darwin/amd64
```
Next, make sure that you set up your `GOPATH` [as described in the installation guide][setupgopath].
You can print the `GOPATH` with `echo $GOPATH`. You should see a non-empty string containing a valid path to your Go workspace; for example:
```txt
/Users/<yourusername>/Code/go
```
### Install Go with Homebrew
If you are a macOS user and have [Homebrew](https://brew.sh/) installed on your machine, installing Go is as simple as the following command:
{{< code file=install-go.sh >}}
brew install go
{{< /code >}}
### Install Go via GVM
More experienced users can use the [Go Version Manager][gvm] (GVM). GVM allows you to switch between different Go versions *on the same machine*. If you're a beginner, you probably don't need this feature. However, GVM makes it easy to upgrade to a new released Go version with just a few commands.
GVM comes in especially handy if you follow the development of Hugo over a longer period of time. Future versions of Hugo will usually be compiled with the latest version of Go. Sooner or later, you will have to upgrade if you want to keep up.
## Create a GitHub account
If you're going to contribute code, you'll need to have an account on GitHub. Go to [www.github.com/join](https://github.com/join) and set up a personal account.
## Install Git on your system
You will need to have Git installed on your computer to contribute to Hugo development. Teaching Git is outside the scope of the Hugo docs, but if you're looking for an excellent reference to learn the basics of Git, we recommend the [Git book][gitbook] if you are not sure where to begin. We will include short explanations of the Git commands in this document.
Git is a [version control system](https://en.wikipedia.org/wiki/Version_control) to track the changes of source code. Hugo depends on smaller third-party packages that are used to extend the functionality. We use them because we don't want to reinvent the wheel.
Go ships with a sub-command called `get` that will download these packages for us when we set up our working environment. The source code of the packages is tracked with Git. `get` will interact with the Git servers of the package hosters in order to fetch all dependencies.
Move back to the terminal and check if Git is already installed. Type in `git version` and press enter. You can skip the rest of this section if the command returned a version number. Otherwise [download](https://git-scm.com/downloads) the latest version of Git and follow this [installation guide](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
Finally, check again with `git version` if Git was installed successfully.
### Git graphical front ends
There are several [GUI clients](https://git-scm.com/downloads/guis) that help you to operate Git. Not all are available for all operating systems and maybe differ in their usage. Because of this we will document how to use the command-line, since the commands are the same everywhere.
### Install Hub on your system (optional)
Hub is a great tool for working with GitHub. The main site for it is [hub.github.com](https://hub.github.com/). Feel free to install this little Git wrapper.
On a Mac, you can install [Hub](https://github.com/github/hub) using [Homebrew](https://brew.sh):
```txt
brew install hub
```
Now we'll create an [alias in Bash](https://tldp.org/LDP/abs/html/aliases.html) so that typing `git` actually runs `Hub`:
```txt
echo "alias git='hub'" >> ~/.bash_profile
```
Confirm the installation:
```txt
git version 2.21.0
hub version 2.10.0
```
## Set up your working copy
You set up the working copy of the repository locally on your computer. Your local copy of the files is what you'll edit, compile, and end up pushing back to GitHub. The main steps are cloning the repository and creating your fork as a remote.
### Clone the repository
We assume that you've set up your `GOPATH` (see the section above if you're unsure about this). You should now copy the Hugo repository down to your computer. You'll hear this called "clone the repo". GitHub's [help pages](https://help.github.com/articles/cloning-a-repository/) give us a short explanation:
## GitHub workflow
{{% note %}}
When you create a repository on GitHub, it exists as a remote repository. You can create a local clone of your repository on your computer and sync between the two locations.
This section assumes that you have a working knowledge of Go, Git and GitHub, and are comfortable working on the command line.
{{% /note %}}
We're going to clone the [master Hugo repository](https://github.com/gohugoio/hugo). That seems counter-intuitive, since you won't have commit rights on it. But it's required for the Go workflow. You'll work on a copy of the master and push your changes to your own repository on GitHub.
Use this workflow to create and submit pull requests.
So, let's make a new directory and clone that master repository:
Step 1
: Fork the [project repository].
```txt
mkdir $HOME/src
cd $HOME/src
git clone https://github.com/gohugoio/hugo.git
[project repository]: https://github.com/gohugoio/hugo/
Step 2
: Clone your fork.
Step 3
: Create a new branch with a descriptive name that includes the corresponding issue number.
For a new feature:
```sh
git checkout -b feat/implement-some-feature-99999
```
Since Hugo 0.48, Hugo uses the Go Modules support built into Go 1.11 to build. The easiest is to clone Hugo in a directory outside of GOPATH
For a bug fix:
And then, install dependencies of Hugo by running the following in the cloned directory:
```txt
cd $HOME/src/hugo
go install
```sh
git checkout -b fix/fix-some-bug-99999
```
Hugo relies on [mage](https://github.com/magefile/mage) for some convenient build and test targets. If you don't already have it, get it:
Step 4
: Make changes.
```txt
go install github.com/magefile/mage@latest
Step 5
: Compile and install:
```text
CGO_ENABLED=1 go install -tags extended
```
### Fork the repository
Step 6
: Test your changes:
If you're not familiar with this term, GitHub's [help pages](https://help.github.com/articles/fork-a-repo/) provide again a simple explanation:
{{% note %}}
A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.
{{% /note %}}
#### Fork by hand
Open the [Hugo repository](https://github.com/gohugoio/hugo) on GitHub and click on the "Fork" button in the top right.
![Fork button](/images/contribute/development/forking-a-repository.png)
Now open your fork repository on GitHub and copy the remote URL of your fork. You can choose between HTTPS and SSH as protocol that Git should use for the following operations. HTTPS works always [if you're not sure](https://help.github.com/articles/which-remote-url-should-i-use/).
![Copy remote url](/images/contribute/development/copy-remote-url.png)
Switch back to the terminal and move into the directory of the cloned master repository from the last step.
```txt
cd $HOME/src/hugo
```text
go test ./...
```
Now Git needs to know that our fork exists by adding the copied remote url:
Step 7
: Commit your changes with a descriptive commit message:
```txt
git remote add <YOUR-GITHUB-USERNAME> <COPIED REMOTE-URL>
```
- Provide a summary on the first line, typically 50 characters or less, followed by a blank line.
- Optionally, provide a detailed description where each line is 80 characters or less, followed by a blank line.
- Add one or more "Fixes" or "Closes" keywords, each on its own line, referencing the [issues] addressed by this change.
#### Fork with Hub
Alternatively, you can use the Git wrapper Hub. Hub makes forking a repository easy:
```txt
git fork
```
That command will log in to GitHub using your account, create a fork of the repository that you're currently working in, and add it as a remote to your working copy.
#### Trust, but verify
Let's check if everything went right by listing all known remotes:
```txt
git remote -v
```
The output should look similar:
```txt
digitalcraftsman git@github.com:digitalcraftsman/hugo.git (fetch)
digitalcraftsman git@github.com:digitalcraftsman/hugo.git (push)
origin https://github.com/gohugoio/hugo (fetch)
origin https://github.com/gohugoio/hugo (push)
```
## The Hugo Git contribution workflow
### Create a new branch
You should never develop against the "master" branch. The development team will not accept a pull request against that branch. Instead, create a descriptive named branch and work on it.
First, you should always pull the latest changes from the master repository:
```txt
git checkout master
git pull
```
Now we can create a new branch for your additions:
```txt
git checkout -b <BRANCH-NAME>
```
You can check on which branch you are with `git branch`. You should see a list of all local branches. The current branch is indicated with a little asterisk.
### Contribute to documentation
Perhaps you want to start contributing to the Hugo docs. If so, you can ignore most of the following steps and focus on the `/docs` directory within your newly cloned repository. You can change directories into the Hugo docs using `cd docs`.
You can start Hugo's built-in server via `hugo server`. Browse the documentation by entering [http://localhost:1313](http://localhost:1313) in the address bar of your browser. The server automatically updates the page whenever you change content.
We have developed a [separate Hugo documentation contribution guide][docscontrib] for more information on how the Hugo docs are built, organized, and improved by the generosity of people like you.
### Build Hugo
While making changes in the codebase it's a good idea to build the binary to test them:
```txt
mage hugo
```
This command generates the binary file at the root of the repository.
If you want to install the binary in `$GOPATH/bin`, run
```txt
mage install
```
### Test
Sometimes changes on the codebase can cause unintended side effects. Or they don't work as expected. Most functions have their own test cases. You can find them in files ending with `_test.go`.
Make sure the commands
```txt
mage -v check
```
passes.
### Formatting
The Go code style guide maybe is opinionated but it ensures that the codebase looks the same, regardless who wrote the code. Go comes with its own formatting tool. Let's apply the style guide to our additions:
```txt
mage fmt
```
Once you made your additions commit your changes. Make sure that you follow our [code contribution guidelines](https://github.com/gohugoio/hugo/blob/master/CONTRIBUTING.md):
```txt
# Add all changed files
git add --all
git commit --message "YOUR COMMIT MESSAGE"
```
The commit message should describe what the commit does (e.g. add feature XYZ), not how it is done.
### Modify commits
You noticed some commit messages don't fulfill the code contribution guidelines or you just forget something to add some files? No problem. Git provides the necessary tools to fix such problems. The next two methods cover all common cases.
If you are unsure what a command does leave the commit as it is. We can fix your commits later in the pull request.
#### Modify the last commit
Let's say you want to modify the last commit message. Run the following command and replace the current message:
```txt
git commit --amend -m"YOUR NEW COMMIT MESSAGE"
```
Take a look at the commit log to see the change:
```txt
git log
# Exit with q
```
After making the last commit you may have forgotten something. There is no need to create a new commit. Just add the latest changes and merge them into the intended commit:
```txt
git add --all
git commit --amend
```
#### Modify multiple commits
{{% note %}}
Modifications such as those described in this section can have serious unintended consequences. Skip this section if you're not sure!
{{% /note %}}
This is a bit more advanced. Git allows you to [rebase](https://git-scm.com/docs/git-rebase) commits interactively. In other words: it allows you to rewrite the commit history.
```txt
git rebase --interactive @~6
```
The `6` at the end of the command represents the number of commits that should be modified. An editor should open and present a list of last six commit messages:
```txt
pick 80d02a1 tpl: Add hasPrefix to template function smoke test"
pick aaee038 tpl: Sort the smoke tests
pick f0dbf2c tpl: Add the other test case for hasPrefix
pick 911c35b Add "How to contribute to Hugo" tutorial
pick 33c8973 Begin workflow
pick 3502f2e Refactoring and typo fixes
```
In the case above we should merge the last two commits in the commit of this tutorial (`Add "How to contribute to Hugo" tutorial`). You can "squash" commits, i.e. merge two or more commits into a single one.
All operations are written before the commit message. Replace "pick" with an operation. In this case `squash` or `s` for short:
```txt
pick 80d02a1 tpl: Add hasPrefix to template function smoke test"
pick aaee038 tpl: Sort the smoke tests
pick f0dbf2c tpl: Add the other test case for hasPrefix
pick 911c35b Add "How to contribute to Hugo" tutorial
squash 33c8973 Begin workflow
squash 3502f2e Refactoring and typo fixes
```
We also want to rewrite the commits message of the third last commit. We forgot "docs:" as prefix according to the code contribution guidelines. The operation to rewrite a commit is called `reword` (or `r` as shortcut).
You should end up with a similar setup:
```txt
pick 80d02a1 tpl: Add hasPrefix to template function smoke test"
pick aaee038 tpl: Sort the smoke tests
pick f0dbf2c tpl: Add the other test case for hasPrefix
reword 911c35b Add "How to contribute to Hugo" tutorial
squash 33c8973 Begin workflow
squash 3502f2e Refactoring and typo fixes
```
Close the editor. It should open again with a new tab. A text is instructing you to define a new commit message for the last two commits that should be merged (aka "squashed"). Save the file with <kbd>CTRL</kbd>+<kbd>S</kbd> and close the editor again.
A last time a new tab opens. Enter a new commit message and save again. Your terminal should contain a status message. Hopefully this one:
```txt
Successfully rebased and updated refs/heads/<BRANCHNAME>.
```
Check the commit log if everything looks as expected. Should an error occur you can abort this rebase with `git rebase --abort`.
### Push commits
To push our commits to the fork on GitHub we need to specify a destination. A destination is defined by the remote and a branch name. Earlier, the defined that the remote URL of our fork is the same as our GitHub handle, in my case `digitalcraftsman`. The branch should have the same as our local one. This makes it easy to identify corresponding branches.
```txt
git push --set-upstream <YOUR-GITHUB-USERNAME> <BRANCHNAME>
```
Now Git knows the destination. Next time when you to push commits you just need to enter `git push`.
If you modified your commit history in the last step GitHub will reject your try to push. This is a safety-feature because the commit history isn't the same and new commits can't be appended as usual. You can enforce this push explicitly with `git push --force`.
## Open a pull request
We made a lot of progress. Good work. In this step we finally open a pull request to submit our additions. Open the [Hugo master repository](https://github.com/gohugoio/hugo/) on GitHub in your browser.
You should find a green button labeled with "New pull request". But GitHub is clever and probably suggests you a pull request like in the beige box below:
![Open a pull request](/images/contribute/development/open-pull-request.png)
The new page summaries the most important information of your pull request. Scroll down and you find the additions of all your commits. Make sure everything looks as expected and click on "Create pull request".
### Accept the contributor license agreement
Last but not least you should accept the contributor license agreement (CLA). A new comment should be added automatically to your pull request. Click on the yellow badge, accept the agreement and authenticate yourself with your GitHub account. It just takes a few clicks and only needs to be done once.
![Accept the CLA](/images/contribute/development/accept-cla.png)
### Automatic builds
We use a GitHub Actions workflow to build and test. This is a matrix build across combinations of operating system (macOS, Windows, and Ubuntu) and Go versions. The workflow is triggered by the submission of a pull request. If you are a first-time contributor, the workflow requires approval from a project maintainer.
## Where to start?
Thank you for reading through this contribution guide. Hopefully, we will see you again soon on GitHub. There are plenty of [open issues][issues] for you to help with.
Feel free to [open an issue][newissue] if you think you found a bug or you have a new idea to improve Hugo. We are happy to hear from you.
## Additional references for learning Git and Go
* [Codecademy's Free "Learn Git" Course][codecademy] (Free)
* [Code School and GitHub's "Try Git" Tutorial][trygit] (Free)
* [The Git Book][gitbook] (Free)
* [Go Bootcamp][gobootcamp]
[codecademy]: https://www.codecademy.com/learn/learn-git
[contributors]: https://github.com/gohugoio/hugo/graphs/contributors
[docscontrib]: /contribute/documentation/
[forums]: https://discourse.gohugo.io
[gitbook]: https://git-scm.com/
[gobootcamp]: https://www.golang-book.com/guides/machine_setup
[godl]: https://go.dev/dl/
[goinstall]: https://go.dev/doc/install
[gvm]: https://github.com/moovweb/gvm
[issues]: https://github.com/gohugoio/hugo/issues
[newissue]: https://github.com/gohugoio/hugo/issues/new
[releases]: /getting-started/
[setupgopath]: https://go.dev/doc/code#Workspaces
[trygit]: https://try.github.io/levels/1/challenges/1
For example:
```sh
git commit -m "tpl/strings: Create wrap function
The strings.Wrap function wraps a string into one or more lines,
splitting the string after the given number of characters, but not
splitting in the middle of a word.
Fixes #99998
Closes #99999"
```
See the [commit message guidelines] for details.
[commit message guidelines]: https://github.com/gohugoio/hugo/blob/master/CONTRIBUTING.md#git-commit-message-guidelines
Step 8
: Push the new branch to your fork of the documentation repository.
Step 9
: Visit the [project repository] and create a pull request (PR).
Step 10
: A project maintainer will review your PR and may request changes. You may delete your branch after the maintainer merges your PR.

View file

@ -325,32 +325,44 @@ Step 2
: Clone your fork.
Step 3
: Create a new branch with a descriptive name.
: Create a new branch with a descriptive name that includes the corresponding issue number, if any:
```sh
git checkout -b fix/typos-shortcode-templates
git checkout -b restructure-foo-page-99999
```
Step 4
: Make changes.
Step 5
: Commit your changes with a descriptive commit message, typically 50 characters or less. Add the "Closes" keyword if your change addresses one or more open [issues].
```sh
git commit -m "Fix typos on the shortcode templates page
Closes #1234
Closes #5678"
```
: Build the site locally to preview your changes.
Step 6
: Push the new branch to your fork of the documentation repository.
: Commit your changes with a descriptive commit message:
- Provide a summary on the first line, typically 50 characters or less, followed by a blank line.
- Optionally, provide a detailed description where each line is 80 characters or less, followed by a blank line.
- Optionally, add one or more "Fixes" or "Closes" keywords, each on its own line, referencing the [issues] addressed by this change.
For example:
```sh
git commit -m "Restructure the taxonomy page
This restructures the taxonomy page by splitting topics into logical
sections, each with one or more examples.
Fixes #9999
Closes #9998"
```
Step 7
: Visit the [documentation repository] and create a pull request (PR).
: Push the new branch to your fork of the documentation repository.
Step 8
: Visit the [documentation repository] and create a pull request (PR).
Step 9
: A project maintainer will review your PR and may request changes. You may delete your branch after the maintainer merges your PR.
[ATX]: https://spec.commonmark.org/0.30/#atx-headings

View file

@ -22,3 +22,9 @@ If one of the numbers is a [`float`], the result is a `float`.
```
[`float`]: /getting-started/glossary/#float
You can also use the `add` function to concatenate strings.
```go-html-template
{{ add "hu" "go" }} → hugo
```

View file

@ -47,5 +47,3 @@ news → true
Note that `os.ReadDir` is not recursive.
Details of the `FileInfo` structure are available in the [Go documentation](https://pkg.go.dev/io/fs#FileInfo).
For more information on using `readDir` and `readFile` in your templates, see [Local File Templates](/templates/files).

View file

@ -36,5 +36,3 @@ This is **bold** text.
```
Note that `os.ReadFile` returns raw (uninterpreted) content.
For more information on using `readDir` and `readFile` in your templates, see [Local File Templates](/templates/files).

View file

@ -175,3 +175,41 @@ Override the cache key by setting a `key` in the options map. Use this approach
```
[configure file caches]: /getting-started/configuration/#configure-file-caches
## Security
To protect against malicious intent, the `resources.GetRemote` function inspects the server response including:
- The [Content-Type] in the response header
- The file extension, if any
- The content itself
If Hugo is unable to resolve the media type to an entry in its [allowlist], the function throws an error:
```text
ERROR error calling resources.GetRemote: failed to resolve media type...
```
For example, you will see the error above if you attempt to download an executable.
Although the allowlist contains entries for common media types, you may encounter situations where Hugo is unable to resolve the media type of a file that you know to be safe. In these situations, edit your site configuration to add the media type to the allowlist. For example:
```text
[security.http]
mediaTypes=['application/vnd\.api\+json']
```
Note that the entry above is:
- An _addition_ to the allowlist; it does not _replace_ the allowlist
- An array of regular expressions
For example, to add two entries to the allowlist:
```text
[security.http]
mediaTypes=['application/vnd\.api\+json','image/avif']
```
[allowlist]: https://en.wikipedia.org/wiki/Whitelist
[Content-Type]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type

View file

@ -11,6 +11,26 @@ weight: 60
# Use level 6 headings for each term in the glossary.
---
[A](#action)
[B](#bool)
[C](#cache)
[D](#default-sort-order)
[E](#environment)
[F](#field)
[G](#global-resource)
[I](#identifier)
[K](#kind)
[L](#layout)
[M](#map)
[O](#object)
[P](#page-bundle)
[R](#regular-page)
[S](#scalar)
[T](#taxonomic-weight)
[U](#unmarshal)
[V](#variable)
[W](#walk)
###### action
See [template action](#template-action).

View file

@ -18,7 +18,7 @@ With this front matter:
title = 'Annual conference'
date = 2023-10-17T15:11:37-07:00
display_related = true
[params.author]
[author]
email = 'jsmith@example.org'
name = 'John Smith'
{{< /code-toggle >}}

View file

@ -6,7 +6,7 @@ keywords: []
action:
related:
- methods/time/Before
- methods/time/After
- methods/time/Equal
- functions/time/AsTime
returnType: bool
signatures: [TIME1.After TIME2]

View file

@ -1,56 +0,0 @@
---
title: Local file templates
description: Hugo's `readDir` and `readFile` functions make it easy to traverse your project's directory structure and write file contents to your templates.
categories: [templates]
keywords: [files,directories]
menu:
docs:
parent: templates
weight: 180
weight: 180
toc: true
aliases: [/extras/localfiles/,/templates/local-files/]
---
## Traverse local files
With Hugo's [`readDir`] and [`readFile`] template functions, you can traverse your website's files on your server.
## Use `readDir`
The [`readDir`] function returns an array of [`os.FileInfo`] structures. It takes the file's `path` as a single string argument. This path can be to any directory of your website (i.e., as found on your server's file system).
Whether the path is absolute or relative does not matter because---at least for `readDir`---the root of your website (typically `./public/`) in effect becomes both:
1. The file system root
2. The current working directory
## Use `readFile`
The [`readfile`] function reads a file from disk and converts it into a string to be manipulated by other Hugo functions or added as-is. `readFile` takes the file, including path, as an argument passed to the function.
To use the `readFile` function in your templates, make sure the path is relative to your *Hugo project's root directory*:
```go-html-template
{{ readFile "/content/templates/local-file-templates" }}
```
### `readFile` Example: Add a Project File to Content
As `readFile` is a function, it is only available to you in your templates and not your content. However, we can create a simple [shortcode template][sct] that calls `readFile`, passes the first argument through the function, and then allows an optional second argument to send the file through the Markdown processor. The pattern for adding this shortcode to your content will be as follows:
```go-html-template
{{</* readfile file="/path/to/local/file.txt" markdown="true" */>}}
```
{{% note %}}
If you are going to create [custom shortcodes](/templates/shortcode-templates/) with `readFile` for a theme, note that usage of the shortcode will refer to the project root and *not* your `themes` directory.
{{% /note %}}
[called directly in the Hugo docs]: https://github.com/gohugoio/hugoDocs/blob/master/content/en/templates/files.md
[`os.FileInfo`]: https://pkg.go.dev/io/fs#FileInfo
[`readDir`]: /functions/os/readdir
[`readFile`]: /functions/os/readfile
[sc]: /content-management/shortcodes/
[sct]: /templates/shortcode-templates/
[readfilesource]: https://github.com/gohugoio/hugoDocs/blob/master/layouts/shortcodes/readfile.html

View file

@ -85,9 +85,6 @@ The above example is fictional, but if used for the homepage on a site with `bas
The following is the full list of configuration options for output formats and their default values:
name
: the output format identifier. This is used to define what output format(s) you want for your pages.
mediaType
: this must match the `Type` of a defined media type.

View file

@ -128,7 +128,7 @@ Here is a code example for how the render-image.html template could look:
Given this template file
{{< code file=layouts/_default/_markup/render-heading.html >}}
<h{{ .Level }} id="{{ .Anchor | safeURL }}">{{ .Text | safeHTML }} <a href="#{{ .Anchor | safeURL }}"></a></h{{ .Level }}>
<h{{ .Level }} id="{{ .Anchor }}">{{ .Text | safeHTML }} <a href="#{{ .Anchor | safeURL }}"></a></h{{ .Level }}>
{{< /code >}}
And this markdown

View file

@ -2,4 +2,4 @@ module github.com/gohugoio/hugoDocs
go 1.16
require github.com/gohugoio/gohugoioTheme v0.0.0-20240126181647-31e47d550511 // indirect
require github.com/gohugoio/gohugoioTheme v0.0.0-20240201183016-8e648a3b5342 // indirect

View file

@ -1,2 +1,2 @@
github.com/gohugoio/gohugoioTheme v0.0.0-20240126181647-31e47d550511 h1:dJLsByAuk9RnZmjL6QxQzHTJ63dr7Cwx6Dj8KAm7uEI=
github.com/gohugoio/gohugoioTheme v0.0.0-20240126181647-31e47d550511/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM=
github.com/gohugoio/gohugoioTheme v0.0.0-20240201183016-8e648a3b5342 h1:jQaO+i2osHeIZ+V7Dvo7CPqN6jPwMRjt7b9QaX7HXE4=
github.com/gohugoio/gohugoioTheme v0.0.0-20240201183016-8e648a3b5342/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM=

View file

@ -0,0 +1,124 @@
<!doctype html>
<html
class="no-js"
lang="{{ with $.Site.LanguageCode }}
{{ . }}
{{ else }}
en-us
{{ end }}
">
<head>
<meta charset="utf-8" />
{{/* https://www.zachleat.com/web/preload/ */}}
<link
rel="preload"
href="{{ "fonts/muli-latin-200.woff2" | absURL }}"
as="font"
type="font/woff2"
crossorigin />
<link
rel="preload"
href="{{ "fonts/muli-latin-400.woff2" | absURL }}"
as="font"
type="font/woff2"
crossorigin />
<link
rel="preload"
href="{{ "fonts/muli-latin-800.woff2" | absURL }}"
as="font"
type="font/woff2"
crossorigin />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
{{/* NOTE: the Site's title, and if there is a page title, that is set too */}}
<title>
{{ block "title" . }}
{{ with .Title }}{{ . }} | {{ end }}{{ .Site.Title }}
{{ end }}
</title>
<meta name="viewport" content="width=device-width,minimum-scale=1" />
{{ hugo.Generator }}
{{ if hugo.IsProduction }}
<meta name="robots" content="index, follow" />
{{ else }}
<meta name="robots" content="noindex, nofollow" />
{{ end }}
{{ range .AlternativeOutputFormats -}}
<link
rel="{{ .Rel }}"
type="{{ .MediaType.Type }}"
href="{{ .Permalink | safeURL }}" />
{{ end -}}
{{ $isDev := eq hugo.Environment "development" }}
{{ $stylesheet := resources.Get "output/css/app.css" }}
{{ if not $isDev }}
{{ $stylesheet = $stylesheet | minify | fingerprint }}
{{ end }}
{{ with $stylesheet }}
{{ if $isDev }}
<link
rel="stylesheet"
href="{{ .RelPermalink }}"
crossorigin="anonymous" />
{{ else }}
<link
rel="stylesheet"
href="{{ .RelPermalink }}"
integrity="{{ .Data.Integrity }}"
crossorigin="anonymous" />
{{ end }}
{{ $.Scratch.Set "stylesheet" . }}
{{ end }}
<meta
name="description"
content="{{ with .Description }}
{{ . }}
{{ else }}
{{ with .Site.Params.description }}{{ . }}{{ end }}
{{ end }}
" />
{{ block "scripts" . }}
{{- partial "site-scripts.html" . -}}
{{ end }}
{{ partial "site-manifest.html" . }}
{{- partial "head-additions.html" . -}}
{{- partial "opengraph/opengraph.html" . -}}
{{- template "_internal/schema.html" . -}}
{{- partial "opengraph/twitter_cards.html" . -}}
{{ if hugo.IsProduction }}
{{ partial "gtag.html" . }}
{{ end }}
{{ $hasMath := .Param "math" }}
{{ if $hasMath }}
{{ partialCached "math.html" . }}
{{ end }}
</head>
<body
class="ma0 sans-serif bg-primary-color-light{{ with getenv "HUGO_ENV" }}
{{ . }}
{{ end }} {{ if $hasMath }}{{ print " dn" }}{{ end }}">
{{ partial "hooks/after-body-start.html" . }}
{{ block "nav" . }}{{ partial "site-nav.html" . }}{{ end }}
{{ block "header" . }}{{ end }}
<main role="main" class="content-with-sidebar min-vh-100 pb7 pb0-ns">
{{ block "main" . }}{{ end }}
</main>
{{ block "footer" . }}{{ partialCached "site-footer.html" . }}{{ end }}
{{ partial "hooks/before-body-end.html" . }}
</body>
</html>

View file

@ -0,0 +1,16 @@
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<script>
MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']], // inline
displayMath: [['$$', '$$'], ['\\[', '\\]']] // block
},
startup: {
pageReady: () => {
return MathJax.startup.defaultPageReady().then(() => {
document.body.classList.remove("dn");
});
}
}
};
</script>