wip
This commit is contained in:
@@ -23,8 +23,6 @@ func DetectType(markdownContent string) (string, error) {
|
||||
return "", fmt.Errorf("failed to compile template: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Content:", markdownContent)
|
||||
|
||||
blocks := matcher.MatchBlocksFuzzy(markdownContent, defaultSchema, 0.3)
|
||||
|
||||
result, err := decoders.Parse(blocks)
|
||||
@@ -32,28 +30,17 @@ func DetectType(markdownContent string) (string, error) {
|
||||
return "", fmt.Errorf("failed to parse blocks: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Result: ", result)
|
||||
|
||||
if result, ok := result.(map[string]any); ok {
|
||||
if contentType, ok := result["@type"]; ok {
|
||||
if contentType, ok := result["_type"]; ok {
|
||||
return contentType.(string), nil
|
||||
} else {
|
||||
return "", fmt.Errorf("frontmatter did not contain '@type'")
|
||||
}
|
||||
} else {
|
||||
return "", fmt.Errorf("could not parse frontmatter")
|
||||
return "", fmt.Errorf("frontmatter did not contain '_type'")
|
||||
}
|
||||
return "", fmt.Errorf("could not parse frontmatter")
|
||||
}
|
||||
|
||||
func prepareMarkdown(input string) string {
|
||||
input = strings.TrimSuffix(input, "\n")
|
||||
input = strings.ReplaceAll(input, "@type:", `"@type":`)
|
||||
input = strings.ReplaceAll(input, "@context:", `"@context":`)
|
||||
return input
|
||||
}
|
||||
|
||||
func ParseFile(markdownContent string) (any, error) {
|
||||
markdownContent = prepareMarkdown(markdownContent)
|
||||
func MatchBlocks(markdownContent string) ([]matcher.Block, error) {
|
||||
markdownContent = strings.TrimSuffix(markdownContent, "\n")
|
||||
|
||||
contentType, err := DetectType(markdownContent)
|
||||
if err != nil {
|
||||
@@ -65,12 +52,33 @@ func ParseFile(markdownContent string) (any, error) {
|
||||
return nil, fmt.Errorf("could not get schema: %w", err)
|
||||
}
|
||||
|
||||
template, err := template.CompileTemplate(templateContent)
|
||||
tpl, err := template.CompileTemplate(templateContent)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to compile template: %w", err)
|
||||
}
|
||||
|
||||
blocks := matcher.MatchBlocksFuzzy(markdownContent, template, 0.3)
|
||||
return matcher.MatchBlocksFuzzy(markdownContent, tpl, 0.3), nil
|
||||
}
|
||||
|
||||
func ParseFile(markdownContent string) (any, error) {
|
||||
markdownContent = strings.TrimSuffix(markdownContent, "\n")
|
||||
|
||||
contentType, err := DetectType(markdownContent)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not detect type: %w", err)
|
||||
}
|
||||
|
||||
templateContent, err := registry.GetTemplate(contentType)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get schema: %w", err)
|
||||
}
|
||||
|
||||
tpl, err := template.CompileTemplate(templateContent)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to compile template: %w", err)
|
||||
}
|
||||
|
||||
blocks := matcher.MatchBlocksFuzzy(markdownContent, tpl, 0.3)
|
||||
|
||||
result, err := decoders.Parse(blocks)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user