Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
corinabioinformatic opened this issue Jun 30, 2023 · 11 comments
Labels

Comments

@corinabioinformatic
Copy link

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
Copy link
Collaborator

cderv commented Jun 30, 2023

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
Copy link
Author

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
Copy link
Collaborator

cderv commented Jun 30, 2023

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
Copy link

ElenaMetori commented Nov 22, 2023

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
Copy link

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
Copy link
Collaborator

cderv commented Nov 22, 2023

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
Copy link

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

@cderv
Copy link
Collaborator

cderv commented Nov 22, 2023

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 !

@cderv cderv added the help wanted ❤️ we'd love your help! label Nov 22, 2023
@ElenaMetori
Copy link

#1447

@ElenaMetori
Copy link

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
Copy link
Collaborator

cderv commented Nov 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants