Skip to content

Commit a3ebfb2

Browse files
author
drewgo
committed
add hugo version without this build fails in netlify
1 parent dda8b89 commit a3ebfb2

File tree

1 file changed

+63
-38
lines changed

1 file changed

+63
-38
lines changed

Diff for: content/docs/hugo.md

+63-38
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ group: Guides
33
weight: 20
44
title: Hugo
55
---
6+
67
## Introduction
78

89
This guide will walk you through how to integrate Decap CMS with Hugo. This is a good place to start if you want to learn from the ground up how these two tools work together. If you want to get up-and-running quicker, you can use one of the pre-existing and amazing [starter templates](/docs/start-with-a-template/)!
@@ -90,22 +91,43 @@ backend:
9091
media_folder: static/img
9192
public_folder: /img
9293
collections:
93-
- name: 'blog'
94-
label: 'Blog'
95-
folder: 'content/blog'
94+
- name: "blog"
95+
label: "Blog"
96+
folder: "content/blog"
9697
create: true
97-
slug: '{{year}}-{{month}}-{{day}}-{{slug}}'
98+
slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
9899
editor:
99100
preview: false
100101
fields:
101-
- { label: 'Title', name: 'title', widget: 'string' }
102-
- { label: 'Publish Date', name: 'date', widget: 'datetime' }
103-
- { label: 'Description', name: 'description', widget: 'string' }
104-
- { label: 'Body', name: 'body', widget: 'markdown' }
102+
- { label: "Title", name: "title", widget: "string" }
103+
- { label: "Publish Date", name: "date", widget: "datetime" }
104+
- { label: "Description", name: "description", widget: "string" }
105+
- { label: "Body", name: "body", widget: "markdown" }
105106
```
106107
107108
**Note:** You won't be able to access the CMS just yet — you still need to deploy the project with **Netlify** and authenticate with **Netlify Identity**. You'll handle this in the next few steps of this guide.
108109
110+
### Configuring Netlify Build Settings
111+
112+
To ensure consistent builds on Netlify, create a `netlify.toml` configuration file at your project's root with these settings:
113+
114+
```toml
115+
[build]
116+
command = "hugo"
117+
publish = "public"
118+
119+
[context.production.environment]
120+
HUGO_VERSION = "0.128.0"
121+
```
122+
123+
This configuration:
124+
125+
1. Specifies the exact Hugo version Netlify should use (match this to your local Hugo version)
126+
2. Defines the build command that generates your site
127+
3. Sets the publish directory to Hugo's default output folder
128+
129+
**Note:** Explicitly setting the Hugo version prevents unexpected build issues from version mismatches between your local environment and Netlify's auto-detected version.
130+
109131
### Pushing to GitHub
110132

111133
It's now time to commit your changes and push to GitHub. You can run the following commands to initialize a git repository and push the changes so far.
@@ -163,9 +185,7 @@ In your `layouts/index.html` file, you'll create an unordered list element and u
163185
<ul>
164186
{{ range (where .Pages "Section" "blog") }}
165187
<li>
166-
<a href="{{ .RelPermalink }}">
167-
{{ .Title }}
168-
</a>
188+
<a href="{{ .RelPermalink }}"> {{ .Title }} </a>
169189
</li>
170190
{{ end }}
171191
</ul>
@@ -191,9 +211,7 @@ Create a file `layouts/blog/single.html`, and put the following content in there
191211
<h1>{{ .Title }}</h1>
192212
<p class="date">{{ .Date }}</p>
193213
<p class="description">{{ .Params.description }}</p>
194-
<article class="content">
195-
{{ .Content }}
196-
</article>
214+
<article class="content">{{ .Content }}</article>
197215
</body>
198216
</html>
199217
```
@@ -210,32 +228,39 @@ You can refer to [registering editor components](https://www.decapcms.org/docs/c
210228

211229
```javascript
212230
CMS.registerEditorComponent({
213-
id: "gist",
214-
label: "Gist",
215-
fields: [{
216-
name: "username",
217-
label: "GitHub Username",
218-
widget: "string"
219-
},
220-
{
221-
name: "gid",
222-
label: "Gist ID",
223-
widget: "string"
224-
},
225-
],
226-
pattern: /^{{< gist ([a-zA-Z0-9]+) ([a-zA-Z0-9]+) >}}/,
227-
fromBlock: function(match) {
228-
return {
229-
username: match[1],
230-
gid: match[2],
231-
};
232-
},
233-
toBlock: function(obj) {
234-
return `{{< gist ${obj.username} ${obj.gid} >}}`;
231+
id: "gist",
232+
label: "Gist",
233+
fields: [
234+
{
235+
name: "username",
236+
label: "GitHub Username",
237+
widget: "string",
235238
},
236-
toPreview: function(obj) {
237-
return '<a href="https://gist.github.com/' + obj.username + '/' + obj.id + '">gist</a>';
239+
{
240+
name: "gid",
241+
label: "Gist ID",
242+
widget: "string",
238243
},
244+
],
245+
pattern: /^{{< gist ([a-zA-Z0-9]+) ([a-zA-Z0-9]+) >}}/,
246+
fromBlock: function (match) {
247+
return {
248+
username: match[1],
249+
gid: match[2],
250+
};
251+
},
252+
toBlock: function (obj) {
253+
return `{{< gist ${obj.username} ${obj.gid} >}}`;
254+
},
255+
toPreview: function (obj) {
256+
return (
257+
'<a href="https://gist.github.com/' +
258+
obj.username +
259+
"/" +
260+
obj.id +
261+
'">gist</a>'
262+
);
263+
},
239264
});
240265
```
241266

0 commit comments

Comments
 (0)