diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-09-19 07:48:17 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-09-23 19:27:23 +0200 |
commit | 2650fa772b40846d9965f8c5f169286411f3beb2 (patch) | |
tree | 26d209ebea23611c146d851cb12827e793eaf6d5 /hugolib | |
parent | ef525b15d4584886b52428bd7a35de835ab07a48 (diff) |
Add directory based archetypes
Given this content:
```bash
archetypes
├── default.md
└── post-bundle
├── bio.md
├── images
│ └── featured.jpg
└── index.md
```
```bash
hugo new --kind post-bundle post/my-post
```
Will create a new folder in `/content/post/my-post` with the same set of files as in the `post-bundle` archetypes folder.
This commit also improves the archetype language detection, so, if you use template code in your content files, the `.Site` you get is for the correct language. This also means that it is now possible to translate strings defined in the `i18n` bundles, e.g. `{{ i18n "hello" }}`.
Fixes #4535
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/fileInfo.go | 4 | ||||
-rw-r--r-- | hugolib/hugo_sites.go | 8 | ||||
-rw-r--r-- | hugolib/page_bundler_capture.go | 2 | ||||
-rw-r--r-- | hugolib/site.go | 2 |
4 files changed, 12 insertions, 4 deletions
diff --git a/hugolib/fileInfo.go b/hugolib/fileInfo.go index 90cf91377..e4af42fd3 100644 --- a/hugolib/fileInfo.go +++ b/hugolib/fileInfo.go @@ -61,7 +61,7 @@ func (fi *fileInfo) isOwner() bool { return fi.bundleTp > bundleNot } -func isContentFile(filename string) bool { +func IsContentFile(filename string) bool { return contentFileExtensionsSet[strings.TrimPrefix(helpers.Ext(filename), ".")] } @@ -98,7 +98,7 @@ const ( // Returns the given file's name's bundle type and whether it is a content // file or not. func classifyBundledFile(name string) (bundleDirType, bool) { - if !isContentFile(name) { + if !IsContentFile(name) { return bundleNot, false } if strings.HasPrefix(name, "_index.") { diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index 88715a86e..3ff31ece3 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -57,6 +57,14 @@ func (h *HugoSites) IsMultihost() bool { return h != nil && h.multihost } +func (h *HugoSites) LanguageSet() map[string]bool { + set := make(map[string]bool) + for _, s := range h.Sites { + set[s.Language.Lang] = true + } + return set +} + func (h *HugoSites) NumLogErrors() int { if h == nil { return 0 diff --git a/hugolib/page_bundler_capture.go b/hugolib/page_bundler_capture.go index 6fe413014..fbfad0103 100644 --- a/hugolib/page_bundler_capture.go +++ b/hugolib/page_bundler_capture.go @@ -76,7 +76,7 @@ func newCapturer( isBundleHeader := func(filename string) bool { base := filepath.Base(filename) name := helpers.Filename(base) - return isContentFile(base) && (name == "index" || name == "_index") + return IsContentFile(base) && (name == "index" || name == "_index") } // Make sure that any bundle header files are processed before the others. This makes diff --git a/hugolib/site.go b/hugolib/site.go index 14f51f978..0eb4d7dfe 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -795,7 +795,7 @@ func (s *Site) processPartial(events []fsnotify.Event) (whatChanged, error) { removed = true } } - if removed && isContentFile(ev.Name) { + if removed && IsContentFile(ev.Name) { h.removePageByFilename(ev.Name) } |