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

Linking to images in same directory with Markdown? #239

Closed
achamess opened this issue Dec 30, 2017 · 9 comments
Closed

Linking to images in same directory with Markdown? #239

achamess opened this issue Dec 30, 2017 · 9 comments
Milestone

Comments

@achamess
Copy link

achamess commented Dec 30, 2017

Hi. I'd like to link to image files that I keep in the same directory as my .Rmd file.
With .Rmd on my computer the images render fine.

For example

Experiment 1 (Parent DIrectory)

  • Exp1.Rmd
  • IMG1.jpg
  • IMG2.jpg

Then, in my .Rmd doc, I'll make an image link:

![Image1](IMG1.jpg)

And this renders well on my desktop. But using blogdown::serve(), the images are broken. I figure this has something to do with how Hugo handles images. Image files can't be in the same directory as the .Rmd files? I see that for the figure files that are generated from the .Rmd internally (plots, etc.), the files go into a figure-html directory automatically. But for the straight external images that I keep bundled in the .Rmd parent directory, they don't show.

Is there a fix for this?

@achamess
Copy link
Author

Looking a little deeper, I see now what bookdown is doing. When code is executed in the .Rmd and it makes some kind of plot or figure, in the static folder, the plot figures are created and placed in a directory. At the same time, those same figures are also in the public directory under the Experiment 1 folder. So it seems like the way you get the figs to render is by making copies in the static folder. Could you also do the same with other static assets (images, files, etc.) that are housed in the .Rmd parent directory (Experiment 1)?

@yihui yihui added this to the v0.5 milestone Dec 31, 2017
@yihui
Copy link
Member

yihui commented Dec 31, 2017

Your understanding is absolutely correct. I admit it can be counterintuitive, but it is how Hugo works. I made special treatments to plots generated from R code chunks (move them to static/), and I was conservative about other files.

In general, static files should be put under the static/ directory. I have mentioned this in the first paragraph in this section: https://bookdown.org/yihui/blogdown/static-files.html

@yihui yihui added the question label Dec 31, 2017
@achamess
Copy link
Author

achamess commented Jan 2, 2018

Thanks for the answer. I'm trying to use the combination of R Markdown files + Hugo for a wet lab notebook. Thus, I need/want to link to image files. I know I could keep them in the s/static folder, but I don't like separating data. Just as for data analysis, I find it best to keep everything that goes together (an experiment) in one folder. Do you think it's possible to do the same as you did with R figures for other images?

@yihui
Copy link
Member

yihui commented Jan 2, 2018

I don't have a good solution, but putting the images under foo_files/figure-html/ probably works where foo is the basename of your Rmd file (without the .Rmd extension).

@achamess
Copy link
Author

achamess commented Jan 2, 2018 via email

@yihui
Copy link
Member

yihui commented Jan 2, 2018

Great! Thanks for posting back!

@yihui yihui closed this as completed Jan 2, 2018
@taraskaduk
Copy link

taraskaduk commented Jan 11, 2018

Thanks @achamess!

I'm sorry, I can't get this to work. Updated Hugo, but no luck.

Just to clarify, should my path now be like
/mysite/content/post/blogpost_folder/image.png ?

blogpost_folder is a hypothetical folder where I keep all files related to the post (images, .Rmd, the .Rproj file, the whole nine yards)

@taraskaduk
Copy link

taraskaduk commented Jan 12, 2018

I got it! Looks like it works for me too! Woo-hoo! Yass! IT WORKS!

The start of the path would be not /content or /public, but one level down (so for regular posts, would be something like /blog or /post)

@sarahsalter
Copy link

Hi there! I have a related, but different question. I am trying to use internal hyperlinks within my blog. But rather than linking images, I am trying to link text to different text in a different section of the document. For instance, I created a blog post that defines some functions in the beginning of the document, and I wanted to link those function names to the portion of the document that I give examples of the specific function. It works great when I knit the Rmd; however, it stops working once the blog is posted. If anyone could provide any suggestions or resources I would really appreciate it! Thank you!!

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

No branches or pull requests

4 participants