jlelse
/
Indiego
Archived
1
Fork 0

Integrate Webmentiond

This commit is contained in:
Jan-Lukas Else 2020-07-22 19:46:15 +02:00
parent 8c9fff73fa
commit 30e253199a
2 changed files with 21 additions and 9 deletions

View File

@ -0,0 +1,17 @@
async function displayWebmentions() {
let endpoint = '{{ .Param "indieweb.endpoints.webmentiond" }}';
let target = window.location.href;
let resp = await fetch(`${endpoint}get?target=${target}`);
let data = await resp.json();
let mentionsListView = document.querySelector('#mentionslist');
let list = document.createElement('ul');
data.forEach(mention => {
let listItem = document.createElement('li');
listItem.innerHTML = `<a href="${mention.source}" target="_blank" rel="nofollow noopener noreferrer">${mention.author_name ? mention.author_name : mention.source}</a>${mention.title ? ` <i>${mention.title}</i>` : ''}`;
list.appendChild(listItem);
});
mentionsListView.innerHTML = ``;
mentionsListView.appendChild(list);
}
displayWebmentions();

View File

@ -1,17 +1,12 @@
{{ if .Param "indieweb.enabled" }}
{{ if not (.Param "indieweb.hidewmform") }}
{{ if .Param "indieweb.endpoints.webmention" }}
{{ $md5pl := md5 (replace .Permalink "/" "") }}
{{ $mentions := index .Site.Data.mentions $md5pl }}
{{ $dateFormat := ( .Site.Params.dateformat | default "January 02, 2006") }}
<details class="p" id="interactions">
<summary><b>{{ T "interactions" }}</b></summary>
{{ with $mentions }}
<ul>
{{ range sort . ".date" "asc" }}{{ $sourceUrl := urls.Parse .source }}
<li><a href="{{ .source }}" target="_blank" rel="nofollow noopener noreferrer">{{ $sourceUrl.Host }}</a> <i>{{ dateFormat $dateFormat .date }}</i></li>
{{ end }}
</ul>
{{ if .Param "indieweb.endpoints.webmentiond" }}
<div id="mentionslist"></div>
{{ $wmScript := resources.Get "js/webmentions.template.js" | resources.ExecuteAsTemplate "js/webmentions.js" . | minify | fingerprint }}
<script defer src="{{ $wmScript.RelPermalink }}" integrity="{{ $wmScript.Data.Integrity }}"></script>
{{ end }}
<form method="post" action="{{ .Param "indieweb.endpoints.webmention" }}">
<label for="wm-source" class="p">{{ T "wmform_label" }}</label>