Skip to content

Indiekit.addSyndicator

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

Constructor

PropertyTypeDescription
idStringKebab-cased plug-in ID. Required.
metaimport.metaRequired.
nameStringHuman readable plug-in name. Required.
optionsObjectPlug-in options. Optional.

Properties

PropertyTypeDescription
infoObjectInformation 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:

js
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://service.example/${user}`,
    },
  };
}
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://service.example/${user}`,
    },
  };
}

The info property returns the following values:

PropertyTypeDescription
nameStringThe name of the third-party service the syndicator supports. Required.
uidStringURL or path to the syndication target. Required.
checkedBooleanWhether this syndicator should be enabled by default in Micropub clients. Optional.
service.nameStringName of the third-party service. Optional.
service.urlStringURL of the third-party service. Optional.
service.photoStringIcon, logo or photo used to identify the third-party service in Micropub clients. Optional.
user.nameStringName of the user on the third-party service. Optional.
user.urlStringURL for the user on the third-party service. Optional.

Methods

MethodTypeDescription
syndicate()async functionSyndicate a post to a third-party service.

syndicate()

ParametersTypeDescription
propertiesObjectPath to file. Required.
publicationObjectPath to file. Required.

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

js
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,
    });
  }
}
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

js
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://service.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);
  }
}
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://service.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: