// Copyright 2024 Matthew Rich . All rights reserved. package builtin import ( _ "context" _ "encoding/json" "fmt" _ "gopkg.in/yaml.v3" _ "net/url" _ "regexp" _ "strings" _ "os" _ "io" _ "compress/gzip" _ "archive/tar" _ "errors" _ "path/filepath" _ "decl/internal/codec" "decl/internal/data" "decl/internal/fs" "decl/internal/folio" _ "decl/internal/resource" _ "decl/internal/config" _ "decl/internal/fan" "embed" "log/slog" ) //go:embed documents/*.jx.yaml var documentFiles embed.FS func Load(uri folio.URI) (documents []data.Document, err error) { var extractor data.Converter var sourceResource data.Resource if extractor, err = folio.DocumentRegistry.ConverterTypes.New(string(uri)); err == nil { slog.Info("builtin.Load() extractor", "uri", uri, "error", err) targetDeclaration := folio.NewDeclaration() if err = targetDeclaration.NewResource((*string)(&uri)); err == nil { slog.Info("builtin.Load() extract many", "resource", sourceResource, "error", err, "uri", uri, "extractor", extractor) sourceResource = targetDeclaration.Attributes sourceResource.(data.FileResource).SetFS(documentFiles) documents, err = extractor.(data.ManyExtractor).ExtractMany(sourceResource, nil) slog.Info("builtin.Load() extract many", "resource", sourceResource, "error", err) } } return } func BuiltInDocuments() (documents []data.Document, err error) { docFs := fs.NewWalkDir(documentFiles, "", func(fsys fs.FS, path string, file fs.DirEntry) (walkErr error) { u := folio.URI(fmt.Sprintf("file://%s", path)) slog.Info("BuiltInDocuments()", "file", u) if ! file.IsDir() { if loadDocs, loadErr := Load(u); loadErr == nil { documents = append(documents, loadDocs...) } else { err = loadErr } } return }) docFs.Walk(nil) return documents, err }