Skip to content

[FR] Managing redirect #1071

Open
Open
@ColinFay

Description

@ColinFay

Context

I've started a book a couple of months ago, with a series of Rmd, let's say named chapter-lorem.Rmd, chapter-ipsum.Rmd.

This had generated a book, hosted on GitHub pages, at myuberbook.org/chapter-lorem.hml and myuberbook.org/chapter-ipsum.html.

My book has been read and shared on the internet, and potentially people have been sharing links to myuberbook.org/chapter-lorem.hml, but now I want to rename it to be myuberbook.org/lorem.hml.

Feature Request

It would be nice to have a native mechanism to do these redirects, in other words having a way to change the chapter URLs, while still keeping the old URL active with a redirect.

A native redirect would allow to:

  • Keep old bookmarks and links "alive", i.e they are still usable
  • Be better for SEO (google prefers finding a redirect than a dead link)

My current approach is to, after the book compilation, write a series of HTML files with in it :

<head>
  <meta http-equiv="refresh" content="0; URL=lorem.hml" />
</head>

using

make_redirect <- function(from, to){
  html <- sprintf(
    '<head><meta http-equiv="refresh" content="0; URL=%s.html" /></head>', 
    to
  )
  dest <- fs::path("_book", from, ext = "html")
  fs::file_create(dest)
  write(html, dest)
}
make_redirect("chapter-lorem", "lorem")

--

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('bookdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/bookdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementnextto consider for next release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions