diff --git a/gatsby-config.js b/gatsby-config.js index 2f55704..6ccf83c 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -32,6 +32,7 @@ module.exports = { '**/*/*/tags', '**/*/*/taxonomies', '**/*/*/users', + '**/*/*/venues', ], excludedRoutes: [ '/yoast/**', diff --git a/gatsby-node.js b/gatsby-node.js index 8c4007a..8990b16 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -115,6 +115,56 @@ exports.createPages = ({ actions, graphql }) => { component: blogTemplate, }) }) + .then(() => { + return graphql(` + { + allWordpressWpVenues { + edges { + node { + id + path + slug + status + } + } + } + } + `) + }) + .then(result => { + if (result.errors) { + result.errors.forEach(e => console.error(e.toString())) + return Promise.reject(result.errors) + } + + const venueTemplate = path.resolve(`./src/templates/venue.js`) + + // In production builds, filter for only published venues. + const allVenues = result.data.allWordpressWpVenues.edges + const venues = + process.env.NODE_ENV === 'production' + ? getOnlyPublished(allVenues) + : allVenues + + // Iterate over the array of venues + _.each(venues, ({ node: venue }) => { + // Create the Gatsby page for this WordPress venue + createPage({ + path: venue.path, + component: venueTemplate, + context: { + id: venue.id, + }, + }) + }) + + // Create the booking page + // const bookingTemplate = path.resolve(`./src/templates/booking.js`) + // createPage({ + // path: `/booking/`, + // component: bookingTemplate, + // }) + }) .then(() => { return graphql(` { diff --git a/src/templates/event.js b/src/templates/event.js index 38b3fdb..35426bf 100644 --- a/src/templates/event.js +++ b/src/templates/event.js @@ -23,7 +23,6 @@ const formatPrices = (regular, student) => { export const EventTemplate = ({ content, title, - hasFeaturedMedia, featuredMedia, startTime, endTime, @@ -34,6 +33,7 @@ export const EventTemplate = ({ priceRegular, eventTypes, }) => { + const hasFeaturedMedia = featuredMedia && !!featuredMedia.localFile return (
@@ -119,9 +119,6 @@ const Event = ({ data }) => { { + const hasFeaturedMedia = featuredMedia && !!featuredMedia.localFile return (
{ title={post.title} date={post.date} author={post.author} - hasFeaturedMedia={!!post.featured_media.localFile} featuredMedia={post.featured_media} /> diff --git a/src/templates/venue.js b/src/templates/venue.js new file mode 100644 index 0000000..06b548b --- /dev/null +++ b/src/templates/venue.js @@ -0,0 +1,129 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { graphql } from 'gatsby' +import Layout from '../components/Layout' +import Img from 'gatsby-image' + +export class VenueTemplate extends React.Component { + render() { + const { + title, + content, + featuredMedia, + floor, + capacityLegal, + capacityStanding, + capacitySitting, + usedFor, + bar, + audio, + audioVideo, + lighting, + } = this.props + const hasFeaturedMedia = featuredMedia && !!featuredMedia.localFile + + return ( +
+
+

{title}

+ {hasFeaturedMedia && ( +
+ +
+ )} +
+
+
+
    + {floor &&
  • Etasje: {floor}
  • } + {capacityLegal &&
  • Branntillatelse for: {capacityLegal}
  • } + {capacityStanding &&
  • StÃ¥ende: {capacityStanding}
  • } + {capacitySitting &&
  • Sittende: {capacitySitting}
  • } + {usedFor &&
  • Bruk: {usedFor}
  • } + {bar &&
  • Bar: {bar}
  • } + {audio &&
  • Lyd: {audio}
  • } + {lighting &&
  • Lys: {lighting}
  • } + {audioVideo &&
  • A/V: {audioVideo}
  • } +
+
+
+ ) + } +} + +VenueTemplate.propTypes = { + title: PropTypes.string.isRequired, + content: PropTypes.string, + featuredImage: PropTypes.object, + floor: PropTypes.string, + capacityLegal: PropTypes.string, + capacityStanding: PropTypes.string, + capacitySitting: PropTypes.string, + usedFor: PropTypes.string, + bar: PropTypes.string, + audio: PropTypes.string, + audioVideo: PropTypes.string, + lighting: PropTypes.string, +} + +const VenuePage = ({ data }) => { + const { wordpressWpVenues: venue } = data + + return ( + + + + ) +} + +VenuePage.propTypes = { + data: PropTypes.object.isRequired, +} + +export default VenuePage + +export const pageQuery = graphql` + query VenueById($id: String!) { + wordpressWpVenues(id: { eq: $id }) { + id + path + title + slug + content + floor + capacity_legal + capacity_standing + capacity_sitting + used_for + bar + audio + lighting + audio_video + featured_media { + localFile { + ...FluidImage + } + } + } + } +`