-
-
Save DarrylDias/9940fe6afc17a277e32f to your computer and use it in GitHub Desktop.
Use this php script to convert a Ghost export json file to Hugo content file. Files will be created in a "output" folder, to reuse images place the ghost content folder into the hugo's static folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ghost_data = json_decode(file_get_contents("./GhostData.json"),true) ; | |
foreach ($ghost_data['data']['posts'] as $key => $value) { | |
$created_at = date("c",$value["created_at"]/1000); | |
$title = str_replace('\\','\\\\',$value["title"]) ; | |
$title = str_replace('"','\"',$title) ; | |
$slug = $value["slug"] ; | |
$markdown = $value["markdown"] ; | |
$draft = ($value["published_at"] == null) ? 'true' : 'false' ; | |
$published_at = ($value["published_at"] == null) ? date("c",$value["created_at"]/1000) : date("c",$value["published_at"]/1000); ; | |
$output_dir = "./output" ; | |
if (!is_dir($output_dir)) { | |
mkdir($output_dir); | |
} | |
$file = $output_dir."/".$slug.".md" ; | |
file_put_contents($file, '+++'); | |
file_put_contents($file, "\n", FILE_APPEND); | |
file_put_contents($file, 'date = "' .$published_at.'"', FILE_APPEND); | |
file_put_contents($file, "\n", FILE_APPEND); | |
file_put_contents($file, 'draft = ' .$draft, FILE_APPEND); | |
file_put_contents($file, "\n", FILE_APPEND); | |
file_put_contents($file, 'title = "' .$title.'"', FILE_APPEND); | |
file_put_contents($file, "\n", FILE_APPEND); | |
file_put_contents($file, 'slug = "' .$slug.'"', FILE_APPEND); | |
file_put_contents($file, "\n", FILE_APPEND); | |
file_put_contents($file, "\n", FILE_APPEND); | |
file_put_contents($file, '+++', FILE_APPEND); | |
file_put_contents($file, "\n", FILE_APPEND); | |
file_put_contents($file, "\n", FILE_APPEND); | |
file_put_contents($file, $markdown, FILE_APPEND); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment