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

New post writes incorrect yaml if archetype contains yaml unnamed list #684

Closed
cderv opened this issue Feb 7, 2022 · 2 comments
Closed
Labels
bug an unexpected problem or unintended behavior

Comments

@cderv
Copy link
Collaborator

cderv commented Feb 7, 2022

Take this test.Rmd file

---
links:
  - icon: images
    icon_pack: fas
    name: slides
    url:
  - icon: github
    icon_pack: fab
    name: code
    url:
---

Content

new_post() will at some point try to modify the YAML header, and this is where we loose the correct YAML format:

save_copy <- file.copy("test.Rmd", "test.Rmd.save")
xfun::file_string("test.Rmd")
#> ---
#> links:
#>   - icon: images
#>     icon_pack: fas
#>     name: slides
#>     url:
#>   - icon: github
#>     icon_pack: fab
#>     name: code
#>     url:
#> ---
#> 
#> Content
blogdown:::modify_yaml("test.Rmd")
xfun::file_string("test.Rmd")
#> ---
#> links:
#>   icon: images
#>   icon_pack: fas
#>   name: slides
#>   url: ~
#>   icon: github
#>   icon_pack: fab
#>   name: code
#>   url: ~
#> ---
#> 
#> Content
rmarkdown::yaml_front_matter("test.Rmd")
#> Error in yaml::yaml.load(..., eval.expr = TRUE): Duplicate map key: 'icon'


# restore
file.rename("test.Rmd.save", "test.Rmd")
#> [1] TRUE

All the - in front of the YAML list item are removed which leads to incorrect YAML.

First reported in https://community.rstudio.com/t/having-nested-elements-on-blogdown-hugo-archetypes/127761/2 by @llrs

@cderv cderv added the bug an unexpected problem or unintended behavior label Feb 7, 2022
@yihui yihui moved this to Backlog in R Markdown Team Projects Feb 16, 2022
@yihui yihui moved this from Backlog to In Progress in R Markdown Team Projects Feb 16, 2022
@yihui yihui closed this as completed in 38e16a5 Feb 16, 2022
Repository owner moved this from In Progress to Done in R Markdown Team Projects Feb 16, 2022
@yihui
Copy link
Member

yihui commented Feb 16, 2022

Should be fixed now. Please try the dev version:

remotes::install_github('rstudio/blogdown')

Thanks!

The problem was from this line introduced from the PR #118:

x = unlist(x, recursive = FALSE)

@cderv
Copy link
Collaborator Author

cderv commented Feb 16, 2022

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
Archived in project
Development

No branches or pull requests

2 participants