lonekorean / wordpress-export-to-markdown

Converts a WordPress export XML file into Markdown files.
MIT License
1.08k stars 221 forks source link

Add the title of the page as "# header" into the MD #62

Closed hobpet closed 3 years ago

hobpet commented 3 years ago

I'm converting a site where the title is displayed as part of the WP template, so I'm loosing that info in the MD file. If would be really useful to add to the MD as header at the first line like this: # title of the WP post [Rest of the content]

hobpet commented 3 years ago

Quick and dirty solution:

function getPostContent(post, turndownService, config) {
...

    // add title as header to the top of the page
    content = "# " + post.title[0] + "\n\n" + content ;

    return content;
}
lonekorean commented 3 years ago

This looks like a layout concern, not a data concern. The title is already provided in the frontmatter, and ideally whatever template consumes the markdown file should render it where needed.

If this works for your case, then that's cool, looks like you got what you need with your quick and dirty solution. 🙂 But I can't assume that everyone wants the title smooshed into the content as an h1 like this.

hobpet commented 3 years ago

Indeed it was there on the frontmatter, the matter of fact my even quicker and dirtier fix was this: (title\: \"(.*)"\n.*\n.*) replaced by $1\n\n# $2 :) Yeah, it may be a special problem I have. I wondered if as a configurable option could help others. But I agree that it may not be needed for others. I'm using docfx, there the frontmatter does not used during rendering.