Skip to content

Commit

Permalink
fix: add Page#WPImageLinks
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishb committed Mar 12, 2024
1 parent 392e17e commit 703b677
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/wp2hugo/internal/hugogenerator/hugopage/hugo_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Page struct {
HTMLContent string
}

var _wpContentRegEx = regexp.MustCompile(`/wp-content/uploads/[^"]+`)
var _imageLinks = regexp.MustCompile(`!\[.*?]\((.+?)\)`)

func (page Page) getRelativeURL() string {
return page.AbsoluteURL.Path
Expand All @@ -52,12 +52,17 @@ func (page Page) Write(w io.Writer) error {
return nil
}

func (page Page) GetWPContentLinks() ([]string, error) {
func (page Page) WPImageLinks() ([]string, error) {
markdown, err := page.getMarkdown()
if err != nil {
return nil, err
}
return _wpContentRegEx.FindAllString(*markdown, -1), nil
var links []string
matches := _imageLinks.FindAllStringSubmatch(*markdown, -1)
for _, match := range matches {
links = append(links, match[1])
}
return links, nil
}

func (page Page) writeMetadata(w io.Writer) error {
Expand Down

0 comments on commit 703b677

Please sign in to comment.