rstudio / blogdown

Create Blogs and Websites with R Markdown
https://pkgs.rstudio.com/blogdown/
1.73k stars 335 forks source link

Using three dashes in YAML config stops site from building #194

Closed andrewheiss closed 7 years ago

andrewheiss commented 7 years ago

When using a YAML-based config file, blogdown breaks if config.yaml starts/ends with ---delimiters, which are typically allowed in Hugo config files.

(Using R 3.4.1 on macOS with blogdown 0.1.2, 2017-08-29, Github (rstudio/blogdown@3df12f3))

Here's a minimal example:

Using the following config.yaml

---
baseurl: "/"
title: "Example site"
---

… creates this error when running create_site():

> blogdown::build_site()
Error in attr(config, "config_time") <- file.info(f)[, "mtime"] : 
  attempt to set an attribute on NULL

However, removing the ---s …

baseurl: "/"
title: "Example site"

… results in no error:

Started building sites ...
Built site for language en:
...
total in 19 ms

Running hugo from the terminal works just fine with and without the ---s in config.yaml, but it naturally doesn't parse any Rmd files. Is there anything stopping blogdown from parsing --- YAML files correctly?


Here's the full session information:

Session info -------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.1 (2017-06-30)
 system   x86_64, darwin15.6.0        
 ui       RStudio (1.1.331)           
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Denver              
 date     2017-08-28                  

Packages -----------------------------------------------------------------------------------------
 package   * version date       source                           
 backports   1.1.0   2017-05-22 cran (@1.1.0)                    
 base64enc   0.1-3   2015-07-28 CRAN (R 3.4.0)                   
 bitops      1.0-6   2013-08-17 CRAN (R 3.4.0)                   
 blogdown    0.1.2   2017-08-29 Github (rstudio/blogdown@3df12f3)
 bookdown    0.5     2017-08-20 cran (@0.5)                      
 caTools     1.17.1  2014-09-10 CRAN (R 3.4.0)                   
 digest      0.6.12  2017-01-27 CRAN (R 3.4.0)                   
 evaluate    0.10.1  2017-06-24 CRAN (R 3.4.1)                   
 graphics  * 3.4.1   2017-07-07 local                            
 grDevices * 3.4.1   2017-07-07 local                            
 highr       0.6     2016-05-09 CRAN (R 3.4.0)                   
 htmltools   0.3.6   2017-04-28 CRAN (R 3.4.0)                   
 httpuv      1.3.5   2017-07-04 CRAN (R 3.4.1)                   
 jsonlite    1.5     2017-06-01 CRAN (R 3.4.0)                   
 knitr       1.17    2017-08-10 cran (@1.17)                     
 magrittr    1.5     2014-11-22 CRAN (R 3.4.0)                   
 markdown    0.8     2017-04-20 CRAN (R 3.4.0)                   
 methods   * 3.4.1   2017-07-07 local                            
 mime        0.5     2016-07-07 CRAN (R 3.4.0)                   
 Rcpp        0.12.12 2017-07-15 CRAN (R 3.4.1)                   
 rmarkdown   1.6     2017-06-15 CRAN (R 3.4.0)                   
 rprojroot   1.2     2017-01-16 cran (@1.2)                      
 servr       0.7     2017-08-17 cran (@0.7)                      
 stats     * 3.4.1   2017-07-07 local                            
 stringi     1.1.5   2017-04-07 CRAN (R 3.4.0)                   
 stringr     1.2.0   2017-02-18 CRAN (R 3.4.0)                   
 tools       3.4.1   2017-07-07 local                            
 utils     * 3.4.1   2017-07-07 local                            
 yaml        2.1.14  2016-11-12 CRAN (R 3.4.0) 
pssguy commented 7 years ago

I may be having the same issue - although it is when I want to put a horizontal line in the body of the post. When I do, the following chunk loses its controls

before withoutlines

after withlines

pssguy commented 7 years ago

I should have stated I'm on Windows: Version 1.1.345 so this might already have been addressed

yihui commented 7 years ago

@andrewheiss A YAML file should not contain three dashes. The notion of three dashes only exists in Markdown files. They mark the beginning and end of YAML metadata but they are not part of the metadata.

@pssguy Your issue is different (please file new issues unless you are very sure you have the same issue). Do you have an empty line before and after three dashes?

andrewheiss commented 7 years ago

Hugo supports dashes in standalone YAML files, though (see https://github.com/kjhealy/kieranhealy.hugo/blob/master/config.yaml, for instance)

yihui commented 7 years ago

Hmm, interesting. The R package yaml does not support them, and I cannot support them in blogdown since blogdown uses yaml to parse YAML files. Anyway, I guess it does not hurt if you remove them.

andrewheiss commented 7 years ago

The fact that yaml can't handle them makes sense. I was struggling to figure out why Hugo could handle them while blogdown choked. Thanks!

yihui commented 7 years ago

I could write a helper function to get rid of the three dashes before parsing the YAML data, but I want to wait until another person reports this issue.

andrewheiss commented 7 years ago

Or perhaps a warning telling people to remove the dashes?

yihui commented 7 years ago

Okay, I'll just add a wrapper function to yaml::yaml.load_file(). Thanks for the suggestion!

yihui commented 7 years ago

Three dashes in config.yaml will be ignored from now on.

charlesritchea commented 6 years ago

I'm not a consumer of this library and I know this has been fixed, but YAML absolutely supports three dashes as a document delimiter, and even a single document created by jackson will start with --- http://yaml.org/spec/current.html#id2502724