Skip to content

Instantly share code, notes, and snippets.

@colorfield
Created May 30, 2017 17:55
Show Gist options
  • Save colorfield/678488345f6b4c908cfbbee341238dee to your computer and use it in GitHub Desktop.
Save colorfield/678488345f6b4c908cfbbee341238dee to your computer and use it in GitHub Desktop.
AudioGuide demo - React audio_list route
title component
Liste Audio
ContentPage

Nodes Drupal

title component
Audio list
ContentPage

Drupal Nodes

import React from 'react';
import { REST_HOST_NAME } from '../../constants';
import Layout from '../../components/Layout';
import AudioContentList from '../../components/AudioContentList';
export default {
path: '/',
async action({ locale }) {
// Get the static Markdown content
const staticContent = await new Promise((resolve) => {
require.ensure([], (require) => {
try {
resolve(require(`./audio_list.${locale}.md`)); // eslint-disable-line import/no-dynamic-require
} catch (e) {
resolve(require('./audio_list.md'));
}
}, 'audio_list');
});
// Match Drupal langcode
// @todo improve this
const drupalLocale = locale.substring(0, 2);
// Fetch the nodes
const endpoint = `${REST_HOST_NAME}/jsonapi/node/audio?sort=title&filter[langcode][value]=${drupalLocale}`;
const nodesResponse = await fetch(endpoint).then(response => response.json());
// Wrap static and Drupal content
const data = { staticContent, audioList: nodesResponse };
return {
title: staticContent.title,
chunk: 'audio_list',
component: <Layout><AudioContentList {...data} /></Layout>,
};
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment