Skip to content

Commit a65286b

Browse files
authored
Merge branch 'main' into youtube-urls
2 parents 2138d74 + f7af15b commit a65286b

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ $ make build_prod
9191
1. [x] WordPress page author
9292
1. [x] Ability to filter by author(s), useful for [WordPress multi-site](https://www.smashingmagazine.com/2020/01/complete-guide-wordpress-multisite/) migrations
9393
1. [x] Featured images - export featured image associations with pages and posts correctly
94+
1. [x] WordPoress [Post formats](https://developer.wordpress.org/advanced-administration/wordpress/post-formats/)
9495
9596
### Why existing tools don't work
9697

src/wp2hugo/internal/hugogenerator/hugo_gen_setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func (g Generator) newHugoPage(pageURL *url.URL, page wpparser.CommonFields) (*h
365365
g.imageURLProvider,
366366
*pageURL, page.Author, page.Title, page.PublishDate,
367367
page.PublishStatus == wpparser.PublishStatusDraft || page.PublishStatus == wpparser.PublishStatusPending,
368-
page.Categories, page.Tags, page.Footnotes, page.Content, page.GUID, page.FeaturedImageID)
368+
page.Categories, page.Tags, page.Footnotes, page.Content, page.GUID, page.FeaturedImageID, page.PostFormat)
369369
}
370370

371371
func (g Generator) downloadPageMedia(outputMediaDirPath string, p *hugopage.Page, pageURL *url.URL) error {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ var _hugoParallaxBlurLinks = regexp.MustCompile(`{{< parallaxblur.*?src="(.+?)".
6464

6565
func NewPage(provider ImageURLProvider, pageURL url.URL, author string, title string, publishDate *time.Time,
6666
isDraft bool, categories []string, tags []string, footnotes []wpparser.Footnote,
67-
htmlContent string, guid *rss.GUID, featuredImageID *string) (*Page, error) {
68-
metadata, err := getMetadata(provider, pageURL, author, title, publishDate, isDraft, categories, tags, guid, featuredImageID)
67+
htmlContent string, guid *rss.GUID, featuredImageID *string, postFormat *string) (*Page, error) {
68+
metadata, err := getMetadata(provider, pageURL, author, title, publishDate, isDraft, categories, tags, guid,
69+
featuredImageID, postFormat)
6970
if err != nil {
7071
return nil, err
7172
}
@@ -119,7 +120,8 @@ func getMarkdownLinks(regex *regexp.Regexp, markdown string) []string {
119120
}
120121

121122
func getMetadata(provider ImageURLProvider, pageURL url.URL, author string, title string, publishDate *time.Time,
122-
isDraft bool, categories []string, tags []string, guid *rss.GUID, featuredImageID *string) (map[string]any, error) {
123+
isDraft bool, categories []string, tags []string, guid *rss.GUID, featuredImageID *string,
124+
postFormat *string) (map[string]any, error) {
123125
metadata := make(map[string]any)
124126
metadata["url"] = pageURL.Path // Relative URL
125127
metadata["author"] = author
@@ -163,6 +165,9 @@ func getMetadata(provider ImageURLProvider, pageURL url.URL, author string, titl
163165
metadata["cover"] = coverInfo
164166
}
165167
}
168+
if postFormat != nil {
169+
metadata["type"] = *postFormat
170+
}
166171
return metadata, nil
167172
}
168173

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestManualLineBreaks(t *testing.T) {
6262
func testMarkdownExtractor(t *testing.T, htmlInput string, markdownOutput string) {
6363
url1, err := url.Parse("https://example.com")
6464
assert.Nil(t, err)
65-
page, err := NewPage(nil, *url1, "author", "Title", nil, false, nil, nil, nil, htmlInput, nil, nil)
65+
page, err := NewPage(nil, *url1, "author", "Title", nil, false, nil, nil, nil, htmlInput, nil, nil, nil)
6666
assert.Nil(t, err)
6767
md, err := page.getMarkdown(nil, htmlInput, nil)
6868
assert.Nil(t, err)

src/wp2hugo/internal/wpparser/wp_parser_setup.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7-
"github.com/mmcdole/gofeed/extensions"
8-
"github.com/mmcdole/gofeed/rss"
9-
"github.com/rs/zerolog/log"
10-
"golang.org/x/text/runes"
11-
"golang.org/x/text/transform"
12-
"golang.org/x/text/unicode/norm"
137
"io"
148
"regexp"
159
"strings"
1610
"time"
1711
"unicode"
12+
13+
ext "github.com/mmcdole/gofeed/extensions"
14+
"github.com/mmcdole/gofeed/rss"
15+
"github.com/rs/zerolog/log"
16+
"golang.org/x/text/runes"
17+
"golang.org/x/text/transform"
18+
"golang.org/x/text/unicode/norm"
1819
)
1920

2021
var (
@@ -92,6 +93,7 @@ type CommonFields struct {
9293
LastModifiedDate *time.Time
9394
PublishStatus PublishStatus // "publish", "draft", "pending" etc. may be make this a custom type
9495
GUID *rss.GUID
96+
PostFormat *string
9597

9698
Description string // how to use this?
9799
Content string
@@ -307,12 +309,16 @@ func getCommonFields(item *rss.Item) (*CommonFields, error) {
307309
}
308310
pageCategories := make([]string, 0, len(item.Categories))
309311
pageTags := make([]string, 0, len(item.Categories))
312+
var postFormat *string
310313

311314
for _, category := range item.Categories {
312315
if isCategory(category) {
313316
pageCategories = append(pageTags, NormalizeCategoryName(category.Value))
314317
} else if isTag(category) {
315318
pageTags = append(pageTags, NormalizeCategoryName(category.Value))
319+
} else if isPostFormat(category) {
320+
tmp := NormalizeCategoryName(category.Value)
321+
postFormat = &tmp
316322
} else {
317323
log.Warn().
318324
Str("link", item.Link).
@@ -358,6 +364,7 @@ func getCommonFields(item *rss.Item) (*CommonFields, error) {
358364
GUID: item.GUID,
359365
LastModifiedDate: lastModifiedDate,
360366
PublishStatus: PublishStatus(publishStatus),
367+
PostFormat: postFormat,
361368
Excerpt: item.Extensions["excerpt"]["encoded"][0].Value,
362369

363370
Description: item.Description,
@@ -471,6 +478,10 @@ func isCategory(category *rss.Category) bool {
471478
return category.Domain == "category"
472479
}
473480

481+
func isPostFormat(category *rss.Category) bool {
482+
return category.Domain == "post_format"
483+
}
484+
474485
func isTag(tag *rss.Category) bool {
475486
return tag.Domain == "post_tag"
476487
}

0 commit comments

Comments
 (0)