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

Prevent creation of faulty site #2411

Closed
wants to merge 2 commits into from
Closed

Prevent creation of faulty site #2411

wants to merge 2 commits into from

Conversation

olivroy
Copy link
Collaborator

@olivroy olivroy commented Mar 12, 2024

Fix #2329

If you think the approach is reasonable, I could add this check in some strategic places.

For me, I'd see these as good candidates:

  • build_reference()
  • build_home()
  • build_articles()
  • build_news()

Add earlier message to prevent the creation of a faulty pkgdown site in build_reference_index().

I tested this interactively with no docs folder initialized and this works as expected.

Edit: the CI failure of no-pandoc appears genuine Maybe I could make the message conditional on the presence of pandoc? I added a condition on interactivity, but that seems a bit clunky.

@hadley
Copy link
Member

hadley commented Mar 12, 2024

Hmmmm, I was thinking more of a solution that would make this error disappear altogether. I don't currently remember enough about how pkgdown initialises a site, but I was thinking about automatically calling init_site() if we could easily detect it was needed.

Comment on lines +118 to +122
cli::cli_abort(c(
"Can't create a site",
i = "Do you need to run {.run pkgdown::init_site()}?"
),
call = call)
Copy link
Collaborator Author

@olivroy olivroy Mar 12, 2024

Choose a reason for hiding this comment

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

Suggested change
cli::cli_abort(c(
"Can't create a site",
i = "Do you need to run {.run pkgdown::init_site()}?"
),
call = call)
init_site()

I see. The problem is that init_site() is not very fast. Ideally, we would just call it when necessary. but I think that this may work?

And I think that the interactive condition has to remain there, otherwise this would break tests (or make them significantly slower)

Copy link
Member

Choose a reason for hiding this comment

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

What if we (unconditionally) check for the presence of {path}/pkgdown.yml? My read of init_site() suggests that file will exist if init_site() has been run, and I doubt it will be created otherwise.

That will require some changes to the logic in is_non_pkgdown_site() too. Maybe to ignore all of the known top-level directories that pkgdown creates?

@@ -247,6 +247,7 @@ examples_env <- function(pkg, seed = 1014, devel = TRUE, envir = parent.frame())
#' @rdname build_reference
build_reference_index <- function(pkg = ".") {
pkg <- section_init(pkg, depth = 1L)
check_dst_path_exists(pkg$dst_path)
dir_create(path(pkg$dst_path, "reference"))
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this again, it might be better to wrap check_...() and dir_create() into a new function like create_subdir() or something.

Comment on lines +118 to +122
cli::cli_abort(c(
"Can't create a site",
i = "Do you need to run {.run pkgdown::init_site()}?"
),
call = call)
Copy link
Member

Choose a reason for hiding this comment

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

What if we (unconditionally) check for the presence of {path}/pkgdown.yml? My read of init_site() suggests that file will exist if init_site() has been run, and I doubt it will be created otherwise.

That will require some changes to the logic in is_non_pkgdown_site() too. Maybe to ignore all of the known top-level directories that pkgdown creates?

Comment on lines +250 to 251
check_dst_path_exists(pkg$dst_path)
dir_create(path(pkg$dst_path, "reference"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
check_dst_path_exists(pkg$dst_path)
dir_create(path(pkg$dst_path, "reference"))
create_subdir(pkg$dst_path, "reference")

To make sure I understand correctly:

if a pkgdown site: just create new reference dir, otherwise (if !fs::file_exists(pkg$dst_path, "pkgdown.yml")) call init_site() then create the new reference dir?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's what I was thinking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. I will think a little bit more. Will let you know when it is ready. I realized that this isn't an issue if you don't have _pkgdown.yml. You don't run in these issues with BS 3 for example..

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.

FR: use more clickable hyperlinks in error messages
2 participants