Skip to content

Commit 703b677

Browse files
committed
fix: add Page#WPImageLinks
1 parent 392e17e commit 703b677

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/wp2hugo/internal/hugogenerator/hugopage/hugo_page.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Page struct {
3636
HTMLContent string
3737
}
3838

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

4141
func (page Page) getRelativeURL() string {
4242
return page.AbsoluteURL.Path
@@ -52,12 +52,17 @@ func (page Page) Write(w io.Writer) error {
5252
return nil
5353
}
5454

55-
func (page Page) GetWPContentLinks() ([]string, error) {
55+
func (page Page) WPImageLinks() ([]string, error) {
5656
markdown, err := page.getMarkdown()
5757
if err != nil {
5858
return nil, err
5959
}
60-
return _wpContentRegEx.FindAllString(*markdown, -1), nil
60+
var links []string
61+
matches := _imageLinks.FindAllStringSubmatch(*markdown, -1)
62+
for _, match := range matches {
63+
links = append(links, match[1])
64+
}
65+
return links, nil
6166
}
6267

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

0 commit comments

Comments
 (0)