add: pipeline categorization by metadata key
parent
46715cf033
commit
165fffe91b
@ -0,0 +1,12 @@
|
||||
<h1>Tag #{{ .Category }}</h1>
|
||||
|
||||
<p>Here are the posts with this tag</p>
|
||||
|
||||
<ul>
|
||||
{{ range .Items }}
|
||||
<li>
|
||||
<p>{{ .Metadata.Title }}</p>
|
||||
<pre><code>{{ .Metadata.MatchResult }}</code></pre>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
package operation
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"github.com/aziis98/cabret"
|
||||
"github.com/iancoleman/strcase"
|
||||
"github.com/yuin/goldmark"
|
||||
meta "github.com/yuin/goldmark-meta"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registerType("frontmatter", &Frontmatter{})
|
||||
}
|
||||
|
||||
type Frontmatter struct {
|
||||
Options map[string]any
|
||||
}
|
||||
|
||||
func (op *Frontmatter) Load(config map[string]any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (op *Frontmatter) ProcessItem(content cabret.Content) (*cabret.Content, error) {
|
||||
md := goldmark.New(
|
||||
goldmark.WithExtensions(
|
||||
meta.Meta,
|
||||
),
|
||||
)
|
||||
|
||||
log.Printf(`[operation.Frontmatter] reading frontmatter`)
|
||||
|
||||
context := parser.NewContext()
|
||||
if err := md.Convert(content.Data, io.Discard, parser.WithContext(context)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
frontmatter := meta.Get(context)
|
||||
for k, v := range frontmatter {
|
||||
content.Metadata[strcase.ToCamel(k)] = v
|
||||
}
|
||||
|
||||
return &content, nil
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package operation
|
||||
|
||||
// import (
|
||||
// "fmt"
|
||||
// "log"
|
||||
// "mime"
|
||||
// "path/filepath"
|
||||
// "strings"
|
||||
|
||||
// "github.com/aziis98/cabret"
|
||||
// "github.com/aziis98/cabret/operation/template"
|
||||
// )
|
||||
|
||||
// func init() {
|
||||
// registerType("template", &Template{})
|
||||
// }
|
||||
|
||||
// type Template struct {
|
||||
// // TemplatePatterns is a list of glob patterns of templates that will be loaded
|
||||
// TemplatePatterns []string
|
||||
// }
|
||||
|
||||
// func (op *Template) Load(config map[string]any) error {
|
||||
// if v, ok := config[ShortFormValueKey]; ok {
|
||||
// globPatternsStr, ok := v.(string)
|
||||
// if !ok {
|
||||
// return fmt.Errorf(`expected a comma separated list of glob patterns but got "%v" of type %T`, v, v)
|
||||
// }
|
||||
|
||||
// globPatterns := strings.Split(globPatternsStr, ",")
|
||||
// for _, pat := range globPatterns {
|
||||
// op.TemplatePatterns = append(op.TemplatePatterns, strings.TrimSpace(pat))
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// }
|
||||
// if v, ok := config["paths"]; ok {
|
||||
// globPatterns, ok := v.([]string)
|
||||
// if !ok {
|
||||
// return fmt.Errorf(`expected a list of glob patterns but got "%v" of type %T`, v, v)
|
||||
// }
|
||||
|
||||
// for _, pat := range globPatterns {
|
||||
// op.TemplatePatterns = append(op.TemplatePatterns, strings.TrimSpace(pat))
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// }
|
||||
// if v, ok := config["path"]; ok {
|
||||
// globPatternStr, ok := v.(string)
|
||||
// if !ok {
|
||||
// return fmt.Errorf(`expected a glob pattern but got "%v" of type %T`, v, v)
|
||||
// }
|
||||
|
||||
// op.TemplatePatterns = []string{strings.TrimSpace(globPatternStr)}
|
||||
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// return fmt.Errorf(`invalid config for "template": %#v`, config)
|
||||
// }
|
||||
|
||||
// func (op *Template) ProcessList(contents []cabret.Content) ([]cabret.Content, error) {
|
||||
// // expand glob patterns
|
||||
// tmplFiles := []string{}
|
||||
// for _, pat := range op.TemplatePatterns {
|
||||
// files, err := filepath.Glob(strings.TrimSpace(pat))
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// tmplFiles = append(tmplFiles, files...)
|
||||
// }
|
||||
|
||||
// // create template
|
||||
// tmpl, err := template.ParseFiles(tmplFiles...)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// log.Printf(`[operation.Layout] rendering into layout "%s"`, strings.Join(op.TemplatePatterns, ", "))
|
||||
|
||||
// ctx := map[string]any{}
|
||||
// ctx["Items"] = contents
|
||||
// data, err := tmpl.Render(ctx)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// return []cabret.Content{
|
||||
// {
|
||||
// Type: mime.TypeByExtension(filepath.Ext(tmplFiles[0])),
|
||||
// Data: data,
|
||||
// Metadata: ctx,
|
||||
// },
|
||||
// }, nil
|
||||
// }
|
Loading…
Reference in New Issue