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

Use config helpers consistently #2556

Merged
merged 20 commits into from
May 21, 2024
Merged

Use config helpers consistently #2556

merged 20 commits into from
May 21, 2024

Conversation

hadley
Copy link
Member

@hadley hadley commented May 17, 2024

Fixes #1927

Copy link

github-actions bot commented May 17, 2024

@hadley
Copy link
Member Author

hadley commented May 20, 2024

@jayhesselberth @maelle no need for a detailed review, but if you see anything that looks amiss, please let me know. This should substantially improve the errors we give people when they make mistakes in yaml. I'm sure it doesn't yet catch every possible failure mode, but I think it gives us a good path to follow for the future.

data_articles_index_(list(1))
Condition
Error in `data_articles_index_()`:
! articles[1] must be a list, not the number 1.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's reasonably clear that I'm talking about the first component of articles here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not write it out and put articles as code

Component 1 of articles must be a list, not the number 1.

In any case it's helpful that the last line of the error refers to the config.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that spelling it out in words will help. I think the mapping between the R data structures and the yaml structure is likely to be confusing, but I don't think that there's much better we can do until RStudio supports feedback directly on the yaml file (which I think is likely to come by the end of the year).

I do wonder if it would be better to put the file name closer, e.g. _pkgdown.yml: articles[1] must be a list.... (Making _pkgdown.yml a link so we can remove the edit bullet at the end).


articles <- pkg$vignettes$file_out[is_vig_in_articles]
purrr::map(articles, ~ paste0(c("articles/", ""), .x))
data_redirects <- function(pkg, has_url = FALSE, call = caller_env()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduced new data_redirects, like most of the other components, to make testing easier.

@@ -100,15 +100,15 @@ find_tutorials <- function(path = ".") {
}

tutorial_info <- function(path, base_path) {
meta <- rmarkdown::yaml_front_matter(path)
title <- meta$title
yaml <- rmarkdown::yaml_front_matter(path)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this in order to reserve meta for site metadata.

"{.field {where}} must supply an inline element, not a block element.",
call = caller_env()
error_pkg,
"{.field {error_path}} must be inline markdown.",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this error, but I think it's a bit clearer than the previous one (since it at least mentions markdown).

Copy link
Collaborator

@jayhesselberth jayhesselberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. These more informative errors will be helpful for yaml debugging.

Copy link
Collaborator

@maelle maelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

data_articles_index_(list(1))
Condition
Error in `data_articles_index_()`:
! articles[1] must be a list, not the number 1.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not write it out and put articles as code

Component 1 of articles must be a list, not the number 1.

In any case it's helpful that the last line of the error refers to the config.

prefix <- config_pluck_string(
pkg,
"authors.footer.text",
default = tr_("Developed by"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default = tr_("Developed by"),
default = tr_("Developped by"),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like that's how you should spell it, but I'm pretty sure my spelling is correct here 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops!!

R/build-home-index.R Outdated Show resolved Hide resolved
component <- components[[name]]
component_path <- paste0(base_path, ".", name)

config_pluck_list(pkg, component_path, has_names = c("title", "text"), call = call)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand this and the following two lines. they're called only to check the contents of components, is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right. It's a tiny bit sloppy, but it's easier than writing another function that only check, but takes the same specification as config_pluck_.

That said, I'm not 100% happy with this API, so it might change again a bit in the future (but not in this PR).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks!

@hadley hadley merged commit eae8c58 into main May 21, 2024
14 checks passed
@hadley hadley deleted the config-helpers branch May 21, 2024 19:40
SebKrantz pushed a commit to SebKrantz/pkgdown that referenced this pull request Jun 1, 2024
* Add `config_check_bool()` and use it for news
* Validate components of home
* Check footer components
* Switch to allowing `NULLs` since all defaults are effectively `NULL`
* Switch redirects checking to new style
* And update home index
* Check `width`
* Update articles and reference checking
* Update home sidebar code
* Add news bullet
* Drop accidentally added test
* Fix missing call
* Remove unusued function
* Align `markdown_text_inline()` error arguments and ...
* Use `modify_list()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standard helper for extracting options from _pkgdown.yaml
3 participants