If you have any draft posts in WordPress, you might run into an error when running gatsby develop after you place the Markdown files in src/posts.Īny draft posts you export will have a nonsensical date that the gatsby-transformer-remark plugin can’t parse. Once you rename the files, your posts will maintain their existing URLs. If you use a different operating system, you’ll have to find a different rename tool that supports regex. To batch rename files using a regular expression, I used a neat tool called transnomino, which runs on macOS. (I uploaded this regex to RegExr, where you can play around with it.) In gatsby-node.js, you can modify createPages() to set the path of your posts based on the URL in the Markdown files' front matter, rather than on the filename, like so: createPage(\. Option 1: use the “url” field as the slug This will break existing incoming links and confuse search engines.įortunately, there are two ways to get around this problem. That means your post might now live at -vegan-chocolate-cake instead. If you use the Gatsby blog starter or you followed the Gatsby tutorial on adding Markdown pages, you'll have Gatsby set up to use the Markdown files' filenames as slugs. For example, if a post lived at, you'd like it to stay there.īy default, the WordPress-to-Hugo exporter creates Markdown files with the filename format YYYY-MM-DD-slug, because that's the format that Hugo expects. When you’re moving from WordPress to Gatsby, you probably want to maintain your site’s URL structure. If you have Gatsby set up to transform Markdown files to pages, you can now drop these files into the appropriate source folder (for me, that’s src/posts) and just like that, your posts will appear in your Gatsby-powered site! Fixing the slugsĬhances are that you’ll need to do a little more work, though. The “front matter” is the content between the triple dashes at the top of the file. In the "posts" subfolder, there is a list of posts. The exporter’s instructions explain how to do this.Īfter you run the exporter, you’ll find a new folder under wp-content/uploads, which contains your WordPress posts and pages. You can run it from the WordPress admin area or from the command line. We’ll start by running the WordPress-to-Hugo exporter. If you have a lot of content, or if you’d like to automate the process as much as possible, read on!) Running the exporter (Note: If your WordPress site does not have many posts and pages, you can probably transfer your content more quickly by using wp2md and manually adding the front matter to the Markdown files. In the remainder of this article, I’ll walk you through using the WordPress-to-Hugo exporter to create Markdown files from which we’ll generate pages in Gatsby. There is a WordPress-to-Hugo exporter it can convert your WordPress content to Markdown files that contain the front matter we need to create pages in Gatsby. If you have several hundred posts on your website, like I did, it would be tedious to manually add the front matter to each Markdown file.įortunately, a better tool exists. But wp2md does not create “front matter”, a block of YAML at the top of each Markdown file that the gatsby-transformer-remark plugin needs to read metadata about the content, such as a post’s title, slug, and category. There is a tool that can convert your WordPress content to Markdown files: wp2md. Could we somehow export our WordPress content to Markdown? ![]() We can do this using the gatsby-source-filesystem and gatsby-transformer-remark plugins. One convenient way to add pages to Gatsby is to write your content in Markdown and to let Gatsby transform your Markdown content into pages. But what if you’d like to export your content from WordPress to Gatsby once and get rid of WordPress entirely? That’s a good solution if you want to run WordPress as a headless CMS. The gatsby-source-wordpress plugin can pull in data from a live WordPress install when Gatsby builds your static site. If you’re switching from WordPress to Gatsby, you’d probably like to transfer your existing content.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |