diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-10-13 08:12:06 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-10-16 15:22:03 +0200 |
commit | 9185e11effa682ea1ef7dc98f2943743671023a6 (patch) | |
tree | f89d4138ddffd163a2afcd814ed2c26d3c66c4c9 /hugolib/filesystems | |
parent | 168a3aab4622786ccd0943137fce3912707f2a46 (diff) |
Reimplement archetypes
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.
This new implementation is using the exact same code path for evaluating the pages as in a regular build.
This also makes it more robust and easier to reason about in a multilingual setup.
Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:
```bash
hugo new content/en/posts/my-first-post.md
```
Fixes #9032
Fixes #7589
Fixes #9043
Fixes #9046
Fixes #9047
Diffstat (limited to 'hugolib/filesystems')
-rw-r--r-- | hugolib/filesystems/basefs.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index d238d2e03..dcfee34ff 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -102,6 +102,42 @@ func (b *BaseFs) RelContentDir(filename string) string { return filename } +// AbsProjectContentDir tries to create a TODO1 +func (b *BaseFs) AbsProjectContentDir(filename string) (string, string) { + isAbs := filepath.IsAbs(filename) + for _, dir := range b.SourceFilesystems.Content.Dirs { + meta := dir.Meta() + if meta.Module != "project" { + continue + } + if isAbs { + if strings.HasPrefix(filename, meta.Filename) { + return strings.TrimPrefix(filename, meta.Filename), filename + } + } else { + contentDir := strings.TrimPrefix(strings.TrimPrefix(meta.Filename, meta.BaseDir), filePathSeparator) + if strings.HasPrefix(filename, contentDir) { + relFilename := strings.TrimPrefix(filename, contentDir) + absFilename := filepath.Join(meta.Filename, relFilename) + return relFilename, absFilename + } + } + + } + + if !isAbs { + // A filename on the form "posts/mypage.md", put it inside + // the first content folder, usually <workDir>/content. + // The Dirs are ordered with the most important last, so pick that. + contentDirs := b.SourceFilesystems.Content.Dirs + firstContentDir := contentDirs[len(contentDirs)-1].Meta().Filename + return filename, filepath.Join(firstContentDir, filename) + + } + + return "", "" +} + // ResolveJSConfigFile resolves the JS-related config file to a absolute // filename. One example of such would be postcss.config.js. func (fs *BaseFs) ResolveJSConfigFile(name string) string { |