diff options
Diffstat (limited to 'hugolib/content_factory.go')
-rw-r--r-- | hugolib/content_factory.go | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/hugolib/content_factory.go b/hugolib/content_factory.go index e22f46513..e6b0fb506 100644 --- a/hugolib/content_factory.go +++ b/hugolib/content_factory.go @@ -22,7 +22,8 @@ import ( "time" "github.com/gohugoio/hugo/common/htime" - "github.com/gohugoio/hugo/helpers" + "github.com/gohugoio/hugo/common/paths" + "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/source" @@ -42,25 +43,17 @@ type ContentFactory struct { } // ApplyArchetypeFilename archetypeFilename to w as a template using the given Page p as the foundation for the data context. -func (f ContentFactory) ApplyArchetypeFilename(w io.Writer, p page.Page, archetypeKind, archetypeFilename string) error { - - fi, err := f.h.SourceFilesystems.Archetypes.Fs.Stat(archetypeFilename) - if err != nil { - return err - } - +func (f ContentFactory) ApplyArchetypeFi(w io.Writer, p page.Page, archetypeKind string, fi hugofs.FileMetaInfo) error { if fi.IsDir() { - return fmt.Errorf("archetype directory (%q) not supported", archetypeFilename) + return fmt.Errorf("archetype directory (%q) not supported", fi.Meta().Filename) } - templateSource, err := afero.ReadFile(f.h.SourceFilesystems.Archetypes.Fs, archetypeFilename) + templateSource, err := fi.Meta().ReadAll() if err != nil { - return fmt.Errorf("failed to read archetype file %q: %s: %w", archetypeFilename, err, err) - + return fmt.Errorf("failed to read archetype file %q: %s: %w", fi.Meta().Filename, err, err) } return f.ApplyArchetypeTemplate(w, p, archetypeKind, string(templateSource)) - } // ApplyArchetypeTemplate templateSource to w as a template using the given Page p as the foundation for the data context. @@ -84,7 +77,7 @@ func (f ContentFactory) ApplyArchetypeTemplate(w io.Writer, p page.Page, archety return fmt.Errorf("failed to parse archetype template: %s: %w", err, err) } - result, err := executeToString(context.TODO(), ps.s.Tmpl(), templ, d) + result, err := executeToString(context.Background(), ps.s.Tmpl(), templ, d) if err != nil { return fmt.Errorf("failed to execute archetype template: %s: %w", err, err) } @@ -92,7 +85,6 @@ func (f ContentFactory) ApplyArchetypeTemplate(w io.Writer, p page.Page, archety _, err = io.WriteString(w, f.shortcodeReplacerPost.Replace(result)) return err - } func (f ContentFactory) SectionFromFilename(filename string) (string, error) { @@ -102,7 +94,7 @@ func (f ContentFactory) SectionFromFilename(filename string) (string, error) { return "", err } - parts := strings.Split(helpers.ToSlashTrimLeading(rel), "/") + parts := strings.Split(paths.ToSlashTrimLeading(rel), "/") if len(parts) < 2 { return "", nil } @@ -114,7 +106,6 @@ func (f ContentFactory) SectionFromFilename(filename string) (string, error) { func (f ContentFactory) CreateContentPlaceHolder(filename string, force bool) (string, error) { filename = filepath.Clean(filename) _, abs, err := f.h.AbsProjectContentDir(filename) - if err != nil { return "", err } @@ -169,7 +160,7 @@ type archetypeFileData struct { // File is the same as Page.File, embedded here for historic reasons. // TODO(bep) make this a method. - source.File + *source.File } func (f *archetypeFileData) Site() page.Site { |