<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Importing posts from Wordpress</title> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="stylesheet" href="../style.css" type="text/css" /> <link rel="stylesheet" href="../local.css" type="text/css" /> </head> <body> <div class="page"> <div class="pageheader"> <div class="header"> <span> <span class="parentlinks"> <a href="../index.html">ikiwiki</a>/ <a href="../tips.html">tips</a>/ </span> <span class="title"> Importing posts from Wordpress </span> </span> </div> </div> <div id="pagebody"> <div id="content" role="main"> <p>Use case: You want to move away from Wordpress to Ikiwiki as your blogging/website platform, but you want to retain your old posts.</p> <p><a href="https://chris-lamb.co.uk/projects/ikiwiki-wordpress-import">This</a> is a simple tool that generates <a href="http://www.kernel.org/pub/software/scm/git/docs/git-fast-import.html">git-fast-import</a>-compatible data from a WordPress export XML file.</p> <p>WordPress categories are mapped onto Ikiwiki tags. The ability to import comments is planned.</p> <p>The script uses the <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> module.</p> <hr /> <p>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.</p> <p>-- <span class="createlink">simonraven</span></p> <p><a href="./importing_posts_from_wordpress/ikiwiki-wordpress-import.html">ikiwiki-wordpress-import</a></p> <hr /> <p>Perhaps slightly insane, but here's an XSLT style sheet that handles my pages. It's basic, but sufficient to get started. Note that I had to break up the ikiwiki meta strings to post this.</p> <p>-- JasonRiedy</p> <pre><code><?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wp="http://wordpress.org/export/1.0/"> <xsl:output method="text"/> <xsl:output method="text" name="txt"/> <xsl:variable name='newline'><xsl:text> </xsl:text></xsl:variable> <xsl:template match="channel"> <xsl:apply-templates select="item[wp:post_type = 'post']"/> </xsl:template> <xsl:template match="item"> <xsl:variable name="idnum" select="format-number(wp:post_id,'0000')" /> <xsl:variable name="basename" select="concat('wp-posts/post-',$idnum)" /> <xsl:variable name="filename" select="concat($basename, '.html')" /> <xsl:text>Creating </xsl:text> <xsl:value-of select="concat($filename, $newline)" /> <xsl:result-document href="{$filename}" format="txt"> <xsl:text>[[</xsl:text><xsl:text>meta title="</xsl:text> <xsl:value-of select="replace(title, '&quot;', '&amp;ldquo;')"/> <xsl:text>"]]</xsl:text><xsl:value-of select="$newline"/> <xsl:text>[[</xsl:text><xsl:text>meta date="</xsl:text> <xsl:value-of select="pubDate"/> <xsl:text>"]]</xsl:text><xsl:value-of select="$newline"/> <xsl:text>[[</xsl:text><xsl:text>meta updated="</xsl:text> <xsl:value-of select="pubDate"/> <xsl:text>"]]</xsl:text> <xsl:value-of select="$newline"/> <xsl:value-of select="$newline"/> <xsl:value-of select="content:encoded"/> <xsl:text> </xsl:text> <xsl:apply-templates select="category[@domain='tag' and not(@nicename)]"> <xsl:sort select="name()"/> </xsl:apply-templates> </xsl:result-document> <xsl:apply-templates select="wp:comment"> <xsl:sort select="date"/> <xsl:with-param name="basename">$basename</xsl:with-param> </xsl:apply-templates> </xsl:template> <xsl:template match="wp:comment"> <xsl:param name="basename"/> <xsl:variable name="cnum" select="format-number(wp:comment_id, '000')" /> <xsl:variable name="filename" select="concat($basename, '/comment_', $cnum, '._comment')"/> <xsl:variable name="nickname" select="concat(' nickname=&quot;', wp:comment_author, '&quot;')" /> <xsl:variable name="username" select="concat(' username=&quot;', wp:comment_author_url, '&quot;')" /> <xsl:variable name="ip" select="concat(' ip=&quot;', wp:comment_author_IP, '&quot;')" /> <xsl:variable name="date" select="concat(' date=&quot;', wp:comment_date_gmt, '&quot;')" /> <xsl:result-document href="{$filename}" format="txt"> <xsl:text>[[</xsl:text><xsl:text>comment format=html</xsl:text><xsl:value-of select="$newline"/> <xsl:value-of select="$nickname"/> <xsl:value-of select="$username"/> <xsl:value-of select="$ip"/> <xsl:value-of select="$date"/> <xsl:text>subject=""</xsl:text><xsl:value-of select="$newline"/> <xsl:text>content="""</xsl:text><xsl:value-of select="$newline"/> <xsl:value-of select="wp:comment_content"/> <xsl:value-of select="$newline"/> <xsl:text>"""]]</xsl:text><xsl:value-of select="$newline"/> </xsl:result-document> </xsl:template> <xsl:template match="category"> <xsl:text>[</xsl:text><xsl:text>[</xsl:text><xsl:text>!tag "</xsl:text><xsl:value-of select="."/><xsl:text>"]]</xsl:text> <xsl:value-of select="$newline"/> </xsl:template> </xsl:stylesheet> </code></pre> </div> </div> <div id="footer" class="pagefooter" role="contentinfo"> <div id="pageinfo"> <div class="pagedate"> Last edited <span class="date">Tue Feb 26 23:01:54 2019</span> <!-- Created <span class="date">Fri Oct 5 06:59:14 2007</span> --> </div> </div> <!-- from ikiwiki --> </div> </div> </body> </html>