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

Add copy code button #963

Merged
merged 9 commits into from
Sep 20, 2024
Merged

Add copy code button #963

merged 9 commits into from
Sep 20, 2024

Conversation

BernatBC
Copy link
Contributor

Issue

Description

Adds a copy code button in all code blocks. To enable this feature, you'll need to add the following lines into config.yaml/hugo.yaml:

params:
  features:
    # Enables copy code button
    copyCodeButton:
      enable: true

I will add this into hugo-toha/hugo-toha.github.io and hugo-toha/guides

Test Evidence

Screenshot_20240831_112156

Copy link

netlify bot commented Aug 31, 2024

Deploy Preview for toha-ci ready!

Name Link
🔨 Latest commit f786f8a
🔍 Latest deploy log https://app.netlify.com/sites/toha-ci/deploys/66eccfac65575f0008416ae1
😎 Deploy Preview https://deploy-preview-963--toha-ci.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hossainemruz
Copy link
Member

Hi @BernatBC! I will review on the weekend. Giving a quick look on the deploy preview, I noticed these:

  1. The copy button looks large. We have to reduce its size little bit.
  2. Need to adjust margin/padding so that the copy icon is at the same level as the first line.
  3. It does not have any feedback on hover.
  4. It does not have any feedback when clicked.

You can follow the GitHub style. Also, we need to think about where to put the configuration. It will be better to unify all markdown related configurations under a single section.

@BernatBC BernatBC marked this pull request as draft September 2, 2024 14:15
@BernatBC BernatBC marked this pull request as ready for review September 6, 2024 17:02
@BernatBC
Copy link
Contributor Author

BernatBC commented Sep 6, 2024

Hi @hossainemruz,
I've made some tweaks to it. Regarding your points:

  1. I've reduced a little bit the icon size.
  2. I've readjusted a little bit the margin, so now it's aligned properly.
  3. When on hover, the icon has the same behavior as any other link. I have also added a mouse tooltip. Should we translate the string "copy"?
  4. I've been thinking about it, and I'm not sure what's the best feedback to give after pressing the button. Maybe a little text "Copied!"? If that's the case, will we have to add it to localization as well?

@hossainemruz
Copy link
Member

Hi @hossainemruz, I've made some tweaks to it. Regarding your points:

  1. I've reduced a little bit the icon size.
  2. I've readjusted a little bit the margin, so now it's aligned properly.
  3. When on hover, the icon has the same behavior as any other link. I have also added a mouse tooltip. Should we translate the string "copy"?
  4. I've been thinking about it, and I'm not sure what's the best feedback to give after pressing the button. Maybe a little text "Copied!"? If that's the case, will we have to add it to localization as well?

Awesome. Thank you. I will take a look soon.

@hossainemruz
Copy link
Member

@BernatBC I have updated the button look and also added some feedback on click. Let me know how does it feel now.

Normal State:
image

Hover State:
image

On Click:
image

@BernatBC
Copy link
Contributor Author

BernatBC commented Sep 7, 2024

Hi @hossainemruz,
it looks great!
Thank you once again

@hossainemruz
Copy link
Member

@BernatBC I was wondering if we should combine these kind of feature configurations under common section? That will make them easily discover-able. For example:

params:
  features:
    utility: # not sure what should be the name. feel free to suggest
      copyCodeButton:
         enable: true # add a button to copy code on a code blocks. default "true"
      readingTime:
         enable: true # show estimated reading time on reading page. default: "true"

Maybe few other settings can go there too.

@BernatBC
Copy link
Contributor Author

BernatBC commented Sep 9, 2024

Looks good to me, but will need to be careful with this change, as it will introduce breaking changes for "readingTime"

@hossainemruz
Copy link
Member

Looks good to me, but will need to be careful with this change, as it will introduce breaking changes for "readingTime"

Keeping as it is now. If we want to group them under utility section, the configuration will be:

params:
  features:
    utility:
      enabled: true
      services:
        copyCodeButton:
          enable: true # add a button to copy code on a code blocks. default "true"
        readingTime:
          enable: true # show estimated reading time on reading page. default: "true"

The utility functions does not have anything in common. So, it does not make sense to put them under same service.

Signed-off-by: hossainemruz <[email protected]>
@hossainemruz hossainemruz enabled auto-merge (squash) September 20, 2024 01:28
@hossainemruz hossainemruz merged commit 0d4d8a8 into hugo-toha:main Sep 20, 2024
11 of 13 checks passed
@rageSpin
Copy link

Thanks 💯

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

Successfully merging this pull request may close these issues.

Feature Request - Add Copy Button to Code Blocks
3 participants