more refactoring

main
Nick Dumas 2 years ago
parent 78eabd4391
commit ab32890495

@ -12,29 +12,6 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
func NewPipeline(dev bool) *Pipeline {
var p Pipeline
var l *zap.Logger
l, _ = zap.NewProduction()
if dev {
l, _ = zap.NewDevelopment()
}
p.L = l
p.Attachments = make(map[string]string)
p.Posts = make([]string, 0)
return &p
}
type Pipeline struct {
Source, Target string
Attachments map[string]string
Notes, Posts []string
L *zap.Logger
BlogDir, AttachmentsDir string
}
func (p *Pipeline) Walk() error { func (p *Pipeline) Walk() error {
notesRoot := os.DirFS(p.Source) notesRoot := os.DirFS(p.Source)
blogRoot := os.DirFS(p.Target) blogRoot := os.DirFS(p.Target)
@ -73,10 +50,6 @@ func (p *Pipeline) findNotes(path string, d fs.DirEntry, err error) error {
return nil return nil
} }
func (p *Pipeline) FindAttachments() error {
return nil
}
func (p *Pipeline) findAttachments(path string, d fs.DirEntry, err error) error { func (p *Pipeline) findAttachments(path string, d fs.DirEntry, err error) error {
if err != nil { if err != nil {
return err return err
@ -124,7 +97,7 @@ func (p *Pipeline) Move() error {
moveLogger.Info("scanning posts", zap.Strings("posts", p.Posts)) moveLogger.Info("scanning posts", zap.Strings("posts", p.Posts))
for _, post := range p.Notes { for _, post := range p.Notes {
// log.Printf("scanning %q for attachment links", post) // log.Printf("scanning %q for attachment links", post)
linkedAttachments, err := extractAttachments(filepath.Join(p.Source, post), p.L.Named("extractAttachments")) linkedAttachments, err := extractAttachments(filepath.Join(p.Source, post))
if err != nil { if err != nil {
return fmt.Errorf("could not extract attachment links from %q: %w", post, err) return fmt.Errorf("could not extract attachment links from %q: %w", post, err)
} }
@ -149,11 +122,7 @@ func moveAttachment(post, attachment string, l *zap.Logger) error {
return nil return nil
} }
func extractAttachments(post string, l *zap.Logger) ([]string, error) { func extractAttachments(post string) ([]string, error) {
l.Info("scanning note",
zap.String("post", post),
)
pat := regexp.MustCompile(`\[\[Resources\/attachments\/(.*)?\]\]`) pat := regexp.MustCompile(`\[\[Resources\/attachments\/(.*)?\]\]`)
@ -165,7 +134,6 @@ func extractAttachments(post string, l *zap.Logger) ([]string, error) {
for _, att := range pat.FindAllSubmatch(postBody, -1) { for _, att := range pat.FindAllSubmatch(postBody, -1) {
filename := string(att[1]) filename := string(att[1])
l.Info("found attachment", zap.String("filename", filename))
attachments = append(attachments, filename) attachments = append(attachments, filename)
} }

@ -0,0 +1,56 @@
package obspipeline
import (
"go.uber.org/zap"
)
func NewPipeline(dev bool) *Pipeline {
var p Pipeline
var l *zap.Logger
l, _ = zap.NewProduction()
if dev {
l, _ = zap.NewDevelopment()
}
p.L = l
p.Attachments = make(map[string]string)
p.Posts = make([]string, 0)
return &p
}
type Pipeline struct {
Source, Target string
Attachments map[string]string
Notes, Posts []string
L *zap.Logger
BlogDir, AttachmentsDir string
}
func (p *Pipeline) FindAttachments() error {
return nil
}
func (p *Pipeline) FindNotes() error {
return nil
}
func (p *Pipeline) FindPosts() error {
return nil
}
func (p *Pipeline) CopyPost(post string) error {
return nil
}
func (p *Pipeline) MoveAttachments(post string) error {
return nil
}
func (p *Pipeline) SanitizePost(post string) error {
return nil
}
Loading…
Cancel
Save