Browse Source

Integrate Webmentiond

master
Jan-Lukas Else 6 months ago
parent
commit
30e253199a
2 changed files with 21 additions and 9 deletions
  1. +17
    -0
      assets/js/webmentions.template.js
  2. +4
    -9
      layouts/partials/mentions.html

+ 17
- 0
assets/js/webmentions.template.js 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();

+ 4
- 9
layouts/partials/mentions.html 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>


Loading…
Cancel
Save