2

I added the media library plugin to my sanity structure builder but want to remove the 'media tag' document that gets created by the plugin

However, you can override this behaviour by defining your own custom desk with Sanity's structure builder and simply omit the media.tag document type in your definition

I am unclear on how to do this with my current structure

  plugins: [
    deskTool({
      structure: pageStructure([home, settings]),

      defaultDocumentNode: previewDocumentNode({ apiVersion, previewSecretId }),
    }),

    singletonPlugin([home.name, settings.name]),

    productionUrl({
      apiVersion,
      previewSecretId,
      types: PREVIEWABLE_DOCUMENT_TYPES,
    }),
    media(),
    vercelDeployTool(),
    visionTool({ defaultApiVersion: apiVersion }),
  ],
Burger Sasha
  • 187
  • 6
  • 17

2 Answers2

1

The project is setup in JSON. The functions you call are probably also returning JSON. So there should be an easy workaround for this.

One of the functions adds a property media.tag with their value. (I don't know which function exactly but you can find out easily by printing each object in your plugins array).

Once you found this out, you can make use of the delete operator in JavaScript.

Here is a simple example which you can derive pretty easy:

const plugins = {
    // other properties here
    media: {
        tag: "plugin-tag",
        // other properties here
    },
}

delete plugins.media.tag // returns true if property deleted.

/*
Plugins object after deletion of `media.tag`:

const plugins = {
    // other properties here
    media: {
        // other properties here
    },
}
*/

⚠️ Note: I treated tag as if it is a property on the media object, if media.tag is the name of a single property, use the bracket notation (["media.tag"]) instead.

Once you have done this, you have "omitted the media.tag document type in your definition" and you should be good to go.

Throvn
  • 795
  • 7
  • 19
1

This is how I hid the Media Tag document type from the desk:

export default defineConfig({
  plugins: [
    deskTool({
      structure: (S) =>
        S.list()
          .title('Content')
          .items([...S.documentTypeListItems().filter((item) => item.getId() !== 'media.tag')]),
    }),
  ],
});
gabrielmaldi
  • 2,157
  • 2
  • 23
  • 39