<?php | |
define('DRUPAL_ROOT', __DIR__); | |
include_once(DRUPAL_ROOT . '/includes/bootstrap.inc'); | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | |
$nids = db_query('SELECT DISTINCT(nid) FROM {node}') | |
->fetchCol(); | |
$nodes = node_load_multiple($nids); | |
foreach($nodes as $node) { | |
$front_matter = array( | |
'title' => $node->title, | |
'date' => date('c', $node->created), | |
'lastmod' => date('c', $node->changed), | |
'draft' => 'false', | |
); | |
if (count($node->taxonomy_vocabulary_2[LANGUAGE_NONE])) { | |
$tags = taxonomy_term_load_multiple( | |
array_column( | |
$node->taxonomy_vocabulary_2[LANGUAGE_NONE], | |
'tid' | |
) | |
); | |
$front_matter['tags'] = array_column($tags, 'name'); | |
} | |
if (count($node->taxonomy_vocabulary_1[LANGUAGE_NONE])) { | |
$cat = taxonomy_term_load_multiple( | |
array_column( | |
$node->taxonomy_vocabulary_1[LANGUAGE_NONE], | |
'tid' | |
) | |
); | |
$front_matter['categories'] = array_column($cat, 'name'); | |
} | |
$path = drupal_get_path_alias('node/'.$node->nid); | |
if ($path != 'node/'.$node->nid) { | |
$front_matter['url'] = '/'.$path; | |
$content_dir = explode('/', $path); | |
$content_dir = end($content_dir); | |
} | |
else { | |
$content_dir = $node->nid; | |
} | |
$content = json_encode( | |
$front_matter, | |
JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE | |
); | |
$content .= "\n\n"; | |
$tmp_file = '/tmp/node.html'; | |
file_put_contents($tmp_file, $node->body['fr'][0]['value']); | |
$body = shell_exec('html2markdown '.$tmp_file); | |
unlink($tmp_file); | |
//$body = $node->body['fr'][0]['value']; | |
$content .= $body; | |
$dir_name = '/tmp/hugo/content/'.$node->type.'/'.$content_dir; | |
mkdir($dir_name, 0777, true); | |
file_put_contents($dir_name.'/index.md', $content); | |
} |
This comment has been minimized.
This comment has been minimized.
Here's the exact error:
|
This comment has been minimized.
This comment has been minimized.
And I think this warning can be safely ignored. It is just coming from the drupal site name, which needs to resolve. Once I fix my dns entries, I avoided that warning message. |
This comment has been minimized.
This comment has been minimized.
I put some more print statements to just show what exact problem I'm running into:
|
This comment has been minimized.
This comment has been minimized.
I finally figured it out. I was lazy to look up the php manual but as is the case always, I need to eat my own dog food.
The language part was reported Thank you so much for writing this script. Me, A web n00b, was able to use it and migrate away from the painful platform that Drupal has become now. Now, next in my list is, to look for a self-hosted commenting system. |
This comment has been minimized.
This comment has been minimized.
Same problem as rickysarraf - language was undefined on nodes, plus script hard codes 'fr' on line 60. Switch 'fr' to 'und' and node content is exported where possible. Was also migrating a site that was previously hosted in Aegir. Needed to run the script with drush 'drush php-script drupal7_to_hugo.php'. With those changes it worked well. Thank you @amoutiers for sharing. |
This comment has been minimized.
I have been running this script to migrate my drupal 7 installation to Hugo. The script does copy the content but the body of the content remains empty. As I see it, I think
$node->body['fr'][0]['value']
is coming up empty for me. Is there someway I can debug this further ? Please.