Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Substitute image links with downloaded paths #42

Open
berezovskyi opened this issue Jun 15, 2013 · 2 comments
Open

Substitute image links with downloaded paths #42

berezovskyi opened this issue Jun 15, 2013 · 2 comments

Comments

@berezovskyi
Copy link

It's rather good that exitwp has download_images option. It'd be great if all image links would be replaced with new ones in process.

@andrewferrier
Copy link

+1. This would be really useful.

@coopermaruyama
Copy link

I've worked around this by doing the following, should work for you (for images you uploaded in wordpress using it's built-in uploader but you can easily change that):

1. Use the body_replace config block in config.yml to have exitwp rewrite the paths:

body_replace: {
  'http://domain.com/wp-content/uploads/[0-9]+/[0-9]+/': '/media/images/{{ page.date }}-{{ page.slug }}/'
}

2. page.date by default is formatted like 2012-07-02 00:15:24+00:00 but the path exitwp creates for images uses just the 2012-07-02 part. Therefore we need to remove everything after YYYY-MM-DD on the frontmatter of all the posts exitwp generates. Using your text editor or bash (I used Sublime Text), do a find/replace on the files exitwp generates in build/jekyll/domain.com/_posts:

  • Find: (date: [0-9]+ [0-9]+ [0-9]+)(.+)$
  • Replace with: $1

3. In your jekyll path create /media/images/ and move the images from exitwp there.

In step 1, If you could put {{ page.date | date: "%F" }} instead of {{ page.date }} that would remove the need to perform step 2, but for some reason html2text.py breaks if you have double quotes. I tried escaping with slashes but that does not work either. My python sucks so maybe someone can write this behavior into exitwp and create a PR.

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

No branches or pull requests

3 participants