source: Make ContentBaseName() return the directory for branch bundles
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 1 Nov 2021 19:30:34 +0000 (20:30 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 1 Nov 2021 20:06:39 +0000 (21:06 +0100)
Fixes #9112

create/content_test.go
source/fileInfo.go

index 802e494c4ebc2a9b4f637f92c6639ae062fb35ed..6f0ed8c86cc3bddc305c3d0cb37b3be60c27fc22 100644 (file)
@@ -50,6 +50,8 @@ func TestNewContent(t *testing.T) {
                {"No archetype", "", "sample-3.md", []string{`title: "Sample 3"`}},                        // no archetype
                {"Empty archetype", "product", "product/sample-4.md", []string{`title = "SAMPLE-4"`}},     // empty archetype front matter
                {"Filenames", "filenames", "content/mypage/index.md", []string{"title = \"INDEX\"\n+++\n\n\nContentBaseName: mypage"}},
+               {"Branch Name", "name", "content/tags/tag-a/_index.md", []string{"+++\ntitle = 'Tag A'\n+++"}},
+
                {"Lang 1", "lang", "post/lang-1.md", []string{`Site Lang: en|Name: Lang 1|i18n: Hugo Rocks!`}},
                {"Lang 2", "lang", "post/lang-2.en.md", []string{`Site Lang: en|Name: Lang 2|i18n: Hugo Rocks!`}},
                {"Lang nn file", "lang", "content/post/lang-3.nn.md", []string{`Site Lang: nn|Name: Lang 3|i18n: Hugo Rokkar!`}},
@@ -274,6 +276,12 @@ title: Test
                        path:    filepath.Join("archetypes", "post.org"),
                        content: "#+title: {{ .BaseFileName  | upper }}",
                },
+               {
+                       path: filepath.Join("archetypes", "name.md"),
+                       content: `+++
+title = '{{ replace .Name "-" " " | title }}'
++++`,
+               },
                {
                        path: filepath.Join("archetypes", "product.md"),
                        content: `+++
index cef44f8ca4c2658bc7bacb396ae80d35b6bd48b6..606b8b02572cd0407a26042e9571e0bf6c5a828a 100644 (file)
@@ -120,7 +120,7 @@ type FileInfo struct {
        translationBaseName string
        contentBaseName     string
        section             string
-       isLeafBundle        bool
+       classifier          files.ContentClass
 
        uniqueID string
 
@@ -199,12 +199,12 @@ func (fi *FileInfo) init() {
                relDir := strings.Trim(fi.relDir, helpers.FilePathSeparator)
                parts := strings.Split(relDir, helpers.FilePathSeparator)
                var section string
-               if (!fi.isLeafBundle && len(parts) == 1) || len(parts) > 1 {
+               if (fi.classifier != files.ContentClassLeaf && len(parts) == 1) || len(parts) > 1 {
                        section = parts[0]
                }
                fi.section = section
 
-               if fi.isLeafBundle && len(parts) > 0 {
+               if fi.classifier.IsBundle() && len(parts) > 0 {
                        fi.contentBaseName = parts[len(parts)-1]
                } else {
                        fi.contentBaseName = fi.translationBaseName
@@ -238,7 +238,6 @@ func (sp *SourceSpec) NewFileInfo(fi hugofs.FileMetaInfo) (*FileInfo, error) {
 
        filename := m.Filename
        relPath := m.Path
-       isLeafBundle := m.Classifier == files.ContentClassLeaf
 
        if relPath == "" {
                return nil, errors.Errorf("no Path provided by %v (%T)", m, m.Fs)
@@ -287,7 +286,7 @@ func (sp *SourceSpec) NewFileInfo(fi hugofs.FileMetaInfo) (*FileInfo, error) {
                name:                name,
                baseName:            baseName, // BaseFileName()
                translationBaseName: translationBaseName,
-               isLeafBundle:        isLeafBundle,
+               classifier:          m.Classifier,
        }
 
        return f, nil