rstudio / bookdown

Authoring Books and Technical Documents with R Markdown
https://pkgs.rstudio.com/bookdown/
GNU General Public License v3.0
3.79k stars 1.27k forks source link

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

Open corinabioinformatic opened 1 year ago

corinabioinformatic commented 1 year ago
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!

cderv commented 1 year ago

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 ?

corinabioinformatic commented 1 year ago

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

cderv commented 1 year ago

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.

ElenaMetori commented 12 months ago

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 ?

ElenaMetori commented 12 months ago

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]])
cderv commented 12 months ago

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

ElenaMetori commented 12 months ago

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

cderv commented 12 months ago

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 !

ElenaMetori commented 12 months ago

1447

ElenaMetori commented 12 months ago

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 ?

cderv commented 12 months ago

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.