1 Use case: You want to move away from Wordpress to Ikiwiki as your blogging/website platform, but you want to retain your old posts.
3 [This](http://git.chris-lamb.co.uk/?p=ikiwiki-wordpress-import.git) is a simple tool that generates [git-fast-import](http://www.kernel.org/pub/software/scm/git/docs/git-fast-import.html)-compatible data from a WordPress export XML file.
5 WordPress categories are mapped onto Ikiwiki tags. The ability to import comments is planned.
7 The script uses the [BeautifulSoup][] module.
9 [BeautifulSoup]: http://www.crummy.com/software/BeautifulSoup/
13 I include a modified version of this script. This version includes the ability to write \[[!tag foo]] directives, which the original intended, but didn't actually do.
15 -- [[users/simonraven]]
17 [[ikiwiki-wordpress-import]]
21 Perhaps slightly insane, but here's an XSLT style sheet that handles my pages. It's basic, but sufficient to get started.
22 Note that I had to break up the ikiwiki meta strings to post this.
26 <?xml version="1.0" encoding="UTF-8"?>
27 <xsl:stylesheet version="2.0"
28 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
29 xmlns:content="http://purl.org/rss/1.0/modules/content/"
30 xmlns:wp="http://wordpress.org/export/1.0/">
32 <xsl:output method="text"/>
33 <xsl:output method="text" name="txt"/>
35 <xsl:variable name='newline'><xsl:text>
36 </xsl:text></xsl:variable>
38 <xsl:template match="channel">
39 <xsl:apply-templates select="item[wp:post_type = 'post']"/>
42 <xsl:template match="item">
43 <xsl:variable name="idnum" select="format-number(wp:post_id,'0000')" />
44 <xsl:variable name="basename"
45 select="concat('wp-posts/post-',$idnum)" />
46 <xsl:variable name="filename"
47 select="concat($basename, '.html')" />
48 <xsl:text>Creating </xsl:text>
49 <xsl:value-of select="concat($filename, $newline)" />
50 <xsl:result-document href="{$filename}" format="txt">
51 <xsl:text>[[</xsl:text><xsl:text>meta title="</xsl:text>
52 <xsl:value-of select="replace(title, '"', '&ldquo;')"/>
53 <xsl:text>"]]</xsl:text><xsl:value-of select="$newline"/>
54 <xsl:text>[[</xsl:text><xsl:text>meta date="</xsl:text>
55 <xsl:value-of select="pubDate"/>
56 <xsl:text>"]]</xsl:text><xsl:value-of select="$newline"/>
57 <xsl:text>[[</xsl:text><xsl:text>meta updated="</xsl:text>
58 <xsl:value-of select="pubDate"/>
59 <xsl:text>"]]</xsl:text> <xsl:value-of select="$newline"/>
60 <xsl:value-of select="$newline"/>
61 <xsl:value-of select="content:encoded"/>
65 <xsl:apply-templates select="category[@domain='tag' and not(@nicename)]">
66 <xsl:sort select="name()"/>
67 </xsl:apply-templates>
68 </xsl:result-document>
69 <xsl:apply-templates select="wp:comment">
70 <xsl:sort select="date"/>
71 <xsl:with-param name="basename">$basename</xsl:with-param>
72 </xsl:apply-templates>
75 <xsl:template match="wp:comment">
76 <xsl:param name="basename"/>
77 <xsl:variable name="cnum" select="format-number(wp:comment_id, '000')" />
78 <xsl:variable name="filename" select="concat($basename, '/comment_', $cnum, '._comment')"/>
79 <xsl:variable name="nickname" select="concat(' nickname="', wp:comment_author, '"')" />
80 <xsl:variable name="username" select="concat(' username="', wp:comment_author_url, '"')" />
81 <xsl:variable name="ip" select="concat(' ip="', wp:comment_author_IP, '"')" />
82 <xsl:variable name="date" select="concat(' date="', wp:comment_date_gmt, '"')" />
83 <xsl:result-document href="{$filename}" format="txt">
84 <xsl:text>[[</xsl:text><xsl:text>comment format=html</xsl:text><xsl:value-of select="$newline"/>
85 <xsl:value-of select="$nickname"/>
86 <xsl:value-of select="$username"/>
87 <xsl:value-of select="$ip"/>
88 <xsl:value-of select="$date"/>
89 <xsl:text>subject=""</xsl:text><xsl:value-of select="$newline"/>
90 <xsl:text>content="""</xsl:text><xsl:value-of select="$newline"/>
91 <xsl:value-of select="wp:comment_content"/>
92 <xsl:value-of select="$newline"/>
93 <xsl:text>"""]]</xsl:text><xsl:value-of select="$newline"/>
94 </xsl:result-document>
97 <xsl:template match="category">
98 <xsl:text>[</xsl:text><xsl:text>[</xsl:text><xsl:text>!tag "</xsl:text><xsl:value-of select="."/><xsl:text>"]]</xsl:text>
99 <xsl:value-of select="$newline"/>