Skip to content

Commit

Permalink
feat: use_poisson_pkgdown()
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Sep 10, 2024
1 parent 43732e6 commit 7f30004
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 23 deletions.
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
Imports:
cli,
desc,
yaml
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(ruler)
export(use_poisson_pkgdown)
59 changes: 59 additions & 0 deletions R/use-poisson-pkgdown.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#' Set up poissontemplate usage
#'
#' This function
#' * registers poissontemplate usage in the pkgdown config;
#' * explains what the next steps are.
#'
#' @param pkg Path to package
#'
#' @return None
#' @export
#'
use_poisson_pkgdown <- function(pkg = getwd()) {
cat(paste(cli::symbol$info, sprintf("Working in %s\n", pkg)))

current_needs <- desc::desc_get("Config/Needs/website")
needs <- if (!is.na(current_needs)) {
toString(c(as.character(current_needs), "poissonconsulting/poissontemplate"))
} else {
"poissonconsulting/poissontemplate"
}
desc::desc_set("Config/Needs/website" = needs)
cat(paste(cli::symbol$tick, "Registered GHA dependency on poissontemplate.\n"))

config_path <- find_pkgdown_config(pkg)
if (is.null(config_path)) {
meta <- list(
template = list(package = "poissontemplate")
)
yaml::write_yaml(meta, file.path(pkg, "_pkgdown.yml"))
} else {
config <- yaml::read_yaml(config_path)
config$template$package <- "poissontemplate"
config$template$params$bootswatch <- NULL
config$template$includes$before_title <- NULL
if (!is.null(config$template$bootstrap)) {
config$template$bootstrap <- 5
}
yaml::write_yaml(config, file.path(pkg, config_path))
}
cat(paste(cli::symbol$tick, "Registered poissontemplate in pkgdown config.\n"))
cat(paste(cli::symbol$bullet, "Check that the config edits are all harmless.\n"))
cat(paste(cli::symbol$bullet, "Git commit and push to origin.\n"))

# TODO: traffic analytics setup?
}

find_pkgdown_config <- function(pkg) {
possible_paths <- c(
"_pkgdown.yml", "_pkgdown.yaml",
"pkgdown/_pkgdown.yml", "pkgdown/_pkgdown.yaml",
"inst/_pkgdown.yml", "inst/_pkgdown.yaml"
)
for (path in possible_paths) {
if (file.exists(file.path(pkg, path))) {
return(path)
}
}
NULL
}
31 changes: 8 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,6 @@
poissontemplate provides a custom [pkgdown](https://pkgdown.r-lib.org/) template for Poisson consulting packages.
Please don’t use it for your own package.

## Setup

### Register the use of the template

In `_pkgdown.yml` that you can create through `usethis::use_pkgdown()` if absent,
have these lines:

```yaml
template:
package: poissontemplate
```
### For continuous integration
For all sites, ensure that DESCRIPTION contains:
```yaml
Config/Needs/website: poissonconsulting/poissontemplate
```
by editing the file manually or by running `desc::desc_set("Config/Needs/website", "poissonconsulting/poissontemplate")`.


## Installation

You can install the development version of poissontemplate from [GitHub](https://github.com/) with:
Expand All @@ -40,6 +17,14 @@ You can install the development version of poissontemplate from [GitHub](https:/
pak::pak("poissonconsulting/poissontemplate")
```

## Setup

In every package where you need to set up poissontemplate usage, run

``` r
poissontemplate::use_poisson_pkgdown()
```

## Relevant resources

- pkgdown documentation about theming: https://pkgdown.r-lib.org/articles/customise.html#theming
Expand Down
21 changes: 21 additions & 0 deletions man/use_poisson_pkgdown.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7f30004

Please sign in to comment.