Coder Social home page Coder Social logo

yihui / blogdown-jekyll Goto Github PK

View Code? Open in Web Editor NEW
205.0 17.0 165.0 42 KB

Automatically knit R Markdown documents, build them with Jekyll, and serve the website with servr locally

Home Page: https://jekyll.yihui.org

License: MIT License

HTML 31.54% R 10.40% SCSS 58.06%
jekyll knitr css html

blogdown-jekyll's Introduction

This is a repo to host the (Markdown) source files of my personal website, including my Chinese and English blogs, as well as several project websites (such as knitr.) The content of all pages is licensed under CC BY-NC-SA 4.0.

You are welcome to post comments on my site. To do so, you need to log in using your GitHub account at the bottom of a page. If you have any other feedback, comments, or questions, please post them to my GitHub discussion board.

A technical note

To build the website locally, you must clone this repo with its submodule (use the --recursive argument), e.g.,

git clone --recursive [email protected]:yihui/yihui.org.git

The website is built via the R package blogdown. Please read its documentation for how to use it.

I don't recommend you to study how my website is built, because it is complicated. In particular, the way I manage images is fairly complicated.

blogdown-jekyll's People

Contributors

cpsievert avatar grantmcdermott avatar luispuerto avatar yihui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blogdown-jekyll's Issues

separate build vs serve?

Hi Yihui,

It would be great to have some way to know when servr::jekyll() was finished building the site (e.g. finished both the knitr and jeykll build steps), such that I could have a script automatically push the updated site to Github.

I'm probably missing something obvious, but at the moment I can't figure out how to do this. I try Rscript -e "servr::jekyll() and because it starts serving the site, the script just keeps running and never finishes and returns, or I can try: Rscript -e "servr::jekyll(daemon=TRUE) and then the script returns immediately but I cannot add a subsequent deploy command because it runs before the site is done building. My thinking might be to add an argument like build_only=TRUE to servr::jekyll() function? (I see that jekyll() seems tightly wrapped around dynamic_site so it's not obvious to me how best to formulate this logical separation. I'm probably missing a better way to go about this in any case).

Figure path misspecified during knit process

Hi again, Yihui.

I've encountered a minor build error when creating new posts. In short, none of the figures render correctly when I try to add/knit new .Rmd files via blogdown::build_site().

I believe the problem occurs because the gsub function on line 12 of build_one.R doesn't account for the fact that the preceding shell script call (i.e. here) prepends ./ to create the relative path. The upshot is that this messes up the figure path that the resulting .md file is supposed to reference against. We end up adding an extra ./ and also fail to remove the leading underscore in _posts.

(FWIW I don't think you would have encountered this issue, because you are specifying a special Dropbox path for your own figures.)

Here's a simple example where my .Rmd file is just printing plot(1:10).

If I build/serve the site with this new .Rmd file, the post appears but the image is missing.

bdj1

It's clear what went wrong from the actual knitted .md file. Again, the figure path is misspecified because of the extra ./_ after "/figure".

{% highlight r %}
plot(1:10)
{% endhighlight %}

![plot of chunk unnamed-chunk-1](/figure/./_posts/2020-10-16-test1/unnamed-chunk-1-1.png)

Ofc the pretty simple solution is just to account for this extra ./ in the original gsub() function. If I do that and rebuild/serve, then everything works as expected.

bdj2

I'll submit a PR with this little patch.

could not find function "setRefClass"

Using a reference class causes an error when serving jekyll pages:
Error in eval(expr, envir, enclos): could not find function "setRefClass"

Interestingly, the RMarkdown script works fine otherwise, when running in the RStudio IDE and when generating a PDF from knitr. Any reason reference classes would fail with servr::jekyll() ?

Build scrips are not working

First:

> blogdown:::serve_site()
Launching the server via the command:
  jekyll serve --port 4321 --host 127.0.0.1 --watch --incremental --livereload
Serving the directory . at http://127.0.0.1:4321
Launched the jekyll server in the background (process ID: 89094). To stop it, call blogdown::stop_server() or restart the R session.
* knitting ./_posts/2014-09-28-jekyll-with-knitr.Rmd
Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : 
  object 'Rscript' not found
Calls: build_one -> ::: -> get
Execution halted
Error in run_script("R/build.R", as.character(local)) : 
  Failed to run R/build.R

Then I tried to change Rscript for run_script

> blogdown:::serve_site()
Launching the server via the command:
  jekyll serve --port 4321 --host 127.0.0.1 --watch --incremental --livereload
Serving the directory . at http://127.0.0.1:4321
Launched the jekyll server in the background (process ID: 98950). To stop it, call blogdown::stop_server() or restart the R session.
* knitting ./_posts/2014-09-28-jekyll-with-knitr.Rmd
Error in if (blogdown:::run_script(shQuote(c("R/build_one.R", io))) !=  : 
  argument is of length zero
Calls: build_one
Execution halted
Error in run_script("R/build.R", as.character(local)) : 
  Failed to run R/build.R

Any idea?

Using htmlwidgets graphics with servr::jekyll()

I'm trying to use metricsgraphics with my jekyll blog but I can't find where I'm missing something.

It seems that the div is created but the graphic never shows up.

Take a look at this: http://dfalbel.github.io/knitr-jekyll/2014/09/jekyll-with-knitr.html

However when I just knit the file in RStudio, evrything works great. See this file:
https://github.com/dfalbel/knitr-jekyll/blob/gh-pages/_source/2014-09-28-jekyll-with-knitr.html

I also tried this with others htmlwidgets like recharts and chartist.

Thanks for the help!

Python rendering

Yihui, thanks for writing knitr-jekyll -- it works exactly as advertised. What is not advertised, and I am not sure if it is supported is Python rendering. knitr can render (and evaluate) Python code. Is this also possible with knitr-jekyll?

New Post add-in not working (misses _config.yml?)

Hi Yihui,

I'm having trouble creating new posts with this template using the "New Post" RStudio add-in. Here's the error message I get if I try to execute the add-in on a clone of your repo:

> blogdown:::new_post_addin()
Error in blogdown:::site_root() : 
  Could not find config.toml / config.yaml under
   /home/grant/blogdown-jekyll
   /home/grant
   /home
   /

So, the problem appears to be that the add-in triggers blogdown:::new_post_addin(), which in turn searches for one of "config.toml" or "config.yaml". In other words, it's not searching for the actual configuration file — "_config.yml" — attached to the site.

Aside: Should "_config.yml" be added to the list of configuration files that blogdown searches for / recognises? That's the standard naming convention for Jekyll sites at least. I'm happy to raise an issue on the main blogdown repo if you agree.

If I manually copy the "_config.yml" configuration file to "config.yaml", then executing the add-in triggers a new error:

> blogdown:::new_post_addin()
Warning: You are recommended to ignore certain files in config.yaml: set the option ignoreFiles: ["\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$"]
Error in setwd(content_file()) : cannot change working directory

I should say that all of the other blogdown integrations with this template appear to work (serve_site(), etc.) I'm also somewhat surprised that no-one else has run into this problem. I don't think there's anything unusual with my system, but I provide my session info below. FWIW, I'm running the latest preview release of RStudio (Version 1.4.869).

Thanks in advance!

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblas_haswellp-r0.3.10.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5          bookdown_0.20       digest_0.6.25       later_1.1.0.1      
 [5] mime_0.9            R6_2.4.1            jsonlite_1.7.1      xtable_1.8-4       
 [9] magrittr_1.5.0.9000 evaluate_0.14       blogdown_0.20.2     rlang_0.4.8        
[13] miniUI_0.1.1.1      promises_1.1.1      rmarkdown_2.4.1     tools_4.0.2        
[17] shiny_1.5.0         fastmap_1.0.1       httpuv_1.5.4        xfun_0.18          
[21] yaml_2.2.1          rsconnect_0.8.16    compiler_4.0.2      htmltools_0.5.0    
[25] knitr_1.30     

create new pages?

Hi Yihui,

I have forked your repo and Im using it to build my own website! This is a very nice structure since integration with rmarkdown and knitr is just awesome! I am wondering how one could creat a new page using your workflow?
I am not sure this is the best place to ask this question, so if it is not, please let me know.

Thanks for developing such nice resources for R users!

Gustavo

Error: invalid byte sequence in UTF-8

I'm fairly new Jekyll but I followed Jekyll's website and used Pudhina theme. Everything worked well until then.
Later I have tried by cloning blogdown-jekyll and ran according to the instructions provided on repository and it worked fine.

selection_006

I created a very minimalistic markdown file (which gets generated automatically when I create a new markdown file) to the _posts folder to test but faced Error: Invalid byte sequence in UTF-8.

selection_008

I was able to the plot in the figure folder but as the message says it was unable to read the file. Surprisingly, the message also says jekyll verson as 3.1.6 but I have installed the latest version 3.8.3.

selection_005

Could you let me know what the issue is?

Terminate server

Is there a way to terminate the server that servr::jekyll() starts? I am using the build tools in Rstudio with a makefile with the following line: Rscript -e "servr::jekyll('..', script = 'build.R', command = 'bundle exec jekyll build', port = 4000)"

It works fine, but when I terminate the script in Rstudio, the server still keeps on running until I close down Rstudio.

R Studio Can't Find Jekyll

I have read a lot on using R studio with Jekyll. I am trying to get this set up as described here:
https://github.com/yihui/knitr-jekyll

Jekyll works fine from the command prompt for me. I just cant get it to work with R studio.

which ruby from Terminal:
/Users/chrislevy/.rvm/rubies/ruby-2.2.4/bin/ruby

which jekyll from Terminal:

/Users/chrislevy/.rvm/gems/ruby-2.2.4/bin/jekyll

echo $PATH from Terminal:

/Users/chrislevy/.rvm/gems/ruby-2.2.4/bin:/Users/chrislevy/.rvm/gems/ruby-2.2.4@global/bin:/Users/chrislevy/.rvm/rubies/ruby-2.2.4/bin:/Users/chrislevy/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Library/TeX/texbin:/Users/chrislevy/.rvm/bin

I just cant get R studio to find jekyll (at least I think thats the problem).

I am using servr::jekyll() and I get the same error as reported here: http://stackoverflow.com/questions/31091443/r-servrjekyll-build-error

I have tried all the solutions listed there, even by giving the direct path for Jekyll in the servr::jekyll(command = )

Within R studio:

system("which jekyll") --> (returns an empty string so Im assuming it cant find it)

Sys.getenv('PATH') --> /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Library/TeX/texbin

system("which ruby") --> /usr/bin/ruby

I think it all has something to do with $PATH. I am bit of a noob when it comes to stuff like this. I installed jekyll through ruby rvm. A long while back when I was even more of a noob I may of installed ruby through some sort of sudo command or something so I hear that can mess things up.

R code chunks transformed into a single line

Hi Yihui,
thanks for the great package, first of all.

I'm having a problem with the display of code chunks: they are rendered as a single line. I tried different configurations in _config.yml, to no avail. Currently I'm using kramdown, and whether I specify the rouge highlighter or not, the result is the same.

The interesting thing is that knitr renders them correctly.

I google around and I did not find a solution. I'm not even sure it is an issue of knitr-jekyll, though.

Thanks.
Osvaldo

Pandoc

Hi Yihui,

I'm enjoying servr and knitr-jekyll so far; really nice work. Like you say in your blog post, the other markdown parsers are akward (though note that kramdown supports fenced code blocks using tildes ~, so no need for cludgy liquid code. Tilde-fenced code blocks are also recognized by pandoc as you know).

Given that a user is running servr::jekyll() locally anyway to call knitr, render, and preview the document, it seems like one may as well set _config.yml to pandoc:

markdown: pandoc
gems: 
  - jekyll-pandoc

(e.g. as in my fork).

Of course the only nuisance with this is having to maintain separate gh-pages and master branches to distinguish between the source and the output. (You can't just use a .nojekyll)

Unfortunately Jekyll doesn't let you have a destination directory that the same as or contains the source directory. Otherwise one could configure Jekyll to work a bit more like your servr does, where inputs are stored in a subdirectory and outputs just appear where they are expected to.

Trouble with jekyll and Rstudio (not the same as other issue)

I'm trying to use jekyll to create blog posts out of Rmarkdown files. My work flow consists of the following. I've successfully installed jekyll server. I also have github desktop installed and Rstudio. First, I forked your repo from github https://github.com/yihui/knitr-jekyll to my own repository. Next, I created a project in Rstudio using the forked repo. Everything so far is fine. When I go to my repo I can click on the link to my site and it pops up with the default posts already there. All I would like to do is add additional blog posts or even edit current default ones but I am at a loss as to how to do that. When I create a new Rmarkdown file in Rstudio in project mode and save it to the _source it creates a markdown file that I then move over to _posts. When I commit changes via github desktop everything seems to work just fine. I navigate to my site at https://cmohamma.github.io and I can see additional blog posts added.

However, when I click on any of the added blog posts, it displays them in non markdown form like in the following link (https://cmohamma.github.io/2016/06/iranelections.html). How do I get Rstudio to render the file into the proper format. I'm sure I'm missing something here. Thank you!

julia deprecated types?

Hi Yihui,

I tried to use knitr with the Julia engine, and encountered some strong errors with Julia 4.5. Hopefully you can help solve this issue.

The output of error is below:

$ Rscript -e "servr::jekyll(command='~/.rvm/gems/ruby-2.3.0/wrappers/jekyll build')"
WARNING: int(s::AbstractString) is deprecated, use parse(Int,s) instead.
 in depwarn at ./deprecated.jl:73
while loading /home/qxd/R/x86_64-pc-linux-gnu-library/3.2/runr/lang/julia_socket.jl, in expression starting on line 4
ERROR: LoadError: listen: address already in use (EADDRINUSE)
 in listen at ./socket.jl:694
while loading /home/qxd/R/x86_64-pc-linux-gnu-library/3.2/runr/lang/julia_socket.jl, in expression starting on line 4

In the .Rmd file, I basically followed your template to have the r setting as below (first a few lines of the file):

library(knitr) 
library(runr) 
j = proc_julia() 
j$start() 
knit_engines$set(julia = function(options) { 
  knitr:::wrap(j$exec(options$code), options) 
}) 

Insights? Thanks.

Using blogdown-jekyll with _collections directory

I've tried using this with _posts and it works great - the Rmd files autoregenerates on its own the also makes a figure directory at the base directory. However, if I make other directories that are not called '_posts' and change the .Rprofile blogdown.subdir = '_collections', I can't autoregenerate the Rmd files anymore. I was wondering if you have any insights into this. I'm probably just missing something very obvious but couldn't figure it out.
Thank you!

Clarify readme: serve locally for development but still deploy a static site to gh-pages?

Hi Yihui,

Just finding some time to dig into your knitr-jekyll project here and it looks awesome. I must admit that I was a bit confused by the discussion of servr at first. Just to make sure, your intended workflow is that a user can develop their site in RStudio while relying on sevr for a live preview, but can still rely on gh-pages to host the rendered content? (e.g. surely I'd rather host my site on Github's reliable CDN-backed site rather than on my own server).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.