blob: b751f657044c1e087099341a795e485e877cfa87 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#+TITLE: Hugo Org-Mode Default Archetype
#+DATE: 2020-06-24T16:45:56-04:00
#+DRAFT: false
#+DESCRIPTION: Setting up an org-mode archetype in Hugo
#+TAGS[]: hugo org-mode
#+KEYWORDS[]: hugo org-mode
#+SLUG:
#+SUMMARY:
#+ATTR_HTML: :title hugo org archetype
#+ATTR_HTML: :alt hugo org archetype
[[file:cover.png]]
I love using [[https://gohugo.io/content-management/archetypes/][Hugo]] to write. Their [[https://orgmode.org/][org-mode]] markup support is
absolutely top notch. The only real problem with it is that while it's
well supported, the Hugo docs don't cover it very much, as [[https://daringfireball.net/projects/markdown/][Markdown]]
and [[https://toml.io/en/][TOML]] are the main markup and configuration languages.
One of the basic building blocks for Hugo blogs are
[[https://gohugo.io/content-management/archetypes/][Archetypes]]. Archetypes get used as the templates for new posts, and
get automatically filled out with the title of the post and creation
date.
Instead of writing the front matter of my posts in TOML, I use
org-mode syntax, to keep the entire document uniformly org-ish.
To setup an org-mode archetype, create the file =[site
root]/archetypes/default.org= with the following contents:
#+BEGIN_SRC org
#+TITLE: {{ replace .Name "-" " " | title }}
#+DATE: {{ .Date }}
#+DRAFT: true
#+DESCRIPTION:
#+TAGS[]:
#+KEYWORDS[]:
#+SLUG:
#+SUMMARY:
#+END_SRC
While this template doesn't contain every predefined front matter
variable, it contains all of the ones I use regularly. You can find a
full list of predefined variables [[https://gohugo.io/content-management/front-matter/][here]]. It doesn't hurt to have more
variables in the template than you use, as empty variables are not
used in the output. The org-mode front matter ends at the first line
that doesn't start with =#+=.
The theme you use may also have its own custom front matter
variables.
Now when I create a post, if the name of the post ends in =.org=, the
=default.org= archetype file is used. For example to create this post,
I ran
#+BEGIN_SRC shell
hugo new posts/hugo-org-archetype.org
#+END_SRC
Then I open it in Emacs and start typing!
|