feat: reimplement pathAlias for yaml fields
All checks were successful
Build and Push Server / build-and-push (push) Successful in 7m4s
All checks were successful
Build and Push Server / build-and-push (push) Successful in 7m4s
This commit is contained in:
@@ -33,6 +33,13 @@ func Yaml(input string, block template.Block) (value any, error error) {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, alias := range f.PathAliases {
|
||||
if value, ok := res[alias]; ok {
|
||||
out = utils.SetPathValue(f.Path, value, out)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if value, ok := renderUtils.GetValueFromPath(res, f.Path); ok {
|
||||
out = utils.SetPathValue(f.Path, value, out)
|
||||
continue
|
||||
|
||||
@@ -87,7 +87,8 @@ My favourite baguette recipe
|
||||
return;
|
||||
}
|
||||
try {
|
||||
compileTemplate(templateValue);
|
||||
const compiledTemplate = compileTemplate(templateValue);
|
||||
console.log({ compiledTemplate, templateValue });
|
||||
|
||||
const result = templateValue
|
||||
? parseMarkdownWithTemplate(markdownValue, templateValue)
|
||||
|
||||
Binary file not shown.
@@ -14,6 +14,7 @@
|
||||
- path: about
|
||||
- path: url
|
||||
- path: author.name
|
||||
pathAlias: author
|
||||
- path: author._type
|
||||
codec: const
|
||||
value: Person
|
||||
@@ -21,11 +22,14 @@
|
||||
- path: datePublished
|
||||
- path: articleSection
|
||||
- path: reviewRating.ratingValue
|
||||
pathAlias: rating
|
||||
pathAlias:
|
||||
- rating
|
||||
- path: reviewRating.bestRating
|
||||
value: 5
|
||||
codec: const
|
||||
hidden: true
|
||||
- path: reviewRating.worstRating
|
||||
value: 1
|
||||
codec: const
|
||||
hidden: true
|
||||
}
|
||||
|
||||
@@ -17,8 +17,12 @@
|
||||
hidden: true
|
||||
value: Person
|
||||
- path: author.name
|
||||
pathAlias:
|
||||
- author
|
||||
- path: author.email
|
||||
- path: datePublished
|
||||
pathAlias:
|
||||
- date
|
||||
- path: prepTime
|
||||
- path: cookTime
|
||||
- path: recipeYield
|
||||
|
||||
@@ -13,13 +13,17 @@
|
||||
- path: tmdbId
|
||||
- path: image
|
||||
- path: author.name
|
||||
pathAlias: author
|
||||
- path: author._type
|
||||
codec: const
|
||||
value: Person
|
||||
hidden: true
|
||||
- path: datePublished
|
||||
- path: itemReviewed.name
|
||||
pathAlias:
|
||||
- date
|
||||
- path: reviewRating.ratingValue
|
||||
pathAlias:
|
||||
- rating
|
||||
- path: reviewRating.bestRating
|
||||
codec: const
|
||||
value: 5
|
||||
|
||||
@@ -9,11 +9,13 @@ cmd = "go build -o ./tmp/marka-server ./cmd/marka-server"
|
||||
bin = "./tmp/marka-server"
|
||||
|
||||
# Command to run the application with arguments.
|
||||
full_bin = "./tmp/marka-server -root=../examples -addr=:8080"
|
||||
full_bin = "./tmp/marka-server -root=/home/max/Notes/resources -addr=:8080 -playground-root=./playground"
|
||||
|
||||
# Watch these file extensions.
|
||||
include_ext = ["go", "http"]
|
||||
|
||||
include_dir = ["../registry","../renderer","../template"]
|
||||
|
||||
# Ignore these directories.
|
||||
exclude_dir = ["tmp"]
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ type yamlField struct {
|
||||
Value any `yaml:"value,omitempty"`
|
||||
Codec string `yaml:"codec"`
|
||||
Hidden bool `yaml:"hidden,omitempty"`
|
||||
PathAlias string `yaml:"pathAlias,omitempty"`
|
||||
PathAlias []string `yaml:"pathAlias,omitempty"`
|
||||
}
|
||||
|
||||
func parseYamlTemplate(input Slice) (block Block, err error) {
|
||||
@@ -53,6 +53,7 @@ func parseYamlTemplate(input Slice) (block Block, err error) {
|
||||
var fields []BlockField
|
||||
|
||||
for _, field := range blk.Fields {
|
||||
|
||||
if field.Path == "" {
|
||||
return block, fmt.Errorf("failed to parse field: %v", field)
|
||||
}
|
||||
@@ -66,18 +67,22 @@ func parseYamlTemplate(input Slice) (block Block, err error) {
|
||||
return block, fmt.Errorf("failed to parse codec -> %w", err)
|
||||
}
|
||||
|
||||
fields = append(fields, BlockField{
|
||||
block := BlockField{
|
||||
Path: field.Path,
|
||||
PathAliases: field.PathAlias,
|
||||
CodecType: fieldCodec,
|
||||
Value: field.Value,
|
||||
Hidden: field.Hidden,
|
||||
})
|
||||
}
|
||||
|
||||
fields = append(fields, block)
|
||||
|
||||
}
|
||||
|
||||
return Block{
|
||||
Type: DataBlock,
|
||||
Path: blk.Path,
|
||||
PathAliases: blk.PathAlias,
|
||||
Codec: codec,
|
||||
Fields: fields,
|
||||
ListTemplate: blk.ListTemplate,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package template
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CompileTemplate scans once, emitting:
|
||||
// - data blocks: inner content between a line that's exactly "{" and a line that's exactly "}"
|
||||
|
||||
@@ -9,6 +9,7 @@ const (
|
||||
|
||||
type BlockField struct {
|
||||
Path string
|
||||
PathAliases []string
|
||||
CodecType CodecType
|
||||
Value any
|
||||
Hidden bool
|
||||
@@ -17,6 +18,7 @@ type BlockField struct {
|
||||
type Block struct {
|
||||
Type BlockType
|
||||
Path string
|
||||
PathAliases []string
|
||||
Codec CodecType
|
||||
ListTemplate string
|
||||
Fields []BlockField
|
||||
|
||||
Reference in New Issue
Block a user