mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
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
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user