This page shows how to add Edit in Zed buttons to your remote site.
Clicking any button below will open the file in Zed on your local workstation
(as long as zed-bridge is running).
The simplest approach. Opens a small pop-up tab that closes itself after 1.8s.
<a class="edit-btn"
href="http://localhost:7654/open?repo=mysite&file=content/posts/hello-world.md"
target="_blank"
rel="noopener">
Edit in Zed
</a>
Opens a small 400Γ160 browser pop-up that closes itself automatically. Doesn't leave a stray tab in your tab bar.
<script>
function editInZed(repo, file) {
const url = 'http://localhost:7654/open'
+ '?repo=' + encodeURIComponent(repo)
+ '&file=' + encodeURIComponent(file);
window.open(url, 'zed-bridge',
'width=420,height=160,menubar=no,toolbar=no,location=no,status=no');
}
</script>
<button onclick="editInZed('mysite', 'content/posts/hello-world.md')">
Edit in Zed
</button>
A realistic file list, like you might generate from a Hugo template or a server-side script. Each row has an edit button.
| File | Path | Action |
|---|---|---|
| Hello World | content/posts/hello-world.md |
|
| Solar Setup Guide | content/posts/solar-setup.md |
|
| LoRa Node Config | content/docs/lora-node.md |
Drop this into any Hugo list or single template. Requires {{ .File.Path }}.
{{`{{ if .File }}`}}
<button class="edit-btn"
onclick="editInZed('mysite', '{{`{{ .File.Path }}`}}');">
βοΈ Edit in Zed
</button>
{{`{{ end }}`}}
Add the editInZed() function once in your base layout's <head> or footer:
<script>
function editInZed(repo, file) {
var url = 'http://localhost:7654/open'
+ '?repo=' + encodeURIComponent(repo)
+ '&file=' + encodeURIComponent(file);
window.open(url, 'zed-bridge',
'width=420,height=160,menubar=no,toolbar=no,location=no');
}
</script>
Tip: Wrap the button in an environment check so it only appears in development or when accessed from your own IP:
{{`{{ if eq (getenv "HUGO_ENV") "development" }}`}}
<!-- edit button here -->
{{`{{ end }}`}}