R/utils_page.R

Defines functions build_redirect extract check_redirect_code with_class

with_class <- function(res, pop_class) {
  class(res) <- c(
    pop_class,
    class(res)
  )
  res
}

check_redirect_code <- function(code) {
  attempt::stop_if(
    code,
    ~ !.x %in% c(
      301:308,
      310
    ),
    sprintf(
      "Redirect code should be one of %s.",
      paste(
        c(
          301:308,
          310
        ),
        collapse = " "
      )
    )
  )
}

extract <- function(content, class) {
  vapply(
    content,
    function(x) {
      inherits(x, class)
    },
    logical(1)
  )
}

build_redirect <- function(redirect) {
  do.call(
    rbind,
    lapply(
      redirect,
      function(x) {
        data.frame(
          from = x$from,
          to = x$to,
          code = x$code
        )
      }
    )
  )
}
ColinFay/brochure documentation built on March 30, 2022, 5:02 a.m.