Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
taylormonacelli committed Jul 25, 2024
1 parent 209490c commit fe49d5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
17 changes: 17 additions & 0 deletions core/cleanup_links.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"bytes"
"fmt"
"io"
"regexp"
Expand Down Expand Up @@ -46,3 +47,19 @@ func RemoveTitlesFromMarkdownLinks(r io.Reader, w io.Writer) error {

return nil
}

func ApplyTransforms(content []byte, transforms ...func(io.Reader, io.Writer) error) ([]byte, error) {
var processedContent bytes.Buffer
currentContent := bytes.NewReader(content)

for _, transform := range transforms {
processedContent.Reset()
err := transform(currentContent, &processedContent)
if err != nil {
return nil, err
}
currentContent = bytes.NewReader(processedContent.Bytes())
}

return processedContent.Bytes(), nil
}
16 changes: 0 additions & 16 deletions core/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@ func ProcessFile(ctx context.Context, path string, transforms ...func(io.Reader,
return nil
}

func ApplyTransforms(content []byte, transforms ...func(io.Reader, io.Writer) error) ([]byte, error) {
var processedContent bytes.Buffer
currentContent := bytes.NewReader(content)

for _, transform := range transforms {
processedContent.Reset()
err := transform(currentContent, &processedContent)
if err != nil {
return nil, err
}
currentContent = bytes.NewReader(processedContent.Bytes())
}

return processedContent.Bytes(), nil
}

func ReadPathsFromStdin() ([]string, error) {
var paths []string
scanner := bufio.NewScanner(os.Stdin)
Expand Down

0 comments on commit fe49d5b

Please sign in to comment.