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

vignette images not loading #172

Closed
goldingn opened this issue Oct 10, 2016 · 7 comments · Fixed by #175
Closed

vignette images not loading #172

goldingn opened this issue Oct 10, 2016 · 7 comments · Fixed by #175

Comments

@goldingn
Copy link
Contributor

@goldingn goldingn commented Oct 10, 2016

This is so useful, I can't believe I've only just seen it!

One hiccup; the images in our vignettes don't load, e.g.: http://goldingn.github.io/zoon/articles/Building_a_module.html

That's because the file paths in the html generated by pkgdown::build_site() are absolute: https://github.com/goldingn/zoon/blob/gh-pages/reference/articles/Building_a_module.html#L187

I'm guessing this is because build_articles() calls rmarkdown::html_document() with the argument self_contained = FALSE: https://github.com/hadley/pkgdown/blob/master/R/build-articles.R#L96, although it's not clear to me why they get the full filepath rather than relative to wherever build_site() is executed.

@hadley
Copy link
Member

@hadley hadley commented Oct 10, 2016

Exactly how are you calling build_site()?

@goldingn
Copy link
Contributor Author

@goldingn goldingn commented Oct 10, 2016

I've tried in RStudio, command line R (OSX), via Rscript on the unix (OSX) command line and via an overly complicated Travis hack (results). I've tried running pkgdown::build_site() on all of these and library(pkgdown); build_site() on a couple.

In all cases, the top level of this repo is the working directory and I get absolute file paths in the html as above.

Here's a bash script that replicates the problem for me:

#!/bin/bash
git clone https://github.com/goldingn/zoon.git
cd zoon
Rscript -e "getwd()"
# Rscript -e "pkgdown::build_site()"
Rscript -e "library(pkgdown); build_site()"
sed '112q;d' docs/reference/articles/Building_a_module.html
cd ..
rm -rf zoon

I get the following output (truncated):

Cloning into 'zoon'...
...
[1] "/Users/nick/Dropbox/temp/build/zoon"
...
Initialising site -----------
...
<p><img src="/Users/nick/Dropbox/Github/zoon/vignettes/building_occ6-1.png" ...

@hadley
Copy link
Member

@hadley hadley commented Oct 10, 2016

Ok, just wanted to check that you weren't calling build_site("absolute/path"). I'll look into what's going wrong.

@goldingn
Copy link
Contributor Author

@goldingn goldingn commented Oct 10, 2016

great, thanks!

@jayhesselberth
Copy link
Collaborator

@jayhesselberth jayhesselberth commented Oct 12, 2016

I think this has to do with the use of output_dir in the call to render, which has the undesired side-effect of putting in absolute paths to images.

https://github.com/hadley/pkgdown/blob/180ea3b9513e3d185c65338c8027198c254be17f/R/build-articles.R#L68

See discussion in rstudio/rmarkdown#587

It is easy enough to render the HTML in the vignette directory and then move it to docs/articles via file.rename() as suggested in that issue:

    path <- rmarkdown::render(
      file.path(pkg$path, "vignettes", file_in),
      output_format = format$format,
      output_file = basename(file_out),
      quiet = TRUE,
      envir = new.env(parent = globalenv())
    )
    tweak_rmarkdown_html(path, depth = vig_depth + depth, index = pkg$topics)

    vignette_html <- file.path(pkg$path, "vignettes", file_out)
    article_html <- file.path(pkg$path, path, file_out)
    file.rename(vignette_html, article_html)

But if there are PNGs generated during the render, they need to be moved from vignettes to docs/articles as well. I'm not sure how to learn what their names are after the render for moving, and globbing all PNGs in the vignettes directory is inelegant (but effective, and maybe safe?).

@hadley
Copy link
Member

@hadley hadley commented Oct 12, 2016

I think it'd probably be easier to copy the vignette to the target dir, build there, and then delete.

Maybe even better to copy the complete contents of the vignette dir, build, and then delete the Rmds.

hadley pushed a commit that referenced this issue Oct 17, 2016
* add missing topic param
- so that output filenames are named with topic name rather than "unknown"

* copy and build vignettes in docs/articles
- fixes #172

* copy everything from vignettes to docs/articles

* use purrr::walk
@goldingn
Copy link
Contributor Author

@goldingn goldingn commented Oct 17, 2016

👌 works like a charm, thanks both!

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

Successfully merging a pull request may close this issue.

3 participants