Skip to content

Commit 5511812

Browse files
committed
JSON templating
1 parent 547b09a commit 5511812

File tree

5 files changed

+154
-88
lines changed

5 files changed

+154
-88
lines changed

docs/publish.md

+87-15
Large diffs are not rendered by default.

docs/releases.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release
13421342

13431343
**Features:**
13441344

1345-
* You can now include a message and/or title template that will be filled with values from a JSON body, great for services that let you specify a webhook URL but do not let you change the webhook body (such as Grafana). ([#724](https://github.com/binwiederhier/ntfy/issues/724), thanks to [@wunter8](https://github.com/wunter8) for implementing)
1345+
* [Message templating](publish.md#message-templating): You can now include a message and/or title template that will be filled with values from a JSON body (e.g. `curl -gd '{"alert":"Disk space low"}' "ntfy.sh/mytopic?tpl=1&m={{.alert}}"`), which is great for services that let you specify a webhook URL but do not let you change the webhook body (such as GitHub, or Grafana). ([#724](https://github.com/binwiederhier/ntfy/issues/724), thanks to [@wunter8](https://github.com/wunter8) for implementing)
13461346

13471347
### ntfy Android app v1.16.1 (UNRELEASED)
13481348

docs/static/js/extra.js

+66-62
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,103 @@
11
// Link tabs, as per https://facelessuser.github.io/pymdown-extensions/extensions/tabbed/#linked-tabs
22

3-
const savedCodeTab = localStorage.getItem('savedTab')
4-
const codeTabs = document.querySelectorAll(".tabbed-set > input")
3+
const savedCodeTab = localStorage.getItem("savedTab");
4+
const codeTabs = document.querySelectorAll(".tabbed-set > input");
55
for (const tab of codeTabs) {
6-
tab.addEventListener("click", () => {
7-
const current = document.querySelector(`label[for=${tab.id}]`)
8-
const pos = current.getBoundingClientRect().top
9-
const labelContent = current.innerHTML
10-
const labels = document.querySelectorAll('.tabbed-set > label, .tabbed-alternate > .tabbed-labels > label')
11-
for (const label of labels) {
12-
if (label.innerHTML === labelContent) {
13-
document.querySelector(`input[id=${label.getAttribute('for')}]`).checked = true
14-
}
15-
}
16-
17-
// Preserve scroll position
18-
const delta = (current.getBoundingClientRect().top) - pos
19-
window.scrollBy(0, delta)
6+
tab.addEventListener("click", () => {
7+
const current = document.querySelector(`label[for=${tab.id}]`);
8+
const pos = current.getBoundingClientRect().top;
9+
const labelContent = current.innerHTML;
10+
const labels = document.querySelectorAll(".tabbed-set > label, .tabbed-alternate > .tabbed-labels > label");
11+
for (const label of labels) {
12+
if (label.innerHTML === labelContent) {
13+
document.querySelector(`input[id=${label.getAttribute("for")}]`).checked = true;
14+
}
15+
}
16+
17+
// Preserve scroll position
18+
const delta = (current.getBoundingClientRect().top) - pos;
19+
window.scrollBy(0, delta);
2020

21-
// Save
22-
localStorage.setItem('savedTab', labelContent)
23-
})
21+
// Save
22+
localStorage.setItem("savedTab", labelContent);
23+
});
2424

25-
// Select saved tab
26-
const current = document.querySelector(`label[for=${tab.id}]`)
27-
const labelContent = current.innerHTML
28-
if (savedCodeTab === labelContent) {
29-
tab.checked = true
30-
}
25+
// Select saved tab
26+
const current = document.querySelector(`label[for=${tab.id}]`);
27+
const labelContent = current.innerHTML;
28+
if (savedCodeTab === labelContent) {
29+
tab.checked = true;
30+
}
3131
}
3232

3333
// Lightbox for screenshot
3434

35-
const lightbox = document.createElement('div');
36-
lightbox.classList.add('lightbox');
35+
const lightbox = document.createElement("div");
36+
lightbox.classList.add("lightbox");
3737
document.body.appendChild(lightbox);
3838

3939
const showScreenshotOverlay = (e, el, group, index) => {
40-
lightbox.classList.add('show');
41-
document.addEventListener('keydown', nextScreenshotKeyboardListener);
42-
return showScreenshot(e, group, index);
40+
lightbox.classList.add("show");
41+
document.addEventListener("keydown", nextScreenshotKeyboardListener);
42+
return showScreenshot(e, group, index);
4343
};
4444

4545
const showScreenshot = (e, group, index) => {
46-
const actualIndex = resolveScreenshotIndex(group, index);
47-
lightbox.innerHTML = '<div class="close-lightbox"></div>' + screenshots[group][actualIndex].innerHTML;
48-
lightbox.querySelector('img').onclick = (e) => { return showScreenshot(e, group, actualIndex+1); };
49-
currentScreenshotGroup = group;
50-
currentScreenshotIndex = actualIndex;
51-
e.stopPropagation();
52-
return false;
46+
const actualIndex = resolveScreenshotIndex(group, index);
47+
lightbox.innerHTML = "<div class=\"close-lightbox\"></div>" + screenshots[group][actualIndex].innerHTML;
48+
lightbox.querySelector("img").onclick = (e) => {
49+
return showScreenshot(e, group, actualIndex + 1);
50+
};
51+
currentScreenshotGroup = group;
52+
currentScreenshotIndex = actualIndex;
53+
e.stopPropagation();
54+
return false;
5355
};
5456

5557
const nextScreenshot = (e) => {
56-
return showScreenshot(e, currentScreenshotGroup, currentScreenshotIndex+1);
58+
return showScreenshot(e, currentScreenshotGroup, currentScreenshotIndex + 1);
5759
};
5860

5961
const previousScreenshot = (e) => {
60-
return showScreenshot(e, currentScreenshotGroup, currentScreenshotIndex-1);
62+
return showScreenshot(e, currentScreenshotGroup, currentScreenshotIndex - 1);
6163
};
6264

6365
const resolveScreenshotIndex = (group, index) => {
64-
if (index < 0) {
65-
return screenshots[group].length - 1;
66-
} else if (index > screenshots[group].length - 1) {
67-
return 0;
68-
}
69-
return index;
66+
if (index < 0) {
67+
return screenshots[group].length - 1;
68+
} else if (index > screenshots[group].length - 1) {
69+
return 0;
70+
}
71+
return index;
7072
};
7173

7274
const hideScreenshotOverlay = (e) => {
73-
lightbox.classList.remove('show');
74-
document.removeEventListener('keydown', nextScreenshotKeyboardListener);
75+
lightbox.classList.remove("show");
76+
document.removeEventListener("keydown", nextScreenshotKeyboardListener);
7577
};
7678

7779
const nextScreenshotKeyboardListener = (e) => {
78-
switch (e.keyCode) {
79-
case 37:
80-
previousScreenshot(e);
81-
break;
82-
case 39:
83-
nextScreenshot(e);
84-
break;
85-
}
80+
switch (e.keyCode) {
81+
case 37:
82+
previousScreenshot(e);
83+
break;
84+
case 39:
85+
nextScreenshot(e);
86+
break;
87+
}
8688
};
8789

88-
let currentScreenshotGroup = '';
90+
let currentScreenshotGroup = "";
8991
let currentScreenshotIndex = 0;
9092
let screenshots = {};
91-
Array.from(document.getElementsByClassName('screenshots')).forEach((sg) => {
92-
const group = sg.id;
93-
screenshots[group] = [...sg.querySelectorAll('a')];
94-
screenshots[group].forEach((el, index) => {
95-
el.onclick = (e) => { return showScreenshotOverlay(e, el, group, index); };
96-
});
93+
Array.from(document.getElementsByClassName("screenshots")).forEach((sg) => {
94+
const group = sg.id;
95+
screenshots[group] = [...sg.querySelectorAll("a")];
96+
screenshots[group].forEach((el, index) => {
97+
el.onclick = (e) => {
98+
return showScreenshotOverlay(e, el, group, index);
99+
};
100+
});
97101
});
98102

99103
lightbox.onclick = hideScreenshotOverlay;

go.mod

-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ require (
3535
github.com/microcosm-cc/bluemonday v1.0.26
3636
github.com/prometheus/client_golang v1.19.0
3737
github.com/stripe/stripe-go/v74 v74.30.0
38-
github.com/tidwall/gjson v1.17.1
3938
)
4039

4140
require (
@@ -70,8 +69,6 @@ require (
7069
github.com/prometheus/procfs v0.13.0 // indirect
7170
github.com/russross/blackfriday/v2 v2.1.0 // indirect
7271
github.com/stretchr/objx v0.5.0 // indirect
73-
github.com/tidwall/match v1.1.1 // indirect
74-
github.com/tidwall/pretty v1.2.1 // indirect
7572
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
7673
go.opencensus.io v0.24.0 // indirect
7774
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect

go.sum

-7
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
143143
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
144144
github.com/stripe/stripe-go/v74 v74.30.0 h1:0Kf0KkeFnY7iRhOwvTerX0Ia1BRw+eV1CVJ51mGYAUY=
145145
github.com/stripe/stripe-go/v74 v74.30.0/go.mod h1:f9L6LvaXa35ja7eyvP6GQswoaIPaBRvGAimAO+udbBw=
146-
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
147-
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
148-
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
149-
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
150-
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
151-
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
152-
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
153146
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
154147
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
155148
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=

0 commit comments

Comments
 (0)