Link Search Menu Expand Document (external link)

Indiekit.addSyndicator

A syndicator plug-in syndicates content to a third-party service such as a social network via its API.

Constructor

Property Type Description
id String Kebab-cased plug-in ID. Required.
meta [Function][] import.meta. Required.
name String Human readable plug-in name. Required.
options Object Plug-in options. Optional.

Properties

Property Type Description
info Object Information about the syndicator.

info

Indiekit’s web interface expects a syndicator plug-in to provide some information about the third-party service it supports. In addition, some Micropub clients may also use this information in their publishing interface. This information is provided by the info property:

get info() {
  const { user } = this.options;

  return {
    name: `${user} on Example service`,
    uid: `https://service.example/${user}`,
    checked: true,
    service: {
      name: "Example service",
      url: "https://service.example/",
      photo: "/assets/example-syndicator/icon.svg",
    },
    user: {
      name: user,
      url: `https://social.example/${user}`,
    },
  };
}

The info property returns the following values:

Property Type Description
name String The name of the third-party service the syndicator supports. Required.
uid String URL or path to the syndication target. Required.
checked Boolean Whether this syndicator should be enabled by default in Micropub clients. Optional.
service.name String Name of the third-party service. Optional.
service.url String URL of the third-party service. Optional.
service.photo String Icon, logo or photo used to identify the third-party service in Micropub clients. Optional.
user.name String Name of the user on the third-party service. Optional.
user.url String URL for the user on the third-party service. Optional.

Methods

Method Type Description
syndicate() async function Syndicate a post to a third-party service.

syndicate()

Parameters Type Description
properties Object Path to file. Required.
publication Object Path to file. Required.

Returns the URL for the syndicated content as a String if successful, else returns [IndiekitError][]. For example:

async syndicate(properties, publication) {
  try {
    return await exampleClient.post(properties, publication);
  } catch (error) {
    throw new IndiekitError(error.message, {
      cause: error,
      plugin: this.name,
      status: error.status,
    });
  }
}

Example

import { IndiekitError } from "@indiekit/error";
import exampleClient from 'example-client';

export default class ExampleStore {
  constructor(options) {
    this.id = "example-syndicator";
    this.meta = import.meta;
    this.name = "Example syndicator";
    this.options = options;
  }

  get info() {
    const { user } = this.options;

    return {
      name: `${user} on Example service`,
      uid: `https://service.example/${user}`,
      checked: true,
      service: {
        name: "Example service",
        url: "https://service.example/",
        photo: "/assets/example-syndicator/icon.svg",
      },
      user: {
        name: user,
        url: `https://social.example/${user}`,
      },
    };
  }

  async syndicate(properties, publication) {
    try {
      return await exampleClient.post(properties, publication);
    } catch (error) {
      throw new IndiekitError(error.message, {
        cause: error,
        plugin: this.name,
        status: error.status,
      });
    }
  }

  init(Indiekit) {
    Indiekit.addSyndicator(this);
  }
}

Example syndicator plug-ins: