quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.9k stars 322 forks source link

Single file in `contents:` does not render #9131

Open kylebutts opened 7 months ago

kylebutts commented 7 months ago

I don't think this is the most important "bug" to fix; but I figured I would flag. When using a single file in the contents of a section (see example below), that file does not render.

It can be fixed by using a item with - file: about.qmd, but took me about ~30 mins to debug. The reason I bring up the bug at all is that yaml::write_yaml will render a single list item in contents in the form that causes bugs (see example below). This bug impacts the altdoc package (cc @etiennebacher)

Reprex:

  1. Run quarto create project website reprex to create simple website.
  2. Change _quarto.yml to:
    
    project:
    type: website

website: title: "reprex" sidebar: collapse-level: 1 style: docked contents:

format: html: theme: cosmo css: styles.css toc: true


## Problems with `write_yaml`

``` r
library(yaml)
txt = c(
  "website:",
  "  title: 'reprex'",
  "  sidebar:",
  "    collapse-level: 1",
  "    style: docked",
  "    contents:",
  "      - text: Home",
  "        file: index.qmd",
  "      - section: Section Header",
  "        contents: ",
  "          - about.qmd"
)
yaml = yaml::yaml.load(txt)
file = tempfile()
write_yaml(yaml, file)
cat(readLines(file), sep = "\n")
#> website:
#>   title: reprex
#>   sidebar:
#>     collapse-level: 1
#>     style: docked
#>     contents:
#>     - text: Home
#>       file: index.qmd
#>     - section: Section Header
#>       contents: about.qmd
cscheid commented 7 months ago

This seems like a bug on the yaml library (or perhaps you need to call yaml.load with different parameters). I'm surprised that our validation lets it through, though.

cscheid commented 7 months ago

It's even stranger; the about.qmd file is actually rendered, but doesn't show up on the navbar.

cscheid commented 7 months ago

@dragonstyle I see in https://github.com/quarto-dev/quarto-cli/blob/main/src/resources/schema/definitions.yml that sidebar-contents allows string; that means we explicitly support it in the schema. Do I understand correctly then that the bug is that we don't populate the sidebar correctly?

dragonstyle commented 7 months ago

That sounds right - it seems like this was expected to be a directory (e.g. for dynamic generation of the sidebar) so perhaps it is just an issue where we're not expecting a single file...