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
Links to assets in blogdown page bundles get "too shallow" relative links in HTML #2037
Comments
Sorry I've seen your SO post the day when you posted it and it has stayed in my browser since then, but I still don't have time to read the wall of text :) At the moment, I can only say that it has been logged in my todo list: https://yihui.org/todo/#todo |
I didn't know you kept a public TODO - I skimmed through it, and was stunned to see this very question has already been discussed by yourself (no. 11 on your TODO) and none other than Alison Hill (whose theme I used for my demo site). I don't know how I missed that github issue during my research. :: really embarrassed :: Sorry for the noise. Alison suggests a couple of different Hugo theme-level fixes, which I believe could work nicely. But I'm surprised the Apero theme (which is fairly new, right?) didn't include one of those fixes? (this is not a criticism, I'm just asking because perhaps I missed something when I setup my Apero demo-site?) Yihui himself explains how chunk plot output gets absolute URLs, namely with a shortcode used like this I'll look into these suggested approaches and try to document the approach I take for my site on SO and/or here. I understand that we should perhaps demand more from RSS reader software, but I can't shake the feeling that site generators like Hugo are the ones that introduced bundling, and thus it's mostly on our generator to produce proper relative links. I have one remaining question, I think. Will either of those approaches (theme-level hooks or shortcode) work for |
Right, I've revisited this thorny issue a couple of times because it has affected several people (e.g., pretty much anyone who uses R-bloggers). I think I know how to fix the RSS feeds but don't have the time yet.
No worries!
I haven't looked closely at Apero yet but it seems we should include one of those fixes. I'll remember to do that, or at least remind Alison. Yes, it's a new theme, and we should have applied the knowledge we learned. Thanks for the feedback!
I'm thinking of automatically adding |
Really appreciate your kind comments! Yeah, if Appreciate the work that went into the Apero theme. It looks awesome and was very easy to get started with. |
I think there is a problem with how
knitr::include_graphics()
or![]()
produces links when relative links to assets in page bundles are used. Whether the source file is.RMarkdown
or.Rmd
made no difference.I have described the issue in detail in this StackOverflow question (so far no comments/answers, I suppose the wall of text is disheartening ;-). So I'll try to be short and to the point here.
I've created a new blogdown site at https://joys.solarchemist.se, and published its full source on github (I started from Alison Hill's nice guide).
I originally observed this problem of relative links in the RSS full-text for my own site, but after observing the same issue for with this newly created site I've become more confident that the issue was not due to some configuration error in my site.
Let's look at a blog post with static images, say
https://joys.solarchemist.se/blog/fonts/
. If we compare the HTML source to the Rmd source, we will see that all images included using eitherinclude_graphics()
or![]()
have what I like to call "shallow" relative links, i.e., relative to the blog post itself, like so:<img src="isaac-font.png" ... />
.If we do the same inspection for plots generated from knitr figure chunks (e.g., see this other post on the same blog, Rmd source here), we can see that those images get "deep" relative links, i.e., links that are relative to the blog site root, like this:
<img src="//joys.solarchemist.se/blog/rmarkdown/index_files/figure-html/unnamed-chunk-1-1.png" .../>
. (Note: in this case, our "deep" link became an absolute link because we've setbaseURL: "//joys.solarchemist.se/"
in the site's config).Both of these link schemas (which I've labelled "shallow" and "deep" relative links) render fine in any browser I know of. But only the deep relative links render correctly in an RSS reader (I've only extensively tested TinyTinyRSS). The shallow relative links is just a broken image in the RSS full-text.
So it seems to me that knitr is already doing something smart when constructing a "deep" relative link when it renders links to chunk images. Could or should the same mechanism perhaps also be applied to
include_graphics()
?Manually keeping tracking of the blog post's URL (albeit simple in this case,
/blog/fonts/
) is very cumbersome, especially since the permalink schema setting in the siteconfig.yml
can include year/month/date etc., and in that case simply changing thedate
in the post's frontmatter creates a new blog post URL.Dammit, this still became a wall of text. Sorry everyone, I tried to be brief ;-)
By filing an issue to this repo, I promise that
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
.I understand that my issue may be closed if I don't fulfill my promises.
The text was updated successfully, but these errors were encountered: