Skip to content

Commit 1335c26

Browse files
committed
Rephrase wordpressdotcom importer alternative caveat.
The wordpressdotcom importer does import pages, posts, images, etc so previous statement was untrue.
1 parent c68ab98 commit 1335c26

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

docs/_importers/wordpressdotcom.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ Their default values are what you see above.
1717

1818
### Further WordPress migration alternatives
1919

20-
While the above method works, it does not import much of the metadata that is
21-
usually stored in WordPress posts and pages. If you need to export things like
22-
pages, tags, custom fields, image attachments and so on, the following resources
23-
might be useful to you:
20+
While the above method works, it doesn't import absolutely every piece of
21+
metadata. If you need to import custom fields from your pages and posts,
22+
the following resources might be useful to you:
2423

2524
- [Exitwp](https://github.com/thomasf/exitwp) is a configurable tool written in
2625
Python for migrating one or more WordPress blogs into Jekyll (Markdown) format

lib/jekyll-import/importers/wordpressdotcom.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def self.download_images(title, post_doc, assets_folder)
2626
images = post_doc.css("img")
2727
return if images.empty?
2828

29-
Jekyll.logger.info "Downloading images for ", title
29+
Jekyll.logger.info "Downloading:", "images for #{title}"
3030
images.each do |i|
3131
uri = URI::DEFAULT_PARSER.escape(i["src"])
3232

@@ -54,8 +54,8 @@ def self.download_images(title, post_doc, assets_folder)
5454

5555
class Item
5656
def initialize(node)
57-
@node = node
5857
raise "Node is nil" if node.nil?
58+
@node = node
5959
end
6060

6161
def text_for(path)
@@ -220,7 +220,7 @@ def self.process(options)
220220
end
221221

222222
import_count.each do |key, value|
223-
Jekyll.logger.info "Imported #{value} #{key}s"
223+
Jekyll.logger.info "Imported", "#{value} #{key}s"
224224
end
225225
end
226226

test/test_wordpressdotcom_importer.rb

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "helper"
2+
require "tmpdir"
23

34
Importers::WordpressDotCom.require_deps
45

@@ -13,9 +14,11 @@ class TestWordpressDotComMigrator < Test::Unit::TestCase
1314
assert File.exist?(xml_path), "Expect xml file to exist"
1415
tmpdir = Dir.mktmpdir
1516
Dir.chdir(tmpdir) do
17+
Jekyll.logger = ::Logger.new(File.open("output.log", "w"))
1618
JekyllImport::Importers::WordpressDotCom.process({"source" => xml_path})
19+
Jekyll.logger = Jekyll::Stevenson.new
1720
end
18-
21+
1922
# The old export produced the following files:
2023
# .
2124
# ├── _attachments
@@ -45,16 +48,21 @@ class TestWordpressDotComMigrator < Test::Unit::TestCase
4548
# └── a-bright-night-sky-full-of-stars-and-the-milky.png
4649
assert_path_exist File.expand_path("assets/2025/01/a-bright-night-sky-full-of-stars-and-the-milky.png", tmpdir)
4750

51+
jekyllbot_author_data = {
52+
"login" => "jekyllbot",
53+
"email" => "[email protected]",
54+
"display_name" => "jekyllbot",
55+
"first_name" => "Jekyllbot",
56+
"last_name" => "Hyde",
57+
}
58+
4859
assert_path_exist File.expand_path("_pages/2025-01-19-about.html", tmpdir)
4960
page_content = File.read(File.expand_path("_pages/2025-01-19-about.html", tmpdir))
50-
assert_match %r{published: true}, page_content
51-
assert_match %r{permalink: "\/about\/"}, page_content
52-
assert_match %r{^author:\s*\n}, page_content
53-
assert_match %r{\s\slogin: jekyllbot}, page_content
54-
assert_match %r{\s\semail: [email protected]}, page_content
55-
assert_match %r{\s\sdisplay_name: jekyllbot}, page_content
56-
assert_match %r{\s\sfirst_name: Jekyllbot}, page_content
57-
assert_match %r{\s\slast_name: Hyde}, page_content
61+
page_front_matter = page_content.match(/^(---\n.*?---\n)/m)[0]
62+
page_data = YAML.safe_load(page_front_matter)
63+
assert_equal true, page_data["published"]
64+
assert_equal "/about/", page_data["permalink"]
65+
assert_equal jekyllbot_author_data, page_data["author"]
5866

5967
assert_path_exist File.expand_path("_posts/2025-01-18-blog-post-1.html", tmpdir)
6068
post_content = File.read(File.expand_path("_posts/2025-01-18-blog-post-1.html", tmpdir))
@@ -64,7 +72,7 @@ class TestWordpressDotComMigrator < Test::Unit::TestCase
6472
assert_equal "Blog Post 1", post_data["title"]
6573
assert_equal ["Foo"], post_data["categories"]
6674
assert_equal ["code", "ruby", "ship", "stars"], post_data["tags"]
67-
assert_equal "jekyllbot", post_data["author"]["login"]
75+
assert_equal jekyllbot_author_data, post_data["author"]
6876
assert_equal "/2025/01/18/blog-post-1/", post_data["permalink"]
6977
assert_equal "101042542514", post_data["meta"]["_publicize_job_id"]
7078
assert_includes post_content, "<p>This is a blog post.</p>"

0 commit comments

Comments
 (0)