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

@arc-core-components/content-source_content-api-v4

Package Overview
Dependencies
Maintainers
14
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arc-core-components/content-source_content-api-v4

Provides a common content source for the Content API portion of the Arc suite.

  • 4.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
221
decreased by-37.22%
Maintainers
14
Weekly downloads
 
Created
Source

Content Source: Content API v4 endpoint

This the Arc Core Component representing a content source that hooks into the Content API portion of the Arc Suite.

The most important part is the pattern, which defines the endpoint that PageBuilder Fusion uses to look up content.

This Core Component takes advantage of PageBuilder Fusion's ability to use CONTENT_BASE to define the credentials for a Content API, ensuring that no private secrets are exposed.

Pattern:

/content/v4/?website={arc-site}&website_url=${website_url}

Parameters:

This content source takes one parameter: a website URL, typically the path to the story following the domain name.

Getting started

This Core Component must be used within a Fusion project.

  1. Add this schema as a dependency of the repo. npm install @arc-core-components/content-source_content-api-v4
  2. Create a file of your desired content source name within the /content/sources folder. For this content source, the suggested name is content-api-v4.js
  3. This is the name you should use when referencing this content source in any content config within a custom field.
  4. Paste the following into content-api-v4.js:
import source from "@arc-core-components/content-source_content-api-v4";

export default source;

What does this content source return?

This will return an ANS document representing a single story from a Content API.

Overwriting the default website

The default export of the content source is set up for multisite deployments where a _website url parameter is necessary when visiting a specific page. Example: http://localhost/pf/sample-page/?_website=the-gazette. To override this behavior for a single site build we provide a factory function for creating an otherwise unchanged content source with a user provided website.

import { createContentSource } from "@arc-core-components/content-source_content-api-v4";
export default createContentSource("washingtonpost");

Adding resizer URLs to images

This module also exports a helper function addResizedUrls that can be called within the transform function to automatically add resizer URLs to all images in the content source:

import source, { addResizedUrls } from '@arc-core-components/content-source_content-api-v4';
import { resizerSecret, resizerUrl } from 'fusion:environment';

const transform = (data) => {
  return addResizedUrls(data, { resizerUrl, resizerSecret, presets: {
    small: { width: 50, height: 50 },
    large: {width: 480 }
  }});
};

export default {
  ...source,
  transform,
};

Then you can use the sizePreset prop in the image core component and it will be automatically resized:

<Image sizePreset="large" {...additionalProps} />

Here's an example for multisite, where each site could have its own resizer endpoint. This is helpful for clients that have publications in different continents - you can set up a resizer endpoint in each site's properties.

// properties/sites/my-site.json
{
    resizerUrl: "my-resizer-endpoint.com",
    resizerSecretKeyEnvVar: "RESIZER_SECRET_EU"
}

// content/sources/content-api-v4.js
import source, { addResizedUrls } from '@arc-core-components/content-source_content-api-v4';
import envVars from 'fusion:environment';
import getProperties from 'fusion:properties';

const transform = (data) => {
  const { website } = data;
  const { resizerSecretKeyEnvVar, resizerUrl } = getProperties(website);
  const resizerSecret = envVars[resizerSecretKeyEnvVar];
  return addResizedUrls(data, { resizerUrl, resizerSecret, presets: {
    small: { width: 50, height: 50 },
    large: {width: 480 }
  }});
  /*
  * Alternately you can give addResizedUrls a callback
  * return addResizedUrls(data, function ({ url, width, height, focalPoint }) {
  *  return { customSize: thumbor.setImagePath(url, resize(480, 0).buildUrl() }
  * });
  *
  */
};

export default {
  ...source,
  transform,
};

See also:

  • fusion recipe on using environment variables and secrets
  • image core component documentation

Testing & Linting

We are using Jest and XO for testing and linting.

We are using Husky to run a pre-push hook, preventing un-linted or code that fails tests from making it into the repo.

To test: npm test

To lint: npm run lint - This will also fix any simple linter errors automatically.

To push without testing or linting: git push --no-verify - This can often be helpful if you just need to push a branch for demonstration purposes or for help.

FAQs

Package last updated on 28 Jan 2020

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