Skip to content

Commit 4d7f297

Browse files
committed
✨ Feat: add open-heart function.
1 parent 8c92cde commit 4d7f297

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
open-heart {
2+
border: 1px solid var(--pink);
3+
border-radius: 4px;
4+
padding: 4px 8px;
5+
}
6+
7+
open-heart:not([disabled]):hover,
8+
open-heart:not([disabled]):focus {
9+
border-color: var(--red);
10+
cursor: pointer;
11+
transition: all 0.2s cubic-bezier(.4, 0, .2, 1);
12+
}
13+
14+
open-heart[disabled] {
15+
cursor: not-allowed;
16+
background: var(--pink);
17+
color: var(--entry);
18+
}
19+
20+
open-heart[count]:not([count="0"])::after {
21+
content: attr(count);
22+
padding-left: 3px;
23+
}

themes/PaperMod/layouts/_default/single.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ <h1 class="post-title entry-hint-parent">
5353
<li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
5454
{{- end }}
5555
</ul>
56+
{{- partial "reaction.html" . }}
5657
{{- if (.Param "ShowPostNavLinks") }}
5758
{{- partial "post_nav_links.html" . }}
5859
{{- end }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- /* Reaction area start */ -}}
2+
<div class="post-reactions">
3+
<open-heart href="https://open-heart-worker.zhuzi.workers.dev/?id={{ .Permalink }}" emoji="❤️">❤️</open-heart>
4+
</div>
5+
<script src="https://unpkg.com/open-heart-element" type="module"></script>
6+
<script>
7+
window.customElements.whenDefined('open-heart').then(() => {
8+
for (const oh of document.querySelectorAll('open-heart')) {
9+
oh.getCount()
10+
}
11+
})
12+
// refresh component after click
13+
window.addEventListener('open-heart', e => {
14+
e && e.target && e.target.getCount && e.target.getCount()
15+
})
16+
</script>
17+
{{- /* React area end */ -}}

0 commit comments

Comments
 (0)