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

Should {downlit} be smarter about detecting the pkgdown website URL from DESCRIPTION? #186

Open
IndrajeetPatil opened this issue Apr 22, 2024 · 2 comments
Labels
feature a feature request or enhancement

Comments

@IndrajeetPatil
Copy link
Contributor

Currently, it simply picks the first URL from all URLs specified in the DESCRIPTION file.

urls[[1]]

But I guess not everyone is aware that, if there are multiple URLs specified, the first URL should be the pkgdown website.

For example:

downlit:::package_urls("styler")
#> [1] "https://github.com/r-lib/styler" "https://styler.r-lib.org"
downlit::href_package("styler")
#> [1] "https://github.com/r-lib/styler"

Created on 2024-04-22 with reprex v2.1.0

So I am wondering if there could be a way to detect the pkgdown website URL, instead of just picking the first URL.

@olivroy
Copy link

olivroy commented Apr 22, 2024

I use a custom logic (based on experience mostly)

The best way is to check for the existence of {url}/pkgdown.yml

However, based on experience, I created these criteria to determine which URL seems to be the pkgdown site in my browse_pkg() function.

 # remove cran, github.com urls from potential pkgdown candidates
  pkgdown_candidates <-
    stringr::str_subset(
      urls,
      pattern = "github.com/.*/|cran\\.|contact.html",
      negate = TRUE
    )

  # If there are more than one link.
  if (length(pkgdown_candidates) > 1) {
    # using common pkgdown URLs pattern to identify it
    pkgdown <- grep("github.io|docs.ropensci|r.igraph", urls, value = TRUE)

    if (length(pkgdown) > 1) {
     # avoid linking papers, or other packages
     # some packages link more than one website, use the one that contains the package name
      pkgdown <- stringr::str_subset(pkgdown_candidate, package_name)
    } else {
      pkgdown <- pkgdown_candidate
 
   }
}

It is a bit ad-hoc and based on experience, but seems to be working well!

@hadley
Copy link
Member

hadley commented Jun 6, 2024

We could add something using remote_metadata() since that already figures out where an actual pkgdown site is.

@hadley hadley added the feature a feature request or enhancement label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants