diff --git a/README.md b/README.md index 7a63f9b..21e776d 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Written in Go. 1. [x] Migrate `caption` (WordPress) to `figure` (Hugo) 1. [x] Migrate "Show more..." of WordPress -> `Summary` in Hugo 1. [x] Support for parallax blur (similar to [WordPress Advanced Backgrounds](https://wordpress.org/plugins/advanced-backgrounds/)) +1. [x] Migrate WordPress table of content -> Hugo 1. [ ] Migrate code blocks correctly - syntax highlighting is not working right now 1. [ ] Featured images - I tried this [WordPress plugin](https://wordpress.org/plugins/export-media-with-selected-content/) but featured images are simply not exported diff --git a/src/wp2hugo/internal/hugogenerator/hugopage/hugo_page.go b/src/wp2hugo/internal/hugogenerator/hugopage/hugo_page.go index 8f8cb11..4c4a159 100644 --- a/src/wp2hugo/internal/hugogenerator/hugopage/hugo_page.go +++ b/src/wp2hugo/internal/hugogenerator/hugopage/hugo_page.go @@ -34,6 +34,7 @@ const _WordPressMoreTag = "" // In the next step, we will replace this as well const _customMoreTag = "{{< more >}}" +const _wordPressTocTag = "[toc]" var _markdownImageLinks = regexp.MustCompile(`!\[.*?]\((.+?)\)`) @@ -130,6 +131,13 @@ func (page *Page) getMarkdown(provider ImageURLProvider, htmlContent string) (*s htmlContent = replaceAWBWithParallaxBlur(provider, htmlContent) htmlContent = strings.Replace(htmlContent, _WordPressMoreTag, _customMoreTag, 1) + // This handling is specific to paperMod theme + // Ref: https://adityatelange.github.io/hugo-PaperMod/posts/papermod/papermod-features/#show-table-of-contents-toc-on-blog-post + if strings.Contains(htmlContent, _wordPressTocTag) { + htmlContent = strings.Replace(htmlContent, _wordPressTocTag, "", 1) + page.metadata["ShowToc"] = true + page.metadata["TocOpen"] = true + } markdown, err := converter.ConvertString(htmlContent) if err != nil { return nil, fmt.Errorf("error converting HTML to Markdown: %s", err)