Skip to content

Commit

Permalink
Merge pull request #357 from Kostov6/remove-md-defaulting
Browse files Browse the repository at this point in the history
Remove defaulting of files to `md`. `fileTree` won't load files without md suffix
  • Loading branch information
RadaBDimitrova authored Nov 28, 2024
2 parents 0dc9df3 + 3c875fc commit 918e444
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
29 changes: 11 additions & 18 deletions pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,17 @@ func resolveRelativeLinks(node *Node, _ *Node, manifest *Node, r registry.Interf
}

func extractFilesFromNode(node *Node, parent *Node, manifest *Node, r registry.Interface) error {
switch node.Type {
case "file":
if !strings.HasSuffix(node.File, ".md") {
node.File += ".md"
}
case "fileTree":
files, err := r.Tree(node.FileTree)
if err != nil {
return err
}
if err := constructNodeTree(files, node, parent); err != nil {
return err
}
removeNodeFromParent(node, parent)
if node.Type != "fileTree" {
return nil
}
files, err := r.Tree(node.FileTree)
if err != nil {
return err
}
if err := constructNodeTree(files, node, parent); err != nil {
return err
}
removeNodeFromParent(node, parent)
return nil
}

Expand All @@ -222,7 +218,7 @@ func constructNodeTree(files []string, node *Node, parent *Node) error {
pathToDirNode[node.Path] = parent
for _, file := range files {
extension := path.Ext(file)
if extension != ".md" && extension != "" {
if extension != ".md" {
continue
}
shouldExclude := false
Expand All @@ -245,9 +241,6 @@ func constructNodeTree(files []string, node *Node, parent *Node) error {
return err
}
fileName := path.Base(file)
if !strings.HasSuffix(fileName, ".md") {
fileName = fileName + ".md"
}
filePath := path.Join(node.Path, path.Dir(file))
parentNode := getParrentNode(pathToDirNode, filePath)
parentNode.Structure = append(parentNode.Structure, &Node{
Expand Down
2 changes: 1 addition & 1 deletion pkg/manifest/tests/manifests/index_md_with_properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ structure:
# _index.md with full path
- file: https://github.com/gardener/docforge/blob/master/contents/website/blog/2024/_index.md
# renamed _index.md file
- file: renamed
- file: renamed.md
source: https://github.com/gardener/docforge/blob/master/contents/website/blog/2024/_index.md
# importing _index.md from filetree
- fileTree: /contents/website
2 changes: 1 addition & 1 deletion pkg/manifest/tests/manifests/multisource.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
structure:
- file: testo
- file: testo.md
multiSource:
- /contents/blogs/2024/foo.md
- /contents/blogs/2024/two.md

0 comments on commit 918e444

Please sign in to comment.