diff --git a/configuration/template.html b/configuration/template.html index 5dbb156..ae2e74e 100644 --- a/configuration/template.html +++ b/configuration/template.html @@ -25,7 +25,7 @@ {body} - + @@ -44,11 +44,18 @@ + diff --git a/weblog/B0. Template/share.js.md b/weblog/B0. Template/share.js.md new file mode 100644 index 0000000..0f39611 --- /dev/null +++ b/weblog/B0. Template/share.js.md @@ -0,0 +1,42 @@ +/*/ +Type: file +Content-Type: application/javascript +Title: Share script +Location: /share.js +/**/ + +const SUBSCRIBE_LINK_REL = 'http://ostatus.org/schema/1.0/subscribe' +function share(uri, handle) { + if(!handle){ + handle = prompt("Please enter your fediverse / mastodon handle (e.g. '@user@domain.social')", "@") + } + + if(handle) { + const input = handle + handle = handle.trim().replace(/^@/,'') + const split = handle.split('@') + if(split.length == 2) { + const resource = `acct:${handle}` + const domain = split[1] + + // look up remote user via webfinger + const url = `https://${domain}/.well-known/webfinger?resource=${resource}` + fetch(url, {headers: { + 'Content-Type': 'application/activity+json' + }}).then(async result => { + const json = await result.json() + const subscribe = json.links.find(link => link.rel && link.rel == SUBSCRIBE_LINK_REL) + let template = subscribe.template + window.open(template.replace("{uri}", uri), '_blank').focus() + }) + .catch(e => { + console.error(e) + throw `Sorry, we couldn't find an uri for ${input}.\n\nTry searching for "${uri}" on ${domain} (or in your fediverse client of choice)` + }) + + } + else { + throw 'Please enter your fediverse address in @user@domain.social format' + } + } +} \ No newline at end of file diff --git a/weblog/B0. Template/template-landing-page.html.md b/weblog/B0. Template/template-landing-page.html.md index cc1cd29..b507a72 100644 --- a/weblog/B0. Template/template-landing-page.html.md +++ b/weblog/B0. Template/template-landing-page.html.md @@ -33,11 +33,18 @@ Title: Landing Page Template + diff --git a/weblog/B0. Template/template-post.html.md b/weblog/B0. Template/template-post.html.md index 8e21d98..e0146a6 100644 --- a/weblog/B0. Template/template-post.html.md +++ b/weblog/B0. Template/template-post.html.md @@ -7,7 +7,7 @@ Title: Post Template {body} - +