ffs, i should have committed wayyy earlier

This commit is contained in:
Max Richter
2025-08-16 20:38:40 +02:00
commit 43644c4f40
25 changed files with 865 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
description: "Core capture aliases for Marka"
patterns:
text: ".+"
word: "\\S+"
num: "(?:\\d+(?:[.,]\\d+)?(?:\\s?\\d+/\\d+)?)" # 3 | 1.5 | 1 1/2
indexMarker: "\\d+[.)]" # 1. / 1)

3
registry/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module git.max-richter.dev/max/marka/registry
go 1.24.3

59
registry/registry.go Normal file
View File

@@ -0,0 +1,59 @@
// Package registry provides functionality for managing and accessing embedded file systems and directories.
package registry
import (
"embed"
"io"
"io/fs"
"os"
)
type Source interface {
Open(name string) (fs.File, error)
ReadFile(name string) ([]byte, error)
ReadDir(name string) ([]fs.DirEntry, error)
}
type src struct{ fsys fs.FS }
func (s src) Open(p string) (fs.File, error) { return s.fsys.Open(p) }
func (s src) ReadFile(p string) ([]byte, error) { return fs.ReadFile(s.fsys, p) }
func (s src) ReadDir(p string) ([]fs.DirEntry, error) { return fs.ReadDir(s.fsys, p) }
func FromDir(path string) Source { return src{fsys: os.DirFS(path)} }
//go:embed templates/*
var templates embed.FS
//go:embed schema-org/*
var schemas embed.FS
//go:embed aliases/*
var aliases embed.FS
func GetTemplates() Source {
return src{fsys: templates}
}
func GetTemplate(name string) (string, error) {
templateFile, err := templates.Open("templates/" + name + ".marka")
if err != nil {
return "", err
}
defer templateFile.Close()
templateBytes, err := io.ReadAll(templateFile)
if err != nil {
return "", err
}
return string(templateBytes), nil
}
func GetSchemas() Source {
return src{fsys: schemas}
}
func GetAliases() Source {
return src{fsys: aliases}
}

View File

@@ -0,0 +1,38 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://schema.org/ImageObject",
"title": "ImageObject",
"description": "Minimal subset of schema.org/ImageObject for use in Recipe image property",
"type": "object",
"required": [
"@type",
"url"
],
"properties": {
"@type": {
"const": "ImageObject"
},
"url": {
"$ref": "url.json"
},
"caption": {
"type": "string",
"description": "A caption for the image."
},
"width": {
"type": [
"integer",
"string"
],
"description": "Width of the image in pixels or as a string with unit."
},
"height": {
"type": [
"integer",
"string"
],
"description": "Height of the image in pixels or as a string with unit."
}
},
"additionalProperties": true
}

View File

@@ -0,0 +1,103 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://schema.org/Recipe",
"title": "Recipe",
"type": "object",
"required": [
"@context",
"@type",
"name",
"image",
"recipeIngredient",
"recipeInstructions"
],
"properties": {
"@context": {
"const": "https://schema.org/"
},
"@type": {
"const": "Recipe"
},
"name": {
"type": "string"
},
"image": {
"oneOf": [
{
"$ref": "Url.json"
},
{
"type": "array",
"items": {
"$ref": "Url.json"
},
"minItems": 1
},
{
"$ref": "ImageObject.json"
},
{
"type": "array",
"items": {
"$ref": "ImageObject.json"
},
"minItems": 1
}
]
},
"description": {
"type": "string"
},
"author": {
"type": "object",
"required": [
"@type",
"name"
],
"properties": {
"@type": {
"const": "Person"
},
"name": {
"type": "string"
}
},
"additionalProperties": false
},
"datePublished": {
"type": "string",
"format": "date"
},
"prepTime": {
"type": "string",
"pattern": "^P(T?\\d+H?\\d*M?\\d*S?)$"
},
"cookTime": {
"type": "string",
"pattern": "^P(T?\\d+H?\\d*M?\\d*S?)$"
},
"recipeYield": {
"type": "string"
},
"recipeIngredient": {
"type": "array",
"items": {
"type": "string"
}
},
"recipeInstructions": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
},
"additionalProperties": true
}

View File

@@ -0,0 +1,12 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://schema.org/Url",
"title": "URL",
"description": "A URL as defined by schema.org/URL",
"type": "string",
"format": "uri",
"examples": [
"https://example.com",
"http://www.example.org/image.png"
]
}

View File

@@ -0,0 +1,60 @@
---
{
path: .
codec: yaml
required: true
assert:
"@context": https://schema.org/
"@type": Recipe
fields:
- path: name
codec: text
required: true
- path: image
codec: text
required: true
- path: author.@type
codec: const
value: Person
- path: author.name
codec: text
required: true
- path: datePublished
codec: text
optional: true
- path: description
codec: text
optional: true
- path: prepTime
codec: text
optional: true
- path: cookTime
codec: text
optional: true
- path: recipeYield
codec: text
optional: true
}
---
# { name | text,required }
{ description | text,optional }
## Ingredients
{
path: recipeIngredient
codec: list
required: true
item:
template: "- { . }"
}
## Steps
{
path: recipeInstructions
codec: list
required: true
item:
template: "{ @index }. { . }"
}