Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: import image #70

Merged
merged 4 commits into from
Jul 20, 2020
Merged

feat: import image #70

merged 4 commits into from
Jul 20, 2020

Conversation

curbengh
Copy link
Contributor

@curbengh curbengh commented Jul 15, 2020

This feature is disabled by default for now; to use it:

$ hexo migrate wordpress wordpress.xml --import-image

Downloads all image attachments and save them according to their respective directories.
Example: http://yourwordpress.com/wp-content/uploads/2020/07/image.jpg => http://yourhexo.com/2020/07/image.jpg.

I'm assuming Wordpress store images like this:

http://yourwordpress.com/wp-content/uploads/2020/07/image.jpg
http://yourwordpress.com/wp-content/uploads/2000/01/image.png
http://yourwordpress.com/wp-content/uploads/2005/08/image.gif

After importing the images, the posts would still embed the original image link:

![caption](http://yourwordpress.com/wp-content/uploads/2005/08/image.gif)

User just need to (manually) replace all occurrences of http://yourwordpress.com/wp-content/uploads, the image embed should become:

![caption](/2005/08/image.gif)

Based on sample wordpress provided by @adnan360 #64 (comment)

Closes #37

@coveralls
Copy link

coveralls commented Jul 15, 2020

Coverage Status

Coverage increased (+0.8%) to 95.041% when pulling f3f3ab5 on curbengh:import-image into cb0b2dc on hexojs:master.

@curbengh
Copy link
Contributor Author

@adnan360 feel free to test this. I will merge in this weekend.

@adnan360
Copy link

adnan360 commented Jul 16, 2020

@curbengh

Downloads all image attachments and save them according to their respective directories.

Thanks a lot. This will save a lot of time and hassle in the conversion process. I wrote a script to do this earlier. My script downloads the images in the post folder (given that post_asset_folder is set to true in config) and replaces the urls in the post markdown.

Do you plan to implement the replacements in posts automatically? This would be awesome. Otherwise my script can be used for the replacement. It will just see the downloaded file, assume that it had already downloaded it and make the replacements of the wordpress (or any other) URL. The script will have to be placed in a "scripts" folder in the hexo site directory and running hexo generate would run the script. Once finished, the script file needs to be deleted from that folder. Details in readme.

EDIT: It does not download images for me. It creates the post folders, but no images are there. I can access the wp image in my browser, but it did not download it, nor the imgur image. I've tested with:

cd /tmp
wget https://github.com/hexojs/hexo-migrator-wordpress/files/4836745/hexotest.WordPress.2020-07-04.xml.zip
unzip hexotest.WordPress.2020-07-04.xml.zip
hexo init hexotest
cd hexotest
sed -i 's/post_asset_folder: false/post_asset_folder: true/' _config.yml
npm install
npm install curbengh/hexo-migrator-wordpress#import-image --save
hexo migrate wordpress ../hexotest.WordPress.2020-07-04.xml
ls source/_posts/post-with-image # returns empty, which should contain images

@curbengh
Copy link
Contributor Author

curbengh commented Jul 19, 2020

Do you plan to implement the replacements in posts automatically?

I think it's possible with this plugin, but in future PR. I consider this PR as minimal implementation for easier review.

sed -i 's/post_asset_folder: false/post_asset_folder: true/' _config.yml

This PR is not compatible with post_asset_folder: true yet since it's disabled by default, perhaps in future PR.

ls source/_posts/post-with-image # returns empty, which should contain images

Currently, http://yourwordpress.com/wp-content/uploads/2005/08/image.gif is downloaded to source/2005/08/image.gif.

nor the imgur image

It's out of scope for now, since imgur embed should still work after migration and original wp is taken offline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

image gallery inside post not migrated
4 participants