- Update the skeleton structure to match the new template system.
- Add a --format flag to the `hugo new theme` command to control the
format of the site configuration and default archetype files.
- Remove theme.toml. This file's presence can be confusing for new
users, and the README in the themes repository already has an example.
- Remove the LICENSE and README files from the skeleton. These files
are not needed for a theme to work, and they can be added later by
the user if desired.
Closes #13489
Closes #13544
createpath := paths.AbsPathify(conf.configs.Base.WorkingDir, filepath.Join(conf.configs.Base.ThemesDir, args[0]))
r.Println("Creating new theme in", createpath)
- err = skeletons.CreateTheme(createpath, sourceFs)
+ err = skeletons.CreateTheme(createpath, sourceFs, format)
if err != nil {
return err
}
return nil
},
withc: func(cmd *cobra.Command, r *rootCommand) {
- cmd.ValidArgsFunction = cobra.NoFileCompletions
+ cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+ if len(args) != 0 {
+ return []string{}, cobra.ShellCompDirectiveNoFileComp
+ }
+ return []string{}, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveFilterDirs
+ }
+ cmd.Flags().StringVar(&format, "format", "toml", "preferred file format (toml, yaml or json)")
+ _ = cmd.RegisterFlagCompletionFunc("format", cobra.FixedCompletions([]string{"toml", "yaml", "json"}, cobra.ShellCompDirectiveNoFileComp))
},
},
},
var themeFs embed.FS
// CreateTheme creates a theme skeleton.
-func CreateTheme(createpath string, sourceFs afero.Fs) error {
+func CreateTheme(createpath string, sourceFs afero.Fs, format string) error {
if exists, _ := helpers.Exists(createpath, sourceFs); exists {
return errors.New(createpath + " already exists")
}
+
+ format = strings.ToLower(format)
+
+ siteConfig := map[string]any{
+ "baseURL": "https://example.org/",
+ "languageCode": "en-US",
+ "title": "My New Hugo Site",
+ "menus": map[string]any{
+ "main": []any{
+ map[string]any{
+ "name": "Home",
+ "pageRef": "/",
+ "weight": 10,
+ },
+ map[string]any{
+ "name": "Posts",
+ "pageRef": "/posts",
+ "weight": 20,
+ },
+ map[string]any{
+ "name": "Tags",
+ "pageRef": "/tags",
+ "weight": 30,
+ },
+ },
+ },
+ "module": map[string]any{
+ "hugoVersion": map[string]any{
+ "extended": false,
+ "min": "0.146.0",
+ },
+ },
+ }
+
+ err := createSiteConfig(sourceFs, createpath, siteConfig, format)
+ if err != nil {
+ return err
+ }
+
+ defaultArchetype := map[string]any{
+ "title": "{{ replace .File.ContentBaseName \"-\" \" \" | title }}",
+ "date": "{{ .Date }}",
+ "draft": true,
+ }
+
+ err = createDefaultArchetype(sourceFs, createpath, defaultArchetype, format)
+ if err != nil {
+ return err
+ }
+
return copyFiles(createpath, sourceFs, themeFs)
}
}
}
- err := newSiteCreateConfig(sourceFs, createpath, format)
+ siteConfig := map[string]any{
+ "baseURL": "https://example.org/",
+ "title": "My New Hugo Site",
+ "languageCode": "en-us",
+ }
+
+ err := createSiteConfig(sourceFs, createpath, siteConfig, format)
if err != nil {
return err
}
- err = newSiteCreateArchetype(sourceFs, createpath, format)
+ defaultArchetype := map[string]any{
+ "title": "{{ replace .File.ContentBaseName \"-\" \" \" | title }}",
+ "date": "{{ .Date }}",
+ "draft": true,
+ }
+
+ err = createDefaultArchetype(sourceFs, createpath, defaultArchetype, format)
if err != nil {
return err
}
})
}
-func newSiteCreateConfig(fs afero.Fs, createpath string, format string) (err error) {
- in := map[string]string{
- "baseURL": "https://example.org/",
- "title": "My New Hugo Site",
- "languageCode": "en-us",
- }
-
+func createSiteConfig(fs afero.Fs, createpath string, in map[string]any, format string) (err error) {
var buf bytes.Buffer
err = parser.InterfaceToConfig(in, metadecoders.FormatFromString(format), &buf)
if err != nil {
return helpers.WriteToDisk(filepath.Join(createpath, "hugo."+format), &buf, fs)
}
-func newSiteCreateArchetype(fs afero.Fs, createpath string, format string) (err error) {
- in := map[string]any{
- "title": "{{ replace .File.ContentBaseName \"-\" \" \" | title }}",
- "date": "{{ .Date }}",
- "draft": true,
- }
-
+func createDefaultArchetype(fs afero.Fs, createpath string, in map[string]any, format string) (err error) {
var buf bytes.Buffer
err = parser.InterfaceToFrontMatter(in, metadecoders.FormatFromString(format), &buf)
if err != nil {
+++ /dev/null
-MIT License
-
-Copyright (c) [year] [fullname]
-
-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 the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
+++ /dev/null
-# Theme Name
-
-## Features
-
-## Installation
-
-## Configuration
+++ /dev/null
-+++
-title = '{{ replace .File.ContentBaseName "-" " " | title }}'
-date = {{ .Date }}
-draft = true
-+++
+++ /dev/null
-baseURL = 'https://example.org/'
-languageCode = 'en-US'
-title = 'My New Hugo Site'
-
-[[menus.main]]
-name = 'Home'
-pageRef = '/'
-weight = 10
-
-[[menus.main]]
-name = 'Posts'
-pageRef = '/posts'
-weight = 20
-
-[[menus.main]]
-name = 'Tags'
-pageRef = '/tags'
-weight = 30
-
-[module]
- [module.hugoVersion]
- extended = false
- min = "0.116.0"
+++ /dev/null
-<!DOCTYPE html>
-<html lang="{{ site.Language.LanguageCode }}" dir="{{ or site.Language.LanguageDirection `ltr` }}">
-<head>
- {{ partial "head.html" . }}
-</head>
-<body>
- <header>
- {{ partial "header.html" . }}
- </header>
- <main>
- {{ block "main" . }}{{ end }}
- </main>
- <footer>
- {{ partial "footer.html" . }}
- </footer>
-</body>
-</html>
+++ /dev/null
-{{ define "main" }}
- {{ .Content }}
- {{ range site.RegularPages }}
- <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
- {{ .Summary }}
- {{ end }}
-{{ end }}
+++ /dev/null
-{{ define "main" }}
- <h1>{{ .Title }}</h1>
- {{ .Content }}
- {{ range .Pages }}
- <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
- {{ .Summary }}
- {{ end }}
-{{ end }}
+++ /dev/null
-{{ define "main" }}
- <h1>{{ .Title }}</h1>
-
- {{ $dateMachine := .Date | time.Format "2006-01-02T15:04:05-07:00" }}
- {{ $dateHuman := .Date | time.Format ":date_long" }}
- <time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>
-
- {{ .Content }}
- {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
-{{ end }}
--- /dev/null
+<p>Copyright {{ now.Year }}. All rights reserved.</p>
--- /dev/null
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width">
+<title>{{ if .IsHome }}{{ site.Title }}{{ else }}{{ printf "%s | %s" .Title site.Title }}{{ end }}</title>
+{{ partialCached "head/css.html" . }}
+{{ partialCached "head/js.html" . }}
--- /dev/null
+{{- with resources.Get "css/main.css" }}
+ {{- if hugo.IsDevelopment }}
+ <link rel="stylesheet" href="{{ .RelPermalink }}">
+ {{- else }}
+ {{- with . | minify | fingerprint }}
+ <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
+ {{- end }}
+ {{- end }}
+{{- end }}
--- /dev/null
+{{- with resources.Get "js/main.js" }}
+ {{- $opts := dict
+ "minify" (not hugo.IsDevelopment)
+ "sourceMap" (cond hugo.IsDevelopment "external" "")
+ "targetPath" "js/main.js"
+ }}
+ {{- with . | js.Build $opts }}
+ {{- if hugo.IsDevelopment }}
+ <script src="{{ .RelPermalink }}"></script>
+ {{- else }}
+ {{- with . | fingerprint }}
+ <script src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end }}
--- /dev/null
+<h1>{{ site.Title }}</h1>
+{{ partial "menu.html" (dict "menuID" "main" "page" .) }}
--- /dev/null
+{{- /*
+Renders a menu for the given menu ID.
+
+@context {page} page The current page.
+@context {string} menuID The menu ID.
+
+@example: {{ partial "menu.html" (dict "menuID" "main" "page" .) }}
+*/}}
+
+{{- $page := .page }}
+{{- $menuID := .menuID }}
+
+{{- with index site.Menus $menuID }}
+ <nav>
+ <ul>
+ {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
+ </ul>
+ </nav>
+{{- end }}
+
+{{- define "_partials/inline/menu/walk.html" }}
+ {{- $page := .page }}
+ {{- range .menuEntries }}
+ {{- $attrs := dict "href" .URL }}
+ {{- if $page.IsMenuCurrent .Menu . }}
+ {{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }}
+ {{- else if $page.HasMenuCurrent .Menu .}}
+ {{- $attrs = merge $attrs (dict "class" "ancestor" "aria-current" "true") }}
+ {{- end }}
+ {{- $name := .Name }}
+ {{- with .Identifier }}
+ {{- with T . }}
+ {{- $name = . }}
+ {{- end }}
+ {{- end }}
+ <li>
+ <a
+ {{- range $k, $v := $attrs }}
+ {{- with $v }}
+ {{- printf " %s=%q" $k $v | safeHTMLAttr }}
+ {{- end }}
+ {{- end -}}
+ >{{ $name }}</a>
+ {{- with .Children }}
+ <ul>
+ {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
+ </ul>
+ {{- end }}
+ </li>
+ {{- end }}
+{{- end }}
--- /dev/null
+{{- /*
+For a given taxonomy, renders a list of terms assigned to the page.
+
+@context {page} page The current page.
+@context {string} taxonomy The taxonomy.
+
+@example: {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
+*/}}
+
+{{- $page := .page }}
+{{- $taxonomy := .taxonomy }}
+
+{{- with $page.GetTerms $taxonomy }}
+ {{- $label := (index . 0).Parent.LinkTitle }}
+ <div>
+ <div>{{ $label }}:</div>
+ <ul>
+ {{- range . }}
+ <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
+ {{- end }}
+ </ul>
+ </div>
+{{- end }}
--- /dev/null
+<!DOCTYPE html>
+<html lang="{{ site.Language.LanguageCode }}" dir="{{ or site.Language.LanguageDirection `ltr` }}">
+<head>
+ {{ partial "head.html" . }}
+</head>
+<body>
+ <header>
+ {{ partial "header.html" . }}
+ </header>
+ <main>
+ {{ block "main" . }}{{ end }}
+ </main>
+ <footer>
+ {{ partial "footer.html" . }}
+ </footer>
+</body>
+</html>
--- /dev/null
+{{ define "main" }}
+ {{ .Content }}
+ {{ range site.RegularPages }}
+ <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
+ {{ .Summary }}
+ {{ end }}
+{{ end }}
--- /dev/null
+{{ define "main" }}
+ <h1>{{ .Title }}</h1>
+ {{ .Content }}
+ {{ range .Pages }}
+ <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
+ {{ .Summary }}
+ {{ end }}
+{{ end }}
+++ /dev/null
-<p>Copyright {{ now.Year }}. All rights reserved.</p>
+++ /dev/null
-<meta charset="utf-8">
-<meta name="viewport" content="width=device-width">
-<title>{{ if .IsHome }}{{ site.Title }}{{ else }}{{ printf "%s | %s" .Title site.Title }}{{ end }}</title>
-{{ partialCached "head/css.html" . }}
-{{ partialCached "head/js.html" . }}
+++ /dev/null
-{{- with resources.Get "css/main.css" }}
- {{- if eq hugo.Environment "development" }}
- <link rel="stylesheet" href="{{ .RelPermalink }}">
- {{- else }}
- {{- with . | minify | fingerprint }}
- <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
- {{- end }}
- {{- end }}
-{{- end }}
+++ /dev/null
-{{- with resources.Get "js/main.js" }}
- {{- if eq hugo.Environment "development" }}
- {{- with . | js.Build }}
- <script src="{{ .RelPermalink }}"></script>
- {{- end }}
- {{- else }}
- {{- $opts := dict "minify" true }}
- {{- with . | js.Build $opts | fingerprint }}
- <script src="{{ .RelPermalink }}" integrity="{{- .Data.Integrity }}" crossorigin="anonymous"></script>
- {{- end }}
- {{- end }}
-{{- end }}
+++ /dev/null
-<h1>{{ site.Title }}</h1>
-{{ partial "menu.html" (dict "menuID" "main" "page" .) }}
+++ /dev/null
-{{- /*
-Renders a menu for the given menu ID.
-
-@context {page} page The current page.
-@context {string} menuID The menu ID.
-
-@example: {{ partial "menu.html" (dict "menuID" "main" "page" .) }}
-*/}}
-
-{{- $page := .page }}
-{{- $menuID := .menuID }}
-
-{{- with index site.Menus $menuID }}
- <nav>
- <ul>
- {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
- </ul>
- </nav>
-{{- end }}
-
-{{- define "partials/inline/menu/walk.html" }}
- {{- $page := .page }}
- {{- range .menuEntries }}
- {{- $attrs := dict "href" .URL }}
- {{- if $page.IsMenuCurrent .Menu . }}
- {{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }}
- {{- else if $page.HasMenuCurrent .Menu .}}
- {{- $attrs = merge $attrs (dict "class" "ancestor" "aria-current" "true") }}
- {{- end }}
- {{- $name := .Name }}
- {{- with .Identifier }}
- {{- with T . }}
- {{- $name = . }}
- {{- end }}
- {{- end }}
- <li>
- <a
- {{- range $k, $v := $attrs }}
- {{- with $v }}
- {{- printf " %s=%q" $k $v | safeHTMLAttr }}
- {{- end }}
- {{- end -}}
- >{{ $name }}</a>
- {{- with .Children }}
- <ul>
- {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
- </ul>
- {{- end }}
- </li>
- {{- end }}
-{{- end }}
+++ /dev/null
-{{- /*
-For a given taxonomy, renders a list of terms assigned to the page.
-
-@context {page} page The current page.
-@context {string} taxonomy The taxonomy.
-
-@example: {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
-*/}}
-
-{{- $page := .page }}
-{{- $taxonomy := .taxonomy }}
-
-{{- with $page.GetTerms $taxonomy }}
- {{- $label := (index . 0).Parent.LinkTitle }}
- <div>
- <div>{{ $label }}:</div>
- <ul>
- {{- range . }}
- <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
- {{- end }}
- </ul>
- </div>
-{{- end }}
--- /dev/null
+{{ define "main" }}
+ <h1>{{ .Title }}</h1>
+
+ {{ $dateMachine := .Date | time.Format "2006-01-02T15:04:05-07:00" }}
+ {{ $dateHuman := .Date | time.Format ":date_long" }}
+ <time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>
+
+ {{ .Content }}
+ {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
+{{ end }}
--- /dev/null
+{{ define "main" }}
+ <h1>{{ .Title }}</h1>
+ {{ .Content }}
+ {{ range .Pages }}
+ <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
+ {{ end }}
+{{ end }}
--- /dev/null
+{{ define "main" }}
+ <h1>{{ .Title }}</h1>
+ {{ .Content }}
+ {{ range .Pages }}
+ <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
+ {{ end }}
+{{ end }}
+++ /dev/null
-name = 'Theme name'
-license = 'MIT'
-licenselink = 'https://github.com/owner/repo/LICENSE'
-description = 'Theme description'
-
-# The home page of the theme, where the source can be found
-homepage = 'https://github.com/owner/repo'
-
-# If you have a running demo of the theme
-demosite = 'https://owner.github.io/repo'
-
-# Taxonomy terms
-tags = ['blog', 'company']
-features = ['some', 'awesome', 'features']
-
-# If the theme has multiple authors
-authors = [
- {name = 'Name of author', homepage = 'Website of author'},
- {name = 'Name of author', homepage = 'Website of author'}
-]
-
-# If the theme has a single author
-[author]
- name = 'Your name'
- homepage = 'Your website'
-
-# If porting an existing theme
-[original]
- author = 'Name of original author'
- homepage = 'Website of original author'
- repo = 'https://github.com/owner/repo'
hugo new theme -h
stdout 'Create a new theme \(skeleton\) called \[name\] in ./themes'
-hugo new theme mytheme
+hugo new theme mytheme --format yml
stdout 'Creating new theme'
! exists resources
cd themes
checkfile content/posts/post-2.md
checkfile content/posts/post-3/bryce-canyon.jpg
checkfile content/posts/post-3/index.md
-checkfile layouts/_default/baseof.html
-checkfile layouts/_default/home.html
-checkfile layouts/_default/list.html
-checkfile layouts/_default/single.html
-checkfile layouts/partials/footer.html
-checkfile layouts/partials/head.html
-checkfile layouts/partials/head/css.html
-checkfile layouts/partials/head/js.html
-checkfile layouts/partials/header.html
-checkfile layouts/partials/menu.html
-checkfile layouts/partials/terms.html
+checkfile layouts/baseof.html
+checkfile layouts/home.html
+checkfile layouts/list.html
+checkfile layouts/single.html
+checkfile layouts/taxonomy.html
+checkfile layouts/term.html
+checkfile layouts/_partials/footer.html
+checkfile layouts/_partials/head.html
+checkfile layouts/_partials/head/css.html
+checkfile layouts/_partials/head/js.html
+checkfile layouts/_partials/header.html
+checkfile layouts/_partials/menu.html
+checkfile layouts/_partials/terms.html
checkfile static/favicon.ico
-checkfile LICENSE
-checkfile README.md
-checkfile hugo.toml
-checkfile theme.toml
+checkfile hugo.yml
exists data
exists i18n