I make this from wordpress-xml-to-kirby
It’s not ready to use, you need to put the class in theme folder and modify your current theme.
In the loop :
$upOne = realpath(__DIR__ . '/../..');
require $upOne.'/vendor/autoload.php';
use League\HTMLToMarkdown\HtmlConverter;
$converter = new HtmlConverter(array('strip_tags' => true));
$exportdir = 'export/';
$markdown = $converter->convert(($content));
// Strip WordPress caption shortcodes, optional
$markdown = preg_replace("/\[caption(.*?)\]/", "", $markdown);
$markdown = preg_replace("/\[\/caption\]/", "", $markdown);
// Prepare various bits of content for the export
$tmptitle = str_replace('%c2%b7', '-', $post->post_name); // · <- change this char to - in the slug
$noslashes = preg_replace('/[^A-Za-z0-9\-]/', '', $tmptitle);
$tmpyear = get_the_date('Y'); //date('Y', strtotime(get_the_date()));
$tmpdate = get_the_date('Ymd');//date('Y/Ymd', strtotime(get_the_date()));
$file = $exportdir . $tmpdate . '_' . $noslashes . '/article.fr.txt'; // <--- french
$folder = $exportdir . $tmpdate . '_' . $noslashes;
$cats = array();
foreach (get_the_category() as $c) {
$cat = get_category($c);
array_push($cats, $cat->name);
}
$tags = array();
if(get_the_tags()) :
foreach (get_the_tags() as $t) {
array_push($tags, $t->name);
}
endif;
// Create the directory for the export
if (!file_exists($folder)) {
mkdir($folder, 0777, true);
}
$dom = new DOMDocument();
$dom->loadHTML(get_the_content());
$images = $dom->getElementsByTagName("img");
foreach($images as $img){
$src = $img->getAttribute('src');
file_put_contents($folder.'/'.basename($src),get_content_curl($src));
}
$pj = $dom->getElementsByTagName("a");
foreach($pj as $p){
$href = $p->getAttribute('href');
$query = 'http://www.example.com/wp-content/uploads';
if(substr($url, 0, strlen($query)) === $query){
file_put_contents($folder.'/'.basename($href),get_content_curl($href));
}
}
$cover =array();
$attachments= get_attached_media( 'image', $post->ID );
foreach($attachments as $att_id => $attachment) {
$full_img_url = wp_get_attachment_url($attachment->ID);
array_push($cover,basename($full_img_url));
file_put_contents($folder.'/'.basename($full_img_url),get_content_curl($full_img_url));
}
// Compile the content for the export
$strtowrite = "Title: " . html_entity_decode(get_the_title())
. PHP_EOL . "----" . PHP_EOL
. "Date: " . get_the_date('Y-m-d h:i')
. PHP_EOL . "----" . PHP_EOL
. "Category: " . implode(', ', $cats)
. PHP_EOL . "----" . PHP_EOL
. "Summary: "
. PHP_EOL . "----" . PHP_EOL
. "Tags: " . implode(', ', $tags)
. PHP_EOL . "----" . PHP_EOL
. "Coverimage: " . $cover[0]
. PHP_EOL . "----" . PHP_EOL
. "Text: " . $markdown;
// Save the article.txt file
file_put_contents($file, $strtowrite);
Put this in functions.php
function get_content_curl($curl){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}