From ab32890495cf390896dcb5d9840e013141432c8c Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Fri, 28 Apr 2023 20:55:36 -0400 Subject: [PATCH] more refactoring --- attachments.go => blerp.go | 36 ++---------------------- pipeline.go | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 34 deletions(-) rename attachments.go => blerp.go (82%) create mode 100644 pipeline.go diff --git a/attachments.go b/blerp.go similarity index 82% rename from attachments.go rename to blerp.go index d117876..aef9407 100644 --- a/attachments.go +++ b/blerp.go @@ -12,29 +12,6 @@ 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) Walk() error { notesRoot := os.DirFS(p.Source) blogRoot := os.DirFS(p.Target) @@ -73,10 +50,6 @@ func (p *Pipeline) findNotes(path string, d fs.DirEntry, err error) error { return nil } -func (p *Pipeline) FindAttachments() error { - return nil -} - func (p *Pipeline) findAttachments(path string, d fs.DirEntry, err error) error { if err != nil { return err @@ -124,7 +97,7 @@ func (p *Pipeline) Move() error { moveLogger.Info("scanning posts", zap.Strings("posts", p.Posts)) for _, post := range p.Notes { // 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 { 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 } -func extractAttachments(post string, l *zap.Logger) ([]string, error) { - - l.Info("scanning note", - zap.String("post", post), - ) +func extractAttachments(post string) ([]string, error) { 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) { filename := string(att[1]) - l.Info("found attachment", zap.String("filename", filename)) attachments = append(attachments, filename) } diff --git a/pipeline.go b/pipeline.go new file mode 100644 index 0000000..a031d51 --- /dev/null +++ b/pipeline.go @@ -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 +}