Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@planetary/sanity-plugin-apple-news

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@planetary/sanity-plugin-apple-news

Generate Apple News JSON from Sanity documents

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
0
Weekly downloads
 
Created
Source

sanity-plugin-apple-news

This is a Sanity Studio v3 plugin.

Generate Apple News JSON directly from within Sanity CMS.

Screenshot 2024-07-05 at 11 30 08@2x

Installation

npm install @planetary/sanity-plugin-apple-news

Usage

Add it as a plugin in sanity.config.ts (or .js):

import {defineConfig} from 'sanity'
import {appleNews} from '@planetary/sanity-plugin-apple-news'

export default defineConfig({
  //...
  plugins: [
    // ...other plugins
    appleNews({
      // Use default configuration for
      article: {},
      blogPost: {
        fields: {
          thumbnail: 'featuredImage',
        },
      },
    }),
  ],
})

A more advanced configuration might look something like this:

import {defineConfig} from 'sanity'
import {appleNews, defaultTheme} from '@planetary/sanity-plugin-apple-news'

appleNews({
  schema: {
    article: {
      fields: {
        // Map Sanity field names to those expected by the Apple News plugin
        title: 'headline',
        subtitle: 'subHeadline',
        body: 'content',
        thumbnail: 'coverImage',
      },
      query: `
        *[_id == $documentId][0] {
          ...,
          # Resolve author references
          "authors": authors[]-> {
            name
          },
        }
      `,
    },
  },
  theme: {
    componentTextStyles: {
      ...defaultTheme.componentTextStyles,
      titleStyle: {
        textAlignment: 'left',
        fontName: 'DINCondensed-Bold',
        fontSize: 42,
        lineHeight: 54,
        textColor: '#4da68c',
      },
    },
  },
})

Configuration options

The plugin accepts the following configuration options.

OptionRequiredDescription
schemafalseObject keyed by the Sanity schema type names, and its respective configuration.
themefalseStyle overrides when generating the article.
customBlocksfalseHandle rendering custom block content when converting Portable Text to Apple News compatible HTML.
callbackfalseCallback to run after generating an article.
schema

This is the primary configuration you will work work with, and defines how to map your specific schema structure to that expected by Apple News JSON.

Enable the Apple News generation for your desired schema by adding it as a key to the schema object.

E.g. to enable this plugin for schema called blogPost the configuration object would be

appleNews({
  schema: {
    blogPost: {}
  }
})
schema.fields

Creates a mapping between the Apple News JSON keys and those of the Sanity schema, allowing the plugin to integrate with your existing schema structures.

Record<'metadata' | 'subtitle' | 'title' | 'authors' | 'body' | 'thumbnail', string>

// e.g. custom blog schema
appleNews({
  schema: {
    blogPost: {
      schema: {
        // Can be a partial mapping
        thumbnail: 'heroImage',
      },
    },
  },
})
schema.query

This is an advanced feature, allowing you to provide a custom GROQ query to execute when fetching documents.

This is primarily used for resolving item references in your documents. Note that the $documentId variable placeholder will be automatically injected by the plugin.

appleNews({
  schema: {
    article: {
      query: `
        *[_id == $documentId][0] {
          ...,
          # Resolve author references
          "authors": authors[]-> {
            name
          },
        }
      `,
    },
  },
})
theme

Customize the appearance of the generated article by configuring the Apple News JSON styles by extending the default theme. Please refer to the TypeScript type definitions for available options, as well as the official Apple News documentation.

customBlocks

This can be used to render custom components in the generated article. Optional mapping between your custom Block Content schema, and their Apple News compatible HTML representation.

This is passed directly to @portabletext/to-html, so please refer to the documentation there.

callback

A handler function to call when successfully generating an article.

This can be used to integrate with publishing workflows for example by trigger Webhooks or Zapier workflows.

It receives the generated Apple News article JSON as the first and only parameter.

Previewing

The only official method of preview Apple News articles is through the News Preview application which can be downloaded here.

The News Preview expects a JSON document titled article.json and a connected device with Apple News installed.

  • In Sanity Studio, navigate to the article you want to preview
  • Click the More / … button next to the document Publish button
  • Click Generate Apple News article
  • Open the News Preview application
  • Click on the big plus (+) icon in the application window, or the file menu bar File > Open…
  • Selected the downloaded article.json
  • From the right sidebar in the News Preview app, select a device to preview the article on
  • The article should open in Apple News
  • If you overwrite the article.json file, the Apple News preview will automatically update

Troubleshooting

At times Apple News Preview fails to load an article for unknown reasons.

Restarting the computer seems to resolve these issues.

If you’re still encountering issues after a restart, please verify that the syntax of the generated article.json is indeed valid. This could be due to issues with custom mappings between Block Content and Apple News HTML.

If issues persist after verifying the syntax, feel free to create an

Publishing

Publishing to Apple News requires an Apple Developer account and various publishing channels provisions.

Configuring these are beyond the scope of this starter kit, however you can utilize the callback configuration of this plugin to call the Apple News API.

Use the Sanity Studio Secrets plugin for securely embedding any required secrets and API keys within your Studio.

Develop & test

This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.

See Testing a plugin in Sanity Studio on how to run this plugin with hotreload in the studio.

Release new version

Run "CI & Release" workflow. Make sure to select the main branch and check "Release new version".

Semantic release will only release on configured branches, so it is safe to run release on any branch.

License

MIT © Planetary Corporation

Keywords

FAQs

Package last updated on 05 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc