aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugofs
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-03-17 11:12:33 +0100
committerBjørn Erik Pedersen <[email protected]>2024-05-14 13:12:08 +0200
commite2d66e3218e180bbfca06ca3a29ce01957c513e9 (patch)
treeed29bb99cf16b75b6334e2fc618d31e80203e5d5 /hugofs
parent55dea41c1ab703f13b841389c6888815a033cf86 (diff)
downloadhugo-e2d66e3218e180bbfca06ca3a29ce01957c513e9.tar.gz
hugo-e2d66e3218e180bbfca06ca3a29ce01957c513e9.zip
Create pages from _content.gotmpl
Closes #12427 Closes #12485 Closes #6310 Closes #5074
Diffstat (limited to 'hugofs')
-rw-r--r--hugofs/files/classifier.go56
-rw-r--r--hugofs/files/classifier_test.go11
-rw-r--r--hugofs/walk.go10
3 files changed, 15 insertions, 62 deletions
diff --git a/hugofs/files/classifier.go b/hugofs/files/classifier.go
index a8d231f73..543d741d0 100644
--- a/hugofs/files/classifier.go
+++ b/hugofs/files/classifier.go
@@ -29,57 +29,13 @@ const (
FilenameHugoStatsJSON = "hugo_stats.json"
)
-var (
- // This should be the only list of valid extensions for content files.
- contentFileExtensions = []string{
- "html", "htm",
- "mdown", "markdown", "md",
- "asciidoc", "adoc", "ad",
- "rest", "rst",
- "org",
- "pandoc", "pdc",
- }
-
- contentFileExtensionsSet map[string]bool
-
- htmlFileExtensions = []string{
- "html", "htm",
- }
-
- htmlFileExtensionsSet map[string]bool
-)
-
-func init() {
- contentFileExtensionsSet = make(map[string]bool)
- for _, ext := range contentFileExtensions {
- contentFileExtensionsSet[ext] = true
- }
- htmlFileExtensionsSet = make(map[string]bool)
- for _, ext := range htmlFileExtensions {
- htmlFileExtensionsSet[ext] = true
- }
+func IsGoTmplExt(ext string) bool {
+ return ext == "gotmpl"
}
-func IsContentFile(filename string) bool {
- return contentFileExtensionsSet[strings.TrimPrefix(filepath.Ext(filename), ".")]
-}
-
-func IsIndexContentFile(filename string) bool {
- if !IsContentFile(filename) {
- return false
- }
-
- base := filepath.Base(filename)
-
- return strings.HasPrefix(base, "index.") || strings.HasPrefix(base, "_index.")
-}
-
-func IsHTML(ext string) bool {
- return htmlFileExtensionsSet[ext]
-}
-
-func IsContentExt(ext string) bool {
- return contentFileExtensionsSet[ext]
+// Supported data file extensions for _content.* files.
+func IsContentDataExt(ext string) bool {
+ return IsGoTmplExt(ext)
}
const (
@@ -93,6 +49,8 @@ const (
FolderResources = "resources"
FolderJSConfig = "_jsconfig" // Mounted below /assets with postcss.config.js etc.
+
+ NameContentData = "_content"
)
var (
diff --git a/hugofs/files/classifier_test.go b/hugofs/files/classifier_test.go
index f2fad56ca..b1a92faad 100644
--- a/hugofs/files/classifier_test.go
+++ b/hugofs/files/classifier_test.go
@@ -14,22 +14,11 @@
package files
import (
- "path/filepath"
"testing"
qt "github.com/frankban/quicktest"
)
-func TestIsContentFile(t *testing.T) {
- c := qt.New(t)
-
- c.Assert(IsContentFile(filepath.FromSlash("my/file.md")), qt.Equals, true)
- c.Assert(IsContentFile(filepath.FromSlash("my/file.ad")), qt.Equals, true)
- c.Assert(IsContentFile(filepath.FromSlash("textfile.txt")), qt.Equals, false)
- c.Assert(IsContentExt("md"), qt.Equals, true)
- c.Assert(IsContentExt("json"), qt.Equals, false)
-}
-
func TestComponentFolders(t *testing.T) {
c := qt.New(t)
diff --git a/hugofs/walk.go b/hugofs/walk.go
index 391f70a65..4af46d89e 100644
--- a/hugofs/walk.go
+++ b/hugofs/walk.go
@@ -23,6 +23,7 @@ import (
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/paths"
+ "github.com/gohugoio/hugo/media"
"github.com/spf13/afero"
)
@@ -50,7 +51,8 @@ type WalkwayConfig struct {
Root string
// The logger to use.
- Logger loggers.Logger
+ Logger loggers.Logger
+ PathParser *paths.PathParser
// One or both of these may be pre-set.
Info FileMetaInfo // The start info.
@@ -72,6 +74,10 @@ func NewWalkway(cfg WalkwayConfig) *Walkway {
panic("fs must be set")
}
+ if cfg.PathParser == nil {
+ cfg.PathParser = media.DefaultPathParser
+ }
+
logger := cfg.Logger
if logger == nil {
logger = loggers.NewDefault()
@@ -161,7 +167,7 @@ func (w *Walkway) walk(path string, info FileMetaInfo, dirEntries []FileMetaInfo
dirEntries = DirEntriesToFileMetaInfos(fis)
for _, fi := range dirEntries {
if fi.Meta().PathInfo == nil {
- fi.Meta().PathInfo = paths.Parse("", filepath.Join(pathRel, fi.Name()))
+ fi.Meta().PathInfo = w.cfg.PathParser.Parse("", filepath.Join(pathRel, fi.Name()))
}
}