Skip to content

Commit

Permalink
feat: migrate WordPress's table of contents to PaperMod's ToC
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishb committed Mar 18, 2024
1 parent 825790e commit 6d99d5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions src/wp2hugo/internal/hugogenerator/hugopage/hugo_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const _WordPressMoreTag = "<!--more-->"

// In the next step, we will replace this as well
const _customMoreTag = "{{< more >}}"
const _wordPressTocTag = "[toc]"

var _markdownImageLinks = regexp.MustCompile(`!\[.*?]\((.+?)\)`)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6d99d5e

Please sign in to comment.