Open IndrajeetPatil opened 7 months ago
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!
We could add something using remote_metadata()
since that already figures out where an actual pkgdown site is.
Currently, it simply picks the first URL from all URLs specified in the
DESCRIPTION
file.https://github.com/r-lib/downlit/blob/c0a8f645e21a03e258b7c1684901f84279cc706a/R/link.R#L343
But I guess not everyone is aware that, if there are multiple URLs specified, the first URL should be the pkgdown website.
For example:
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.