Broken image links when publishing bookdown on GitHub pages

This issue was raised earlier:

But the solution didn't work for me (late 2020), so I'm sharing my own here.

Issue: bookdown saves images generated by the R code to a directory called /_main_files/figure-html. However, GitHub's default site generator jekyll ignores all directories starting with an underscore (_), so the image links broke when I tried to view the site online.

Solution: The problem can be solved by adding an empty file to the directory called .nojekyll, which disables jekyll. This works for us, since bookdown already generates a standalone site and doesn't need jekyll. What helped me specifically was adding .nojekyll to the same directory as the index.html file - usually it's the docs/ directory.

Hope this is useful.

2 Likes

You’ll also find this step mentioned in the bookdown book instructions for setting up a gh-pages workflow.

Alas, I originally put .nojekyll in the root folder, which did not do the trick. And then it took me some time to track down the underscore issue and link it back to jekyll.

Ah. Yes, it has to be in the root directory of the content being served by Github Pages, which I think would be wherever index.html is, regardless of how everything is setup. Good catch.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.