carrot / roots-wordpress

Pull your wordpress posts into a roots project
Other
45 stars 9 forks source link

Image Download #5

Open savage7 opened 9 years ago

savage7 commented 9 years ago

Is it possible to sync the images from the blog posts to the img folder somehow?

jescalan commented 9 years ago

That capability is not a part of the extension at the moment, but would be happy to accept a pull request to add something like this!

kylemac commented 9 years ago

@savage7 to clarify, do you mean to sync them to your source files (by default /assets/img) or to the compiled site (by default /public/img)?

Could you explain the use-case a little more too, so we're clear on it?

savage7 commented 9 years ago

I meant /public/img, so that during the compile process the file are copied to /assets/img.

I want to use roots to completely sync & restyle a wordpress blog. So that compiled site has no reference to the actual wordpress blog anymore. The synced static site will then be packed in a phone gap app as content sites.

kylemac commented 9 years ago

@savage7 our coworker @slang800 works on a project that may provide some help here: https://github.com/wp-sync-db/wp-sync-db-media-files but as @jenius mentioned, that's out of scope for this extension for the time being

kylemac commented 9 years ago

actually, that project is syncing between WP installations. Sorry, I misunderstood it's intention.

I'm afraid the process to achieve what you want might be a few steps. You could manually take the wp-content/uploads directory from your current wordpress installation and drop it into your roots project and then use a wordpress find-and-replace plugin to replace references for wp-content/uploads/* to /img/*.

jescalan commented 9 years ago

Can you get a site's images from wordpress' API? If so, we could add a feature that would do this without that much effort. If not, it would be much harder. I don't see it on first scan but maybe I'm missing something...

https://developer.wordpress.com/docs/api/

kylemac commented 9 years ago

yeah, it's in there: https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/media/

jescalan commented 9 years ago

Ah nice. Looks like you need auth though. So the extension would need to accept a token and have some kind of sync_media option. We'd also need some way to scan all posts and convert any linked media to the new url structure.

Honestly seems like a feature that could be completed in a day or two. Unfortunately I'm not going to have a day or two to complete it soon, personally.

notslang commented 9 years ago

You'd just need to take the URL of the image from the JSON API, download the image, and then save it into a directory... No auth should be required.

kylemac commented 9 years ago

you need auth to get /media response from the api, it looks like. Although, the docs are not very clear about it.

notslang commented 9 years ago

Oh, and I bet you could do this by just running the compiled site through assetgraph... that should be able to download all the images you reference, optimize them, and then modify the links to point to the new local images.

notslang commented 9 years ago

And for the auth thing - Listing all media in the library with that endpoint probably requires auth because it lists non-public images. But you can still get the images by just looking for their links in the response from the JSON API that we get right now. And we would need to search for links in the JSON API response anyway because we would need to rewrite them.

jescalan commented 9 years ago

Yeah that works. I think assetgraph is overkill for a light roots extension like this (maybe you were talking about a workaround in the meantime anyway, if so then agreed), but a simple regex could scan the response and do the replacements.

notslang commented 9 years ago

Oh, I was talking about what @savage7 could use. Maybe we could use assetgraph in the extension, but it's really made for processing an already-compiled site.