Adapters API
@diazoma/adapters has feed adapters for the wall. Each one implements FeedAdapter and only fetches and parses. It never
renders, and the cursors it returns are opaque strings.
| Adapter | Reads | Cursor |
|---|---|---|
JsonFeedAdapter({ url, search?, filters?, fetch? }) | a feed of the spec: { items, next } | the server’s next, verbatim |
WellKnownAdapter({ origin }) | /.well-known/wall.json (or <link rel="wall-manifest">). Builds a JsonFeedAdapter per feed and exposes brand, policy, filters and actions | base64url(JSON { f: feed id, c: server cursor }) |
DomAdapter({ root?, mode? }) | the page itself: [data-wall-item], then JSON-LD, then clusters of similar siblings | base64url(JSON { u: next url }), or { p: n } for infinite scroll |
RssAdapter({ url }) | RSS 2.0 and Atom | none, unless the feed has <atom:link rel="next"> |
RecipeAdapter({ recipe }) | a recipe from @diazoma/recipe-schema: a JSON API (JSONPath, no eval) or the DOM (CSS selectors) | base64url(JSON { page }) or { u } |
import { WellKnownAdapter } from '@diazoma/adapters';
const adapter = await new WellKnownAdapter({ origin: location.origin }).ready();new Wall({ mount, adapter, brand: adapter.brand });WellKnownAdapter.capabilities() is synchronous, so call ready() before you pass the adapter to the wall.
Options worth knowing
Section titled “Options worth knowing”DomAdaptermode:auto(the default),annotated,jsonldorheuristic.autotries them in that order and stops at the first that finds items.JsonFeedAdapterfilterstake{ key, values, param? }.paramis the query parameter, and defaults tokey.RssAdaptersizesis a function from an absolute image URL to smaller copies. See Image sizes.- Every adapter takes
fetch(to replace the global one) andonWarning(to hear about dropped items). RecipeAdaptersourceforcesapiordom.
Invalid items are dropped and reported through onWarning. A manifest with "policy": "deny" makes page() reject with an
AdapterError whose code is policy-denied.
The site’s view
Section titled “The site’s view”Every adapter that reads a site description also passes on the site’s view: WellKnownAdapter from
manifest.view, RecipeAdapter from recipe.view, and DomAdapter from the first
<script type="application/json" data-wall-view> on the page. A panorama that is not an absolute http(s) URL is dropped.
WellKnownAdapter also sets login (from auth.login) and capabilities().links: the actions with mode: "deeplink".
Smaller images
Section titled “Smaller images”Every adapter looks for smaller images when an item brings only image. See Image sizes.
Node entry: @diazoma/adapters/node
Section titled “Node entry: @diazoma/adapters/node”Adapters use the global DOMParser. In a browser that is built in. In Node, call installDom() from
@diazoma/adapters/node first. It installs linkedom’s.
runFixtures(recipe, dir) replays each fixture of a recipe through RecipeAdapter with a fixture-backed fetch, and checks
at least one item with id, link, image and aspect. The diazoma-recipe run <recipe.json> command does the same from a
shell and exits 1 on a failure. See Recipes.
Browser bundle
Section titled “Browser bundle”dist/adapters.iife.js exposes window.DiazomaAdapters for pages without a bundler.