rstudio / bookdown

Authoring Books and Technical Documents with R Markdown

Home Page:https://pkgs.rstudio.com/bookdown/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How could I add a link for the "Edit" icon to private Bitbucket repo?

corinabioinformatic opened this issue · comments

topButtonEdit_bookdown

Hello, related to Bookdown I am editing the "index.Rmd" and "_output.yaml" file in order to make functional the "Edit" button.
I followed the instructions detailed in this page: 29.4 Edits and source code

But when render my book and I click on that "Edit icon" I get again the error page in Bitbucket.
error404_bitbucket

I have a private bitbucket and I added the following lines of code in the :
"_output.yml"

bookdown::gitbook:
  css: style.css
  config:
    toc:
      collapse: section
      before: |
        <li><a href="./">Demo Book</a></li>
      after: |
        <li><a href="https://bitbucket.whatever.com/projects/my_repo_name/my_bookdown" target="blank">Published with bookdown</a></li>
    edit:
      link: bitbucket.whatever.com/my_username/my_repo_name/edit/master/%s
      text: "Suggest an edit"

    download: ["pdf", "epub"]

"index.Rmd"

title: "bookdown"
author:"authors"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography:
- book.bib
- packages.bib
description: 
  Thats it
link-citations: yes
always_allow_html: yes
github-repo: my_bitb_username/my_repo_name

Does anybody know if Bookdown can have a Edit button to edit in a private Bitbucket repo? (or suggest edits?)
Many thanks!

But when render my book and I click on that "Edit icon" I get again the error page in Bitbucket.

What is the link supposed to be for bitbucket source file edition ?

What would be the correct link to generate ?

The link for bitbucket source file edition is something like this:
"https://bitbucket.whatever.com/projects/my_repo_name/repos/my_bookdown/browse/my_Rmd.Rmd"
and it appears the Rmd file window with thebutton option to "Edit" in bitbucket. and when you click on it, the address do not change, but the window enable to edit the content on the Rmd and below there is a new button that let you "commit" changes.

I searched online about this issue but I did not found a solution yet. Here my Stackoverflow question: https://stackoverflow.com/questions/76590504/how-could-i-add-a-link-for-the-edit-icon-to-private-bitbucket-repo

What you described above does not match what you put in your configuration

edit:
      link: bitbucket.whatever.com/my_username/my_repo_name/edit/master/%s

I believe Bitbucket is adding some parameters to URL so you could try putting the same url you have in your browser and adds ?mode=edit&at=main at the end.

The URL I got on bitbucket.org is not exactly the same as yours though

https://bitbucket.org/dervieuxchr/bookdown-demo/src/main/README.md

when I clicked it adds mode=edit&at=main

So you need to adapt and put the right url in edit config, leaving %s where the filename should go.

Hello,

Same problem here but with the links to a devops repo

I've modified the links in the "_output.yml" :

bookdown::bs4_book:
  css: css/style.css
  theme:
    primary: "#096B72"
  repo: https://dev.azure.com/company_name/project_name/_git/repo_name
  edit: https://dev.azure.com/company_name/project_name/_git/repo_name&path=/%s

But the links on the built book are modified as:

And another question : how to open the link on a new tab ?

I think the problem comes from the function tweak_navbar() in bs4_book.R :

repo_edit <- paste0(repo$base, "/edit/", repo$branch, "/", repo$subdir, rmd_index[[active]])
repo_view <- paste0(repo$base, "/blob/", repo$branch, "/", repo$subdir, rmd_index[[active]])

yes bs4_book() does not support the url you want to put. If should be extended in configuration to allow that.

This is probably part of

Any way to workaround other than make a local modified version of bookdown ?

Unfortunately know, you found the place where this is built

bookdown/R/bs4_book.R

Lines 416 to 427 in cedaac9

# Source links ------------------------------------------------------------
if (!is.null(repo) && active %in% names(rmd_index)) {
if (!is.null(repo$subdir)) {
repo$subdir <- paste0(repo$subdir, "/")
}
repo_edit <- paste0(repo$base, "/edit/", repo$branch, "/", repo$subdir, rmd_index[[active]])
repo_view <- paste0(repo$base, "/blob/", repo$branch, "/", repo$subdir, rmd_index[[active]])
} else {
repo_edit <- NULL
repo_view <- NULL
}

Currently it will add the file in the path, and not as a query params like your dev azure expect.

A PR is welcome to improve support. Thanks !

I also modified the template_link() function in order to open the link into a new tab, but I'm not sure that you want a new PR with that too ?

I also modified the template_link() function in order to open the link into a new tab, but I'm not sure that you want a new PR with that too ?

Yes you can make a PR for this too.