webmen v1.0.2
webmen
A small module to send WebMentions. Should work in both Node and the browser, although you might want to include polyfills for Array.from
, Promise
and fetch
for the latter.
This project also includes TypeScript type definitions.
Installation
npm install webmen --save
Usage
import { webmention } from 'webmen';
webmention('https://webmention.rocks/test/1', 'http://poop.bike')
.then((success) => console.log('Did the target accept the WebMention?', success))
.catch((error) => console.error('Something went wrong sending a WebMention:', error););
API
webmention(target: string, source: string): Promise<boolean>
Notify target
that source
links to it. You will usually use this method.
This should be called when the link to target
is added, and again every time source
is updated, or if/when it eventually is deleted.
Parameter: target
The web page that is mentioned by source
. webmen will attempt to find a reference to the WebMention endpoint there, to which the actual WebMention will be sent.
Parameter: source
The web page that mentions target
; it should actually include a link to target
to be a valid WebMention, or have included one at some point of time in the past.
Returns
A Promise that is either rejected, e.g. when the network is down, or resolved with either true
(target
accepted the WebMention) or false
(e.g. target
does not support WebMentions).
discover(target: string): Promise<string | null>
Given a target
that is linked to, finds that page's associated WebMention endpoint, if any.
Parameter: target
The web page that is mentioned. If the page supports WebMentions, it will include a reference to an endpoint (e.g. <link rel="webmention" href="https://endpoint.example">
) that a WebMention should be sent to.
Returns
A Promise that is either rejected, e.g. when the network is down, or resolved. If it is resolved, it will either return the endpoint referred to in the target page, or null
if it did not refer to an endpoint.
send(endpoint: string, source: string, target: string): Promise<Response>
Given an endpoint, send it a WebMention.
Parameter: endpoint
An endpoint that is set up to receive WebMentions for a given target
.
Parameter: source
The page that links to target
.
Parameter: target
A page whose WebMention endpoint is endpoint
, and which is linked to from source
.
Changelog
See CHANGELOG.md
.
License
MIT © Vincent Tunru
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago