quarto-dev / quarto-cli

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

Some metadata set in `_metadata.yml` and in YAML header inside document are not correctly merged. #9864

Open cderv opened 3 weeks ago

cderv commented 3 weeks ago

Discussed in https://github.com/quarto-dev/quarto-cli/discussions/9855

Originally posted by **McKabue** June 3, 2024 **/posts/welcome/index.qmd** ``` --- title: "Welcome To My Blog" date: "2024-05-01" categories: [news] author: "martin from welcome" --- This is the first post in a Quarto blog. Welcome! ![](thumbnail.jpg) Since this post doesn't specify an explicit `image`, the first image in the post will be used in the listing page of posts. ``` **/posts/_metadata.yml** ``` categories: [tech] author: - name: James from posts ``` With the above setup, I get the following post and listing: Screenshot 2024-06-03 at 22 21 52 Screenshot 2024-06-03 at 22 22 14 ***** However, if: **/posts/welcome/index.qmd** ``` --- title: "Welcome To My Blog" date: "2024-05-01" --- This is the first post in a Quarto blog. Welcome! ![](thumbnail.jpg) Since this post doesn't specify an explicit `image`, the first image in the post will be used in the listing page of posts. ``` **/posts/welcome/_metadata.yml** ``` categories: [news] author: "martin from welcome" ``` **/posts/_metadata.yml** ``` categories: [tech] author: - name: James from posts ``` I get the following post and listing: Screenshot 2024-06-03 at 22 25 43 Screenshot 2024-06-03 at 22 25 54 ***** When the metadata is in the document file, it overwrites all parent metadata such as authors and categories instead of extending it in the post page.
cderv commented 3 weeks ago

I looked quickly into this to diagnose and I think this happens also in regular rendering not only for blog or listing.

Basically, we have a part in our code where we "override" any processing that could have been done, by forcing the use of the metadata inside the document. https://github.com/quarto-dev/quarto-cli/blob/b34b24d924f1d7b708611592c0d96fd8b3adc3a3/src/command/render/pandoc.ts#L978-L1002

So basically in here:

We got already bitten by this in revealjs for themes, where I added an escape https://github.com/quarto-dev/quarto-cli/blob/b34b24d924f1d7b708611592c0d96fd8b3adc3a3/src/command/render/pandoc.ts#L994-L998

This is very old codebase (341cc3b8eb79c6cc53e172dec3b532148db107c9 from 3 years) for backward compatibility for inline yaml rendering.

So I think either we keep it but we probably need to consider author as a isQuartoMetadata key because we process it. Or we should remove this overwrite which does not make sense anymore probably.

mcanouil commented 3 weeks ago

FYI:

it was another issue were all were merged resulting in duplicates, the fix was: https://github.com/quarto-dev/quarto-cli/commit/478b3df44b6db1e97d9bb25d5ec4dc6b0f33cdb8

cderv commented 3 weeks ago

Yes this is different. #8860 is really about listing. As I said here, the problem happening also with default project, using shared metadata.

cderv commented 3 weeks ago

A note that this is not only for author, but any key that will pass the check !isQuartoMetadata(key) && !isChapterTitle && !isIncludeMetadata(key)