Skip to content

feat: copy button on blog pages and getting started pages#487

Merged
stasadev merged 8 commits intomainfrom
20251213_bmartinez_copybutton
Dec 19, 2025
Merged

feat: copy button on blog pages and getting started pages#487
stasadev merged 8 commits intomainfrom
20251213_bmartinez_copybutton

Conversation

@bmartinez287
Copy link
Copy Markdown
Collaborator

@bmartinez287 bmartinez287 commented Dec 13, 2025

The Issue

Adds a copy button for code.

Use Gemini to determine how to integrate it with the getting-started page.

Manual Testing

Review at, for example:

Screenshot 2025-12-13 at 4 34 53 PM

@bmartinez287 bmartinez287 changed the title Copy button on blog pages and getting started page. Copy button on blog pages and getting started pages. Dec 13, 2025
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Dec 13, 2025

Deploying ddev-com-front-end with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0cde7e0
Status: ✅  Deploy successful!
Preview URL: https://c07e114e.ddev-com-front-end.pages.dev
Branch Preview URL: https://20251213-bmartinez-copybutto.ddev-com-front-end.pages.dev

View logs

@bmartinez287
Copy link
Copy Markdown
Collaborator Author

bmartinez287 commented Dec 14, 2025

So this version is different from #121 since it still relies on the shiki plugin directly. The way it works is through a custom transformer plugin that lets that copy button come in.

#121 replaced shiki for the astroExpressiveCode which astro starlight and other popular astro packages use, but that also changes how the terminal looked in a few different places.
#118 also used astroExpressiveCode. An changes on how the terminal looked was the biggest concern.

Copy link
Copy Markdown
Collaborator

@mattstein mattstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice and works fine for me in Safari and Firefox, but three things seem odd:

  1. Each code block is preceded with an unnecessary---. Maybe that’s an untransformed Markdown horizontal rule?
  2. The horizontal padding for the code block’s text and copy button is inconsistent.
  3. It’s a little strange to copy sample terminal output and not the commands you would want to copy and paste. I assume there’s no way to toggle the copy feature for each code block or limit the copyable chunk of text?

Sorry for the deranged-looking arrows but this is what I’m referring to in context:

@bmartinez287
Copy link
Copy Markdown
Collaborator Author

bmartinez287 commented Dec 16, 2025

  1. It was a typo, so that one is easy.
  2. This one is tricky, but I improved it a bit by making the padding even on each side.
  3. Not sure if any copy packages do that. It would be cool, but it would likely be challenging since there are so many things specific to each language.

@mattstein
Copy link
Copy Markdown
Collaborator

Thanks @bmartinez287! I realize the copy area is an annoying thing to deal with, it just seems like a minor barrier to someone getting started.

Do you think it’s possible to match the padding on blog post pages? That looks more optically correct to me (example):

That left padding would ideally match the right side (1), with a little bit of padding at the bottom of the window so a one-line example still gets even spacing to the right and bottom of the copy button (2). (You could probably scoot the copy button up slightly and aim to align the baseline of the code and copy text.) Nitpicky again but it’d feel more balanced and better match the other less-fancy code blocks.

@bmartinez287
Copy link
Copy Markdown
Collaborator Author

yeah. that sounds good.

Copy link
Copy Markdown
Member

@stasadev stasadev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, one small nitpick, can we better support horizontal scrolling? The copy button should always remain in the upper right corner:

https://20251213-bmartinez-copybutto.ddev-com-front-end.pages.dev/blog/legacy-projects-with-unsupported-php-and-mysql-using-ddev/#step-2-rewiredb

scroll

@rfay
Copy link
Copy Markdown
Member

rfay commented Dec 18, 2025

So great that this is going to land, big improvement!

@stasadev
Copy link
Copy Markdown
Member

One more thing: we don't need copy in mobile:

mobile

The button overlaps with the code.

@stasadev stasadev force-pushed the 20251213_bmartinez_copybutton branch from acf93d6 to 14a14be Compare December 19, 2025 14:24
@stasadev
Copy link
Copy Markdown
Member

can we better support horizontal scrolling? The copy button should always remain in the upper right corner

Fixed it:

1

One more thing: we don't need copy in mobile

Fixed it, no copy for any width below 768px:

2

It’s a little strange to copy sample terminal output and not the commands you would want to copy and paste.

I also tried to fix it, but without success. I think we can live with it.

Copy link
Copy Markdown
Member

@stasadev stasadev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@stasadev stasadev changed the title Copy button on blog pages and getting started pages. feat: copy button on blog pages and getting started pages Dec 19, 2025
Comment thread src/components/Terminal.astro Outdated
// Regex to find the symbol at the start of a line (or start of string), globally
const search = new RegExp(`^${searchSymbol} `, "gm")
return code.replaceAll(search, `<span class="prompt">${symbol} </span>`)
return code.replaceAll(search, "")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Losing this visible prompt is unfortunate, but if we have to sacrifice it, that is OK.

I'll make one last attempt to get it back.

@stasadev
Copy link
Copy Markdown
Member

It’s a little strange to copy sample terminal output and not the commands you would want to copy and paste.

All good now, prompt symbol is back, and Claude Code helped me with fixing copy for:

$ ddev -v
ddev version v1.24.10

Now it copies only ddev -v

1

Copy link
Copy Markdown
Member

@stasadev stasadev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, please check again and give a second approval.

Copy link
Copy Markdown
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the result in a blog post and in get-started and they both looked great, but I'm not much of a web expert.

@stasadev stasadev merged commit 3922063 into main Dec 19, 2025
5 checks passed
@stasadev stasadev deleted the 20251213_bmartinez_copybutton branch December 19, 2025 17:19
@rfay
Copy link
Copy Markdown
Member

rfay commented Dec 19, 2025

Thank you for making this happen @bmartinez287 ! Thanks for still paying attention @mattstein !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants