bookdown icon indicating copy to clipboard operation
bookdown copied to clipboard

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

Open corinabioinformatic opened this issue 1 year ago • 11 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!

corinabioinformatic avatar Jun 30 '23 13:06 corinabioinformatic

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 ?

cderv avatar Jun 30 '23 14:06 cderv

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

corinabioinformatic avatar Jun 30 '23 15:06 corinabioinformatic

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.

cderv avatar Jun 30 '23 16:06 cderv

Hello,

Same problem here but with the links to a devops repo

  • the url for the project must be something like : https://dev.azure.com/company_name/project_name/_git/repo_name
  • for a file (index.Rmd for example) : https://dev.azure.com/company_name/project_name/_git/repo_name?path=/index.Rmd (the url doesn't change on edit mode)

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:

  • https://dev.azure.com/company_name/project_name/_git/repo_name/blob/master/index.Rmd
  • https://dev.azure.com/company_name/project_name/_git/repo_name/edit/master/index.Rmd

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

ElenaMetori avatar Nov 22 '23 09:11 ElenaMetori

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]])

ElenaMetori avatar Nov 22 '23 11:11 ElenaMetori

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

  • https://github.com/rstudio/bookdown/issues/1011

cderv avatar Nov 22 '23 11:11 cderv

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

ElenaMetori avatar Nov 22 '23 13:11 ElenaMetori

Unfortunately know, you found the place where this is built https://github.com/rstudio/bookdown/blob/cedaac98f2d4b54a97865e5b050a38fb8938cc7f/R/bs4_book.R#L416-L427

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 !

cderv avatar Nov 22 '23 13:11 cderv

#1447

ElenaMetori avatar Nov 23 '23 15:11 ElenaMetori

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 ?

ElenaMetori avatar Nov 23 '23 15:11 ElenaMetori

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.

cderv avatar Nov 23 '23 15:11 cderv