feat: some stuff?
All checks were successful
Build and Push Server / build-and-push (push) Successful in 4m19s

This commit is contained in:
2026-02-10 18:24:39 +01:00
parent 137e3da6d4
commit f9c4b7bc05
7 changed files with 26 additions and 16 deletions

View File

@@ -16,7 +16,7 @@ func Yaml(input string, block template.Block) (value any, error error) {
return nil, fmt.Errorf("failed to parse yaml '%q': %w", input, err) return nil, fmt.Errorf("failed to parse yaml '%q': %w", input, err)
} }
var out any var out any // Keep out as any
for _, f := range block.Fields { for _, f := range block.Fields {
if f.Path == "@schema" { if f.Path == "@schema" {
@@ -25,8 +25,15 @@ func Yaml(input string, block template.Block) (value any, error error) {
if f.CodecType == template.CodecConst { if f.CodecType == template.CodecConst {
if f.Value != nil { if f.Value != nil {
// Only set const value if 'out' is a map and the path doesn't exist
if outMap, ok := out.(map[string]any); ok {
if _, exists := renderUtils.GetValueFromPath(outMap, f.Path); !exists {
out = utils.SetPathValue(f.Path, f.Value, out) out = utils.SetPathValue(f.Path, f.Value, out)
} }
} else if out == nil { // If out is nil, it's the first value, so set it
out = utils.SetPathValue(f.Path, f.Value, out)
}
}
} else { } else {
if value, ok := res[f.Path]; ok { if value, ok := res[f.Path]; ok {
out = utils.SetPathValue(f.Path, value, out) out = utils.SetPathValue(f.Path, value, out)

View File

@@ -3,6 +3,7 @@ package matcher
import ( import (
"math" "math"
"strings"
"git.max-richter.dev/max/marka/parser/utils" "git.max-richter.dev/max/marka/parser/utils"
"git.max-richter.dev/max/marka/template" "git.max-richter.dev/max/marka/template"
@@ -20,7 +21,7 @@ func (m Block) GetContent() string {
if m.src == nil || m.Start < 0 || m.End > len(*m.src) || m.Start > m.End { if m.src == nil || m.Start < 0 || m.End > len(*m.src) || m.Start > m.End {
return "" return ""
} }
return (*m.src)[m.Start:m.End] return strings.TrimSpace((*m.src)[m.Start:m.End])
} }
// MatchBlocksFuzzy finds anchor positions for all BlockMatching blocks using // MatchBlocksFuzzy finds anchor positions for all BlockMatching blocks using

View File

@@ -72,7 +72,7 @@ func TestMatch_FuzzyBlockBaguette(t *testing.T) {
value: "- Flour\n- Water\n- Salt", value: "- Flour\n- Water\n- Salt",
}, },
{ {
value: "1. Mix Flour Water and Salt\n2. Bake the bread\n", value: "1. Mix Flour Water and Salt\n2. Bake the bread",
}, },
} }
@@ -118,7 +118,7 @@ func TestMatch_FuzzyBlockSalad(t *testing.T) {
value: "- 100 g lettuce\n- 5 cherry tomatoes\n- 1 tbsp olive oil\n- Pinch of salt", value: "- 100 g lettuce\n- 5 cherry tomatoes\n- 1 tbsp olive oil\n- Pinch of salt",
}, },
{ {
value: "1. Wash and dry the lettuce.\n2. Halve the cherry tomatoes.\n3. Toss with olive oil and salt.\n", value: "1. Wash and dry the lettuce.\n2. Halve the cherry tomatoes.\n3. Toss with olive oil and salt.",
}, },
} }

View File

@@ -4,7 +4,6 @@ package parser
import ( import (
"fmt" "fmt"
"strings"
"git.max-richter.dev/max/marka/parser/decoders" "git.max-richter.dev/max/marka/parser/decoders"
"git.max-richter.dev/max/marka/parser/matcher" "git.max-richter.dev/max/marka/parser/matcher"
@@ -69,11 +68,6 @@ func ParseFileWithTemplate(markdownContent string, templateContent string) (any,
return nil, fmt.Errorf("failed to compile template -> %w", err) return nil, fmt.Errorf("failed to compile template -> %w", err)
} }
for strings.HasSuffix(markdownContent, "\n") {
markdownContent = strings.TrimSuffix(markdownContent, "\n")
}
markdownContent = markdownContent + "\n"
blocks := matcher.MatchBlocksFuzzy(markdownContent, tpl, 0.3) blocks := matcher.MatchBlocksFuzzy(markdownContent, tpl, 0.3)
result, err := decoders.Parse(blocks) result, err := decoders.Parse(blocks)

View File

@@ -66,6 +66,12 @@
{ {
"type": "string" "type": "string"
}, },
{
"type": "array",
"items": {
"type": "string"
}
},
{ {
"$ref": "schema:CreativeWork" "$ref": "schema:CreativeWork"
}, },

View File

@@ -11,6 +11,7 @@
codec: const codec: const
value: Review value: Review
- path: tmdbId - path: tmdbId
- path: isbn
- path: link - path: link
pathAlias: link pathAlias: link
- path: image - path: image

View File

@@ -35,13 +35,14 @@ func main() {
absPlaygroundRoot, err := filepath.Abs(*playgroundRoot) absPlaygroundRoot, err := filepath.Abs(*playgroundRoot)
must(err) must(err)
info, err := os.Stat(absPlaygroundRoot) info, err := os.Stat(absPlaygroundRoot)
must(err) if err == nil {
if !info.IsDir() { if !info.IsDir() {
log.Fatalf("playground-root %s is not a directory", *playgroundRoot) log.Fatalf("playground-root %s is not a directory", *playgroundRoot)
} }
log.Printf("serving playground from %s", absPlaygroundRoot) log.Printf("serving playground from %s", absPlaygroundRoot)
http.Handle("/_playground/", http.StripPrefix("/_playground/", http.FileServer(http.Dir(absPlaygroundRoot)))) http.Handle("/_playground/", http.StripPrefix("/_playground/", http.FileServer(http.Dir(absPlaygroundRoot))))
} }
}
if len(roots) == 0 { if len(roots) == 0 {
log.Fatal("at least one -root flag must be specified") log.Fatal("at least one -root flag must be specified")