publishDocuments

The publishDocuments method is responsible for publishing documents in the underlying content source.

Netlify Create calls this method when the user selects and publishes documents using the Netlify Create UI.

Parameters

This method receives an options object with the following properties:

  • document: Document[]: A list of Document objects from the Netlify Create cache to publish.
  • assets: Asset[]: A list of Asset objects from the Netlify Create cache to publish.
  • userContext?: UserContext: An object that contains the user's email, name, and optional OAuth access tokens defined by the UserContext generic type.

Return Value

This method should return a Promise that resolves with a void, indicating that the documents have been successfully published.

Example

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
import type { ContentSourceInterface, UpdateOperation } from '@stackbit/types'

interface UserContext {
  accessToken: string
}

export class MyContentSource
  implements
    ContentSourceInterface<
      UserContext,
      SchemaContext,
      DocumentContext,
      AssetContext
    >
{
  async publishDocuments(options: {
    documents: Document<DocumentContext>[]
    assets: Asset<AssetContext>[]
    userContext?: UserContext
  }): Promise<void> {
    // update the document
    await this.apiClient.publishDocuments({
      accessToken: options.userContext?.accessToken,
      documentIds: documents.map((document) => document.id),
    })
  }

  // other methods ...
}