]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/tips/Importing_posts_from_Wordpress.mdwn
Templates render bugfix appear to be working.
[git.ikiwiki.info.git] / doc / tips / Importing_posts_from_Wordpress.mdwn
1 [[!meta date="2007-10-05 06:59:14 +0000"]]
3 Use case: You want to move away from Wordpress to Ikiwiki as your blogging/website platform, but you want to retain your old posts.
5 [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.
7 WordPress categories are mapped onto Ikiwiki tags. The ability to import comments is planned.
9 The script uses the [BeautifulSoup][] module.
11 [BeautifulSoup]: http://www.crummy.com/software/BeautifulSoup/
13 -----
15 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.
17 -- [[users/simonraven]]
19 [[ikiwiki-wordpress-import]]
21 -----
23 Perhaps slightly insane, but here's an XSLT style sheet that handles my pages.  It's basic, but sufficient to get started.
24 Note that I had to break up the ikiwiki meta strings to post this.
26 -- JasonRiedy
28         <?xml version="1.0" encoding="UTF-8"?>
29         <xsl:stylesheet version="2.0"
30           xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
31           xmlns:content="http://purl.org/rss/1.0/modules/content/"
32           xmlns:wp="http://wordpress.org/export/1.0/">
33           
34         <xsl:output method="text"/>
35         <xsl:output method="text" name="txt"/>
36         
37         <xsl:variable name='newline'><xsl:text>
38         </xsl:text></xsl:variable>
39         
40         <xsl:template match="channel">
41           <xsl:apply-templates select="item[wp:post_type = 'post']"/>
42         </xsl:template>
43         
44         <xsl:template match="item">
45           <xsl:variable name="idnum" select="format-number(wp:post_id,'0000')" />
46           <xsl:variable name="basename"
47                         select="concat('wp-posts/post-',$idnum)" />
48           <xsl:variable name="filename"
49                         select="concat($basename, '.html')" />
50           <xsl:text>Creating </xsl:text>
51           <xsl:value-of select="concat($filename, $newline)" />
52           <xsl:result-document href="{$filename}" format="txt">
53             <xsl:text>[[</xsl:text><xsl:text>meta title="</xsl:text>
54             <xsl:value-of select="replace(title, '&quot;', '&amp;ldquo;')"/>
55             <xsl:text>"]]</xsl:text><xsl:value-of select="$newline"/>
56             <xsl:text>[[</xsl:text><xsl:text>meta date="</xsl:text>
57             <xsl:value-of select="pubDate"/>
58             <xsl:text>"]]</xsl:text><xsl:value-of select="$newline"/>
59             <xsl:text>[[</xsl:text><xsl:text>meta updated="</xsl:text>
60             <xsl:value-of select="pubDate"/>
61             <xsl:text>"]]</xsl:text> <xsl:value-of select="$newline"/>
62             <xsl:value-of select="$newline"/>
63             <xsl:value-of select="content:encoded"/>
64             <xsl:text>
65         
66         </xsl:text>
67             <xsl:apply-templates select="category[@domain='tag' and not(@nicename)]">
68               <xsl:sort select="name()"/>
69             </xsl:apply-templates>
70           </xsl:result-document>
71           <xsl:apply-templates select="wp:comment">
72             <xsl:sort select="date"/>
73             <xsl:with-param name="basename">$basename</xsl:with-param>
74           </xsl:apply-templates>
75         </xsl:template>
76         
77         <xsl:template match="wp:comment">
78           <xsl:param name="basename"/>
79           <xsl:variable name="cnum" select="format-number(wp:comment_id, '000')" />
80           <xsl:variable name="filename" select="concat($basename, '/comment_', $cnum, '._comment')"/>
81           <xsl:variable name="nickname" select="concat(' nickname=&quot;', wp:comment_author, '&quot;')" />
82           <xsl:variable name="username" select="concat(' username=&quot;', wp:comment_author_url, '&quot;')" />
83           <xsl:variable name="ip" select="concat(' ip=&quot;', wp:comment_author_IP, '&quot;')" />
84           <xsl:variable name="date" select="concat(' date=&quot;', wp:comment_date_gmt, '&quot;')" />
85           <xsl:result-document href="{$filename}" format="txt">
86             <xsl:text>[[</xsl:text><xsl:text>comment format=html</xsl:text><xsl:value-of select="$newline"/>
87             <xsl:value-of select="$nickname"/>
88             <xsl:value-of select="$username"/>
89             <xsl:value-of select="$ip"/>
90             <xsl:value-of select="$date"/>
91             <xsl:text>subject=""</xsl:text><xsl:value-of select="$newline"/>
92             <xsl:text>content="""</xsl:text><xsl:value-of select="$newline"/>
93             <xsl:value-of select="wp:comment_content"/>
94             <xsl:value-of select="$newline"/>
95             <xsl:text>"""]]</xsl:text><xsl:value-of select="$newline"/>
96           </xsl:result-document>
97         </xsl:template>
98         
99         <xsl:template match="category">
100           <xsl:text>[</xsl:text><xsl:text>[</xsl:text><xsl:text>!tag "</xsl:text><xsl:value-of select="."/><xsl:text>"]]</xsl:text>
101           <xsl:value-of select="$newline"/>
102         </xsl:template>
103         
104         </xsl:stylesheet>