You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 lines
1.7 KiB

<?php
$json = file_get_contents('import.json');
$data = json_decode($json, true);
$posts = $data['db'][0]['data']['posts'];
foreach($posts as $post){
echo '.';
$mobiledoc = json_decode($post['mobiledoc'], true);
$postcontent = '';
foreach($mobiledoc['cards'] as $card){
$postcontent .= $card[1]['markdown'];
}
$tpl = "{% extends 'post.twig' %}\n{% block entry %}\n{% markdown %}\n" . $postcontent . "\n{% endmarkdown %}\n{% endblock %}\n";
file_put_contents('templates/casper/pages/posts/' . date('Y-m-d', strtotime($post['created_at'])) . '_' . $post['slug'] . '.twig', $tpl);
$ini = "[settings]\nslug = \"" . $post['slug'] . "\"\n\n";
$ini .= "[variables]\n";
if($post['feature_image']){
if(substr($post['feature_image'], 0, 8) == "https://" || substr($post['feature_image'], 0, 7) == "http://"){
$img = file_get_contents($post['feature_image']);
$url = parse_url($post['feature_image']);
$filename = 'static/casper/img/posts' . $url['path'];
if(substr($filename, -4) !== '.png' && substr($filename, -4) !== '.jpg'){
$filename .= ".jpg";
}
}else{
$img = file_get_contents('https://tsia.me' . $post['feature_image']);
$filename = 'static/casper/img/posts/' . basename($post['feature_image']);
}
file_put_contents($filename, $img);
$ini .= "image = " . str_replace('/casper/', '/', $filename) . "\n";
}
$ini .= "title = \"" . str_replace('"', "'", $post['title']) . "\"\ndate = " . date('Y-m-d H:i:s', strtotime($post['created_at'])) . "\n";
file_put_contents('templates/casper/pages/posts/' . date('Y-m-d', strtotime($post['created_at'])) . '_' . $post['slug'] . '.ini', $ini);
}