Skip to content

Instantly share code, notes, and snippets.

@usulpro
Created November 7, 2019 19:21
Show Gist options
  • Save usulpro/22c67e9bdc9f03bb0819ae4d1161827c to your computer and use it in GitHub Desktop.
Save usulpro/22c67e9bdc9f03bb0819ae4d1161827c to your computer and use it in GitHub Desktop.
// lib/getPage.js
import { getEntry } from "./contentful-client";
import { selectImages, selectTemplate } from "./cms-selectors";
export const getPage = async entryId => {
const customPage = await getEntry(entryId);
const {
url,
title,
seoTitle,
seoDescription,
headerImage,
template,
} = customPage.fields;
const headerBackground = selectImages([headerImage])[0];
const page = {
title: seoTitle,
description: seoDescription,
canonical: `/${url}`,
};
const header = {
background: headerBackground && headerBackground.url,
title,
};
const content = selectTemplate(template);
return { page, header, content };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment