Microformat objects are a set of utility classes for working with indieweb posts.
- Read different kinds of posts:
- notes
- articles
- replies
- likes
- reposts
- Parse comments and reply contexts as nested objects
- Resolve author with the authorship algorithm
- Get a list of webmention targets
- Serialize and deserialize from JSON
Microformat objects makes use of ES6 features and requires Node >= 4.0.0.
npm install mf-obj --save
mfo.getEntry('http://somesite/2016/5/1/1')
.then(entry => {
if (entry.isReply() {
console.log('I\'m a reply to "' + entry.replyTo.name + '"');
}
});
- name
- published
- content
- summary
- url
- author
- category
- syndication
- syndicateTo
- photo
- audio
- video
- replyTo
- likeOf
- repostOf
- embed
- getDomain()
- getPath()
- getReferences()
- getMentions()
- getChildren(sortFunc?)
- addChild(entry)
- deleteChild(url)
- isReply()
- isLike()
- isRepost()
- isArticle()
- serialize()
- deserialize(json)
mfo.getEntry(url)
.then(entry => {
//...
});
mfo.getEntry(url, ['entry','event','oembed'])
.then(entry => {
//...
});
Fetches the page at url
and returns a Promise for an Entry. This will perform the authorship algorithm and fetch the author h-card from a separate url if necessary.
The second parameter strategies
is an optional array of strategies to attempt to marshal to an Entry. Strategies are tried in order and if all fail, an exception is thrown. This can be used for displaying comments or reply contexts of URLs that don't contain h-entries. The default value for this parameter is ['entry']
.
entry
- Default h-entry strategy.event
- Marshall an h-event to an Entry. Useful for creating RSVP reply-contexts to an h-event.oembed
- Marshall oembed data to an Entry. Useful for creating reply-contexts or reposts of silo content.opengraph
- Marshall opengraph data to an Entry. Useful for creating reply-contexts or reposts of silo content.html
- Most basic strategy. Marshalls html<title>
to name and<body>
to content.
mfo.getCard(url)
.then(card => {
//...
});
Fetches the page at url and returns a Promise for a Card. This will return null if an h-card could not be found according to the authorship algorithm.
mfo.getEvent(url)
.then(event => {
//...
});
Fetches the page at url and returns a Promise for an Event.
mfo.getFeed(url)
.then(feed => {
//...
});
Fetches the page at url and returns a Promise for a Feed.
Represents an h-entry or h-cite. Properties of this object correspond to output from the mf2 parser, but have been converted from arrays of string to other data types for convenience.
var entry = new mfo.Entry();
var entry2 = new mfo.Entry('http://somesite/2016/5/2/1');
The constructor takes an optional argument to set the url.
string || null
Date || null
{html: string, value: string} || null
string || null
string || null
Card || null
See Card.
string[]
string[]
Parsed from syndicate-to.
string[]
string[]
string[]
string[]
Parsed from in-reply-to.
Entry[] || null
Parsed from like-of.
Entry[] || null
Parsed from repost-of.
Entry[] || null
{html: string, value: string} || null
Experimental property for storing oembed content. Parsed from e-x-embed.
Returns the domain component of the url.
Returns the path component of the url.
Returns an array of urls from the reply-to, like-of, or repost-of properties.
Returns an array of urls found in links in the e-content, in addition to getReferences(). Intended for sending webmentions.
Returns an array of Entries. Use this instead of directly accessing the children property. Takes an optional argument to sort the results.
var unsorted = entry.getChildren();
var sorted = entry.getChildren(mfo.Entry.byDate);
Adds an Entry to the list of children. If there is an existing child with the same url, it will be overwritten.
function receiveWebmention(sourceUrl, targetUrl) {
// ...
var sourceEntry = mfo.getEntryFromUrl(sourceUrl);
targetEntry.addChild(sourceEntry);
// ...
}
Remove an entry from the list of children by url.
function receiveWebmention(sourceUrl, targetUrl) {
// ...
if (got404) {
targetEntry.deleteChild(sourceUrl);
}
// ...
}
Tests if reply-to is non-empty.
Tests if like-of is non-empty.
Tests if repost-of is non-empty.
Tests if name and content.value properties exist and differ, in addition to other heuristics.
Serialize object to JSON. Nested Entry objects in replyTo, likeOf, repostOf, and children are serialized as an url string.
Example output:
{
"name":"Hello World!",
"published":"2015-08-28T08:00:00.000Z",
"content":{
"value":"Hello World!",
"html":"Hello <b>World!</b>"
},
"summary":"Summary",
"url":"http://testsite/2015/8/28/2",
"author":{
"name":"Test User",
"photo":null,
"url":"http://testsite",
"uid":null
},
"category":["indieweb"],
"syndication":[],
"syndicateTo":[],
"photo":[],
"audio":[],
"video":[],
"replyTo":["http://testsite/2015/8/28/2"],
"likeOf":[],
"repostOf":[],
"embed":null,
"children":["http://testsite/2015/8/28/3"]
}
Static method to deserialize json. Nested objects from replyTo, likeOf, repostOf, and children are deserialized as stub Entry objects with only url set.
var entry = mfo.Entry.deserialize(json);
Represents an h-card. Properties of this object correspond to output from the mf2 parser, but have been converted from arrays of string to string for convenience.
var author = new mfo.Card();
var author = new mfo.Card('http://somesite');
The constructor takes an optional argument to set the url.
string || null
string || null
string || null
string || null
Represents an h-event. Properties of this object correspond to output from the mf2 parser, but have been converted from arrays of string to other datatypes for convenience.
var event = new mfo.Event();
var event = new mfo.Event('http://somesite/event');
The constructor takes an optional argument to set the url.
string || null
string || null
Date || null
Date || null
Card || null
Represents an h-feed. Properties of this object correspond to output from the mf2 parser, but have been converted from arrays of string to other datatypes for convenience.
var event = new mfo.Feed();
var event = new mfo.Feed('http://somesite');
The constructor takes an optional argument to set the url.
string || null
string || null
Card || null
See Card.
Parsed from rel="prev" or rel="previous".
string || null
Parsed from rel="next".
string || null
Returns an array of Entries. Use this instead of directly accessing the children property. Takes an optional argument to sort the results.
Adds an Entry to the list of children. If there is an existing child with the same url, it will be overwritten.
Remove an entry from the list of children by url.