Skip to main content

Resolve pages and templates with fallback data sources

Status: Draft

Benefits

  • Removes the need to define CMS pages in Magento as well as Contentful
  • Provides the ability to resolve page types locally without API request to speed up page load
  • Gives greater flexibility to page templates and improves page SEO by providing data required for canonical, hreflang, breadcrumbs schema.
  • Templates approach (phase 2) increases flexibility for nesting sections within custom layouts.

Route and Template datasource fallbacks

LocalDataSource

  • Remove page data source
  • Create new local data source @overdose/datasource-local. This datasource can be used to handle any APIs which can be resolved without a HTTP request to an external API. It would often be heavily modified on a project to define custom routes.
  • Existing functionality in /src/static-pages will be moved to this new data source.

Routes fallback

  • Add ability for route to register multiple data sources.
  • On requests each data source if called sequentially until one returns a page type. If a datasource cannot handle a route then it returns undefined and the next datasource is queried
export const dataSources: DataSources = {
// ... other data sources
route: [
new LocalRouteDataSource(),
new MagentoRouteDataSource(),
new ContentfulRouteDataSource(),
]
}
  • LocalRouteDataSource is instance of datasource-local
    • This will allow a project to implement specific paths for products (/products), categories (/categories), etc without requiring any HTTP request to determine the route type.
  • route APIs will return a Route type with additional data to assist with SEO schema generation.
interface Route {
type: PageType
canonicalUrl: Url
locale: string
alternateLocales: [AlternateLocaleRoute],
breadcrumbs: [Breadcrumb]
}

interface AlternateLocaleRoute {
locale: string
url: Url
}

interface Breadcrumb {
title: string,
url: Url
}

Templates fallback

  • Add ability for template to register multiple data sources.
  • On request each data source is called sequentially until one returns a template. If a datasource cannot handle a route then it returns undefined and the next data source is queried.
export const dataSources: DataSources = {
// ... other data sources
template: [
new LocaltemplateDataSource(),
new ContentfulTemplateDataSource(),
]
}
  • LocalTemplateDataSource is instance of datasource-local
    • This will allow a project to define a template for specific page types without requiring API requests to an external source.
    • eg Checkout pages, account pages, auth pages, cart page