baranovskypd / goodpress

WIP!! :warning: R Package to Write Posts from R Markdown to Wordpress :warning:
https://maelle.github.io/goodpress/
Other
34 stars 5 forks source link

Images didn't show #22

Closed henrywangnl closed 3 years ago

henrywangnl commented 4 years ago

for example, one image links to this path: https://henrywang.nl/rmarkdown-wordpress-goodpress/figs/wp.png

maelle commented 4 years ago

is the source of your post public? it'd help me to see index.Rmd and index.md.

maelle commented 4 years ago

This is how I included an external image in an example post

https://github.com/maelle/goodpress/blob/5a14966e93a1b7abf539a4267bfc75e2b3a05606/inst/post-example/index.Rmd#L48-L50

henrywangnl commented 4 years ago

here you go: https://github.com/henrywangnl/Blog/blob/master/20200625/index.Rmd

maelle commented 4 years ago

thanks, I made a suggestion there.

maelle commented 4 years ago

to be clear, I need to make the Xpat query less strict, but I like the idea that there's a bug when there's no alternative text :stuck_out_tongue_winking_eye:

henrywangnl commented 4 years ago

hmmm, it didn't seem change: https://henrywang.nl/rmarkdown-wordpress-goodpress/

maelle commented 4 years ago

I'll look into it shortly

maelle commented 4 years ago

I knitted Rmd and got the image https://rmd-wordpress.eu/rmarkdown-wordpress-goodpress/ (don't worry I'll remove your post from my website ;-) )

I'll know try without alt text.

maelle commented 4 years ago

even without alt text I get the image https://rmd-wordpress.eu/rmarkdown-wordpress-goodpress/, weird.

it's especially weird to me that it works for the other plot in your post on your blog!

maelle commented 4 years ago

Can you please look in your WordPress gallery (from the dasbhoard) to see whether wp.png is there?

henrywangnl commented 4 years ago

Can you please look in your WordPress gallery (from the dasbhoard) to see whether wp.png is there?

yes, it's there lol

maelle commented 4 years ago

as wp.png, right, not the old name?

at least it got uploaded, the bug must be after that

henrywangnl commented 4 years ago

yes, it's wp.png: https://henrywang.nl/wp-content/uploads/2020/06/wp.png

maelle commented 4 years ago

weird, I'm still thinking about what can have gone wrong. btw can you update goodpress, and re-run wp_post()?

henrywangnl commented 4 years ago

I re-install it but it didn't work.

henrywangnl commented 4 years ago

I tried to upload a new image and it works now...

maelle commented 4 years ago

but the ggplot2 plot disappeared?

henrywangnl commented 4 years ago

yes, ggplot2 plots work

henrywangnl commented 4 years ago

oh no, even ggplot2 plots don't show anymore haha

henrywangnl commented 4 years ago

I think something is wrong with the file path handler, which works weird...

maelle commented 4 years ago

So locally you still have the plots in the figs folder but they don't get uploaded to the gallery?

henrywangnl commented 4 years ago

So locally you still have the plots in the figs folder but they don't get uploaded to the gallery?

Yes, the plots are still there. I'm not sure if they are uploaded to WP every time I call wp_post but I can see they are in galley.

maelle commented 4 years ago

how about you delete them from the gallery manually and rerun the function?

henrywangnl commented 4 years ago

haha let me try

henrywangnl commented 4 years ago

they are uploaded to gallery successfully but didn't show correctly in the post.

maelle commented 4 years ago

mmmh can you replace post_folder with the correct path and run


post_folder <- "inst/post-example3"
file.create(file.path(post_folder, "index.html"))
withr::with_dir(
  post_folder,
  rmarkdown::pandoc_convert(
    "index.md",
    to = "html",
    output = "index.html",
    wd = getwd(),
    options = "--mathjax"
  )
)
content <- xml2::read_html(file.path(post_folder, "index.html"))
imgs <- xml2::xml_find_all(content, "//img")
imgs

this is to check the XPat query.

henrywangnl commented 4 years ago

here is what I get:

{xml_nodeset (2)}
[1] <img src="figs/unnamed-chunk-3-1.png" width="700px" style="display: block; margin: auto;">
[2] <img src="figs/wp.png" width="700px" style="display: block; margin: auto;">
maelle commented 4 years ago

Argh so the Xpat query works. I'm sorry, I'm a bit puzzled.

I think what I'd try is

maelle commented 4 years ago

(yeah sorry that's what you get for being an early tester/adopter of the package: all the problems)

henrywangnl commented 4 years ago

No worries! I did learn a lot from the discussion!

henrywangnl commented 4 years ago

I think what I'd try is

As you see from my blog, the steps you suggest work now! Yet I have no idea what happened haha!

maelle commented 4 years ago

argh yeah sometimes one needs to resort to some version of "let's try turning it off an on again" or "delete everything and starts again" :sweat_smile: I'm very relieved it worked!!

maelle commented 4 years ago

I don't see what we can add to the docs so I'll close this. :-)

henrywangnl commented 3 years ago

Hi Maelle,

It seems that this issue appears again even I tried the steps you suggested last time. Could you please check it for me? My post: https://henrywang.nl/roc-curve-simulation-classification-performance/ Post source: https://github.com/henrywangnl/Blog/tree/master/20200714 Thanks!

henrywangnl commented 3 years ago

I fixed it by changing the image URLs on the WordPress Dashboard for the time being, so now the post looks fine...

maelle commented 3 years ago

Argh, sorry I don't have time to dive into this at the moment (which is also why I took so long to respond).

I see there are .DS_store files that aren't needed, but I don't think they can be the bug source (worth trying to delete them and then adding .DS_store to .gitignore).

maelle commented 3 years ago

It's of course especially problematic since adding the images via the dashboard sounds painful!

If you feel like having a look yourself see

https://github.com/maelle/goodpress/blob/d53850cf194fe94a831e4070c4866f0dae923b8e/R/post.R#L142-L160

and

https://github.com/maelle/goodpress/blob/d53850cf194fe94a831e4070c4866f0dae923b8e/R/post.R#L219-L245

maelle commented 3 years ago

what's also important to investigate is

maelle commented 3 years ago

A last wild guess for today, apart from deleting .DS_store can you also try not using underscores in filenames? Who knows. Sorry for not being more helpful.

henrywangnl commented 3 years ago

Regarding this issue, the images not shown properly are those generated by r chunk codes as the images urls in the post are linked to the folder of figs not to the wordpress dashboard url.

henrywangnl commented 3 years ago

Hi @maelle

I think this issue might because of the following code but I didn't verify it yet, so just to give you an idea: As media is a data frame with two columns, length(media) and seq_along(media) may not what you want here. They will only loop the first two images. I guess you mean !is.null() or nrow() or something.

https://github.com/maelle/goodpress/blob/d53850cf194fe94a831e4070c4866f0dae923b8e/R/post.R#L151-L162

maelle commented 3 years ago

Would you want to try & make a PR?

henrywangnl commented 3 years ago

Sure Maelle! I'll try it.

Thanks Henry

On Mon, Oct 26, 2020, 6:45 AM Maëlle Salmon notifications@github.com wrote:

Would you want to try & make a PR?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/maelle/goodpress/issues/22#issuecomment-716318279, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE7BXKHVPP67VFDBD2R3OKTSMUEILANCNFSM4OJJT6GA .