SlideShare une entreprise Scribd logo
1  sur  53
Télécharger pour lire hors ligne
Embracing the modern web using
Drupal as Headless CMS
with GatsbyJS
by Jesus Manuel Olivas / weKnow
$ whoami
Jesus Manuel Olivas
jmolivas@weknowinc.com
twitter.com/jmolivas
github.com/jmolivas
drupal.org/u/jmolivas
jmolivas.weknowinc.com
weAre
101 Web Development
Traditional Monolithic CMS
The Traditional Headless
+
Visitor Server CMS Database
Challenges
Performance Reliability Security Hosting
Is there anything else we can use?
Static Site Generators
Back to the flat-files
Visitor CDN
The JAMStack Stack
Challenges
• Web Forms (CRM Integration , Serverless
Function, Form submission PaaS)
• E-Commerce (Shopify, Salsify, PXM,
Headless Commerce, Stripe, Paypal, Recurly)
• Comments (Disqus, Serverless functions)
A GUI providing a WYSIWYG to
enter content and create a content
model
Decoupling the
"Content Management System"
from the
“Production Environment".
●
Git Based / Headless CMS
●
CloudCannon
NetlifyCMS
Forestry
Blaze
Sanity
Drupal
Contentful
Gatsby is a free and open source
framework based on React that
helps developers build blazing
fast websites and apps
The Content Mesh
● https://www.gatsbyjs.org/blog/2018-10-18-creating-compelling-content-experiences/
https://github.com/weknowinc/drupal-boina
https://github.com/weknowinc/gatsby-starter-drupal-boina
How to Start?
https://boina.weknowinc.com/
http://drupal-boina.weknowinc.com/
Must have Gatsby plugins
• gatsby-source-drupal
• gatsby-transformer-remark
• gatsby-remark-drupal (support drupal images)
• gatsby-remark-images
• gatsby-remark-external-links
• gatsby-plugin-sharp
• gatsby-plugin-react-helmet
JSON:API
TUI Editor (WYSIWYG for markdown)
Build Hooks (Trigger a external build hook)
Gatsby Live Preview
https://weknowinc.com/blog/drupal-and-gatsby-live-preview
What to keep using
• Data modeling.
• Content editor capabilities,
revisions, moderation and
scheduling.
• Pathauto
• Site Settings
• Twig
• Render array
• Theme layer
• Theme preprocessing
• Views (use GraphQL instead)
What is Gone
●●
Feel free to turn off your Drupal site after build
●https://twitter.com/ckaotik/status/647020262001614848
Code or didn't happen
Source Data
Gatsby Source Drupal
    {
      resolve: 'gatsby-source-drupal',
      options: {
        baseUrl: `${process.env.DRUPAL_HOST}`,
        apiBase: `api`,
        preview: true,
      },
    },
Gatsby Source Airtable
{
  resolve: `gatsby-source-airtable`,
  options: {
    apiKey: process.env.AIRTABLE_API_KEY,
    tables: [
      {
        baseId: `appVUfH5DCWgBSBH1`,
        tableName: `Statistics`,
        mapping: { 
          icon: `fileNode`,
        }
      },
      {
        baseId: `appVUfH5DCWgBSBH1`,
        tableName: `Events`,
      },
      {
        baseId: `appVUfH5DCWgBSBH1`,
        tableName: `Presentations`,
        tableLinks: [`event`],
      },
    ]
  }
},
Custom Source API
exports.sourceNodes = async ({ actions }) => {
  const {createNode} = actions;
  const items = await axios.get(`https://YOUR-API-ENDPOINT-URI`);
  for (const item of items.data) {
      await createNode({
        children: [],
        ...item,
        parent: null,
        internal: {
          type: 'Items',
          contentDigest: crypto
            .createHash(`md5`)
            .update(JSON.stringify(item))
            .digest(`hex`),
        }
    })
  }
};
Create Pages
Create Pages 1/2
exports.createPages = ({ graphql, actions }) => {
  const { createPage } = actions
  return graphql(`
    {
      allNodeLanding(filter: {path: {alias: {ne: "/homepage"}}}) {
        edges {
          node {
            path {
              alias
            }
          }
        }
      }
    }
  `)
Create Pages 2/2
.then(result => {
    if (result.errors) {
      throw result.errors
    }
    const landings = result.data.allNodeLanding.edges
    landings.forEach(landing => {
      createPage({
        path: landing.node.path.alias,
        component: path.resolve(`./src/templates/landing.js`),
        context: {
          slug: landing.node.path.alias,
        },
      })
    })
  })
Create GraphQL Fragments
Paragraphs as GraphQL Fragments
import { graphql } from 'gatsby';
export const ParagraphCtaFragment = graphql`
  fragment ParagraphCtaFragment on paragraph__cta {    
    __typename
    field_cta_link {
      alias
    }
    field_download
    field_is_animated
    field_cta_size
    field_bg_color
    field_text {
      processed
    }
  }
`
Paragraphs as GraphQL Fragments
import { graphql } from 'gatsby';
export const ParagraphHeroFragment = graphql`
  fragment ParagraphHeroFragment on paragraph__hero {
    __typename
    field_title {
      processed
    }
    relationships {
      field_background_image {
        relationships {
          field_media_image {
            localFile {
              childImageSharp {
                fluid(maxWidth: 1440, maxHeight: 560, cropFocus: CENTER) {
                  ...GatsbyImageSharpFluid
                }
              }
            }
          }
        }
      }
    }
  }
`
Paragraphs as GraphQL Fragments
import { graphql } from 'gatsby';
export const ParagraphJSXComponentFragment = graphql`
  fragment ParagraphJSXComponentFragment on paragraph__jsx_component {    
    __typename
    field_component
    field_text {
      processed
    }
    field_title {
      processed
    }
  }
`
Use GraphQL Fragments
GraphQL queries using Fragments
query landingBySlug($slug: String!) {
    landing: nodeLanding(path: {alias: {eq: $slug}}) {
          title
      relationships {
        field_components {
          ...ParagraphHeroFragment
          ...ParagraphJSXComponentFragment
          ...ParagraphGridCardFragment
          ...ParagraphTextContentFragment
          ...ParagraphPartnersFragment
          ...ParagraphCtaFragment
        }
      }
}

}`
Render React Components
Render Components
import { componentResolver } from '../utils'
  const field_components = componentResolver(landing.relationships.field_components);
  return (
    <Layout>
      <SEO
        title={}
        keywords={[]}
      />
      {field_components && (
          field_components.map((item, i) => {
            return (
              <React.Fragment key={i}>
                {item}
              </React.Fragment>
            )
          })
      )}
    </Layout>
  );
Map Data to Components
Resolve Components 1/3
import TitleHero from ‘../components/title-hero';
import Cta from ‘../components/cta’;
import StatsBlocks from '../components/stats-blocks'
import StatsEventsBlocks from '../components/stats-events-blocks'
import TeamAdmin  from '../components/team-admin'
import AnimatedWordsHero  from '../components/animated-words-hero'
import Presentations from '../components/presentations';
const JSXComponents = {
  StatsBlocks: (props) => (<StatsBlocks {...props} />),
  TeamAdmin: (props) => (<TeamAdmin {...props} />),
  StatsEventsBlocks: (props) => (<StatsEventsBlocks {...props} />),
  AnimatedWordsHero: (props) => (<AnimatedWordsHero {...props} />),

Presentations: (props) => (<Presentations {...props} />),
}
Resolve Components 2/3
export const componentResolver = (data) => {
   const components = [];
   data.forEach(element => {
   if (element.__typename === `paragraph__hero`) {
     const title = element.field_title ? element.field_title.processed : ``;
     const field_image = element.relationships.field_image.relationships;
const image = field_image.field_media_image.localFile.childImageSharp.fluid;
      components.push(<TitleHero title={title} image={image} />);
    }
. . .
Resolve Components 3/3
. . .
   if (element.__typename === `paragraph__jsx_component`) {
      const Component = JSXComponents[element.field_component];
      const title = element.field_title ? element.field_title.processed : '';
      const text = element.field_text ? element.field_text.processed : '';
      
components.push(<Component title={title} text={text} />);
    }
  })
  return components;
}
Thank you
Feel free ask here and via twitter @jmolivas

Contenu connexe

Similaire à Embracing the modern web using Drupal as a Headless CMS with Gatsby BADCamp

DHO Intro to CMS for DH Workshop
DHO Intro to CMS for DH WorkshopDHO Intro to CMS for DH Workshop
DHO Intro to CMS for DH Workshop
Shawn Day
 
SharePoint 2007 and SharePoint 2010 for Web Content Management (WCM)
SharePoint 2007 and SharePoint 2010 for Web Content Management (WCM)SharePoint 2007 and SharePoint 2010 for Web Content Management (WCM)
SharePoint 2007 and SharePoint 2010 for Web Content Management (WCM)
Richard Harbridge
 

Similaire à Embracing the modern web using Drupal as a Headless CMS with Gatsby BADCamp (20)

Adding Enterprise Content Managment to your Drupal site using CMIS
Adding Enterprise Content Managment to your Drupal site using CMISAdding Enterprise Content Managment to your Drupal site using CMIS
Adding Enterprise Content Managment to your Drupal site using CMIS
 
Headless CMS VS Traditional CMS.pdf
Headless CMS VS Traditional CMS.pdfHeadless CMS VS Traditional CMS.pdf
Headless CMS VS Traditional CMS.pdf
 
DHO Intro to CMS for DH Workshop
DHO Intro to CMS for DH WorkshopDHO Intro to CMS for DH Workshop
DHO Intro to CMS for DH Workshop
 
Integrating DevOps and ALM tools to speed delivery
Integrating DevOps and ALM tools to speed deliveryIntegrating DevOps and ALM tools to speed delivery
Integrating DevOps and ALM tools to speed delivery
 
How to keep Drupal relevant in the Git-based and API-driven CMS era - BADCamp
How to keep Drupal relevant in the Git-based and API-driven CMS era - BADCampHow to keep Drupal relevant in the Git-based and API-driven CMS era - BADCamp
How to keep Drupal relevant in the Git-based and API-driven CMS era - BADCamp
 
Shift Remote FRONTEND: Optimizing Content Management with the Headless CMS - ...
Shift Remote FRONTEND: Optimizing Content Management with the Headless CMS - ...Shift Remote FRONTEND: Optimizing Content Management with the Headless CMS - ...
Shift Remote FRONTEND: Optimizing Content Management with the Headless CMS - ...
 
Headless 101 - Everything You Wanted to Know and More!
Headless 101 - Everything You Wanted to Know and More!Headless 101 - Everything You Wanted to Know and More!
Headless 101 - Everything You Wanted to Know and More!
 
CMS Tools for Developers- Owen Harris
CMS Tools for Developers- Owen HarrisCMS Tools for Developers- Owen Harris
CMS Tools for Developers- Owen Harris
 
WebMatrix
WebMatrixWebMatrix
WebMatrix
 
Kentico CMS Feature Overview
Kentico CMS Feature OverviewKentico CMS Feature Overview
Kentico CMS Feature Overview
 
Serverless is FaaS-tastic - All Things Open Meet-up
Serverless is FaaS-tastic - All Things Open Meet-upServerless is FaaS-tastic - All Things Open Meet-up
Serverless is FaaS-tastic - All Things Open Meet-up
 
Painless DevSecOps: Building Security Into Your DevOps Pipeline
Painless DevSecOps: Building Security Into Your DevOps PipelinePainless DevSecOps: Building Security Into Your DevOps Pipeline
Painless DevSecOps: Building Security Into Your DevOps Pipeline
 
Drupal Business Day, Singapore: Keynote
Drupal Business Day, Singapore: KeynoteDrupal Business Day, Singapore: Keynote
Drupal Business Day, Singapore: Keynote
 
Cloud Computing: First Steps to Jump-Start Your Cloud Project
Cloud Computing: First Steps to Jump-Start Your Cloud ProjectCloud Computing: First Steps to Jump-Start Your Cloud Project
Cloud Computing: First Steps to Jump-Start Your Cloud Project
 
Content Management - The story of headless CMS
Content Management - The story of headless CMSContent Management - The story of headless CMS
Content Management - The story of headless CMS
 
Modern Static Site with GatsbyJS
Modern Static Site with GatsbyJSModern Static Site with GatsbyJS
Modern Static Site with GatsbyJS
 
EdTechJoker Spring 2020 - Lecture 5 grav cms
EdTechJoker Spring 2020 - Lecture 5 grav cmsEdTechJoker Spring 2020 - Lecture 5 grav cms
EdTechJoker Spring 2020 - Lecture 5 grav cms
 
Dix conseils pour supporter la croissance de votre Startup de 0 à 10 millions...
Dix conseils pour supporter la croissance de votre Startup de 0 à 10 millions...Dix conseils pour supporter la croissance de votre Startup de 0 à 10 millions...
Dix conseils pour supporter la croissance de votre Startup de 0 à 10 millions...
 
SharePoint 2007 and SharePoint 2010 for Web Content Management (WCM)
SharePoint 2007 and SharePoint 2010 for Web Content Management (WCM)SharePoint 2007 and SharePoint 2010 for Web Content Management (WCM)
SharePoint 2007 and SharePoint 2010 for Web Content Management (WCM)
 
Microservices in der Cloud - Software Architecture Summit Berlin 2016
Microservices in der Cloud - Software Architecture Summit Berlin 2016Microservices in der Cloud - Software Architecture Summit Berlin 2016
Microservices in der Cloud - Software Architecture Summit Berlin 2016
 

Plus de Jesus Manuel Olivas

Plus de Jesus Manuel Olivas (20)

Remix & GraphQL: A match made in heaven with type-safety DX
Remix & GraphQL:  A match made in heaven with type-safety DXRemix & GraphQL:  A match made in heaven with type-safety DX
Remix & GraphQL: A match made in heaven with type-safety DX
 
Drupal 10 Party GraphQL
Drupal 10 Party GraphQLDrupal 10 Party GraphQL
Drupal 10 Party GraphQL
 
How to use Drupal to create editorial experiences your content creators will...
How to use Drupal  to create editorial experiences your content creators will...How to use Drupal  to create editorial experiences your content creators will...
How to use Drupal to create editorial experiences your content creators will...
 
Beyond Static: Building a Dynamic Application with Gatsby
Beyond Static: Building a Dynamic Application with GatsbyBeyond Static: Building a Dynamic Application with Gatsby
Beyond Static: Building a Dynamic Application with Gatsby
 
Drupal, GraphQL, Views, View Modes and Gatsby for a US Gov site CMS Philly
Drupal, GraphQL, Views, View Modes  and Gatsby for a US Gov site CMS PhillyDrupal, GraphQL, Views, View Modes  and Gatsby for a US Gov site CMS Philly
Drupal, GraphQL, Views, View Modes and Gatsby for a US Gov site CMS Philly
 
Building a modern application using Symfony API Platform and GatsbyJS PHP QRO
Building a modern application using  Symfony API Platform and GatsbyJS PHP QROBuilding a modern application using  Symfony API Platform and GatsbyJS PHP QRO
Building a modern application using Symfony API Platform and GatsbyJS PHP QRO
 
Building a dynamic application with GatsbyJS-Tec-Mexicali
Building a dynamic application  with GatsbyJS-Tec-MexicaliBuilding a dynamic application  with GatsbyJS-Tec-Mexicali
Building a dynamic application with GatsbyJS-Tec-Mexicali
 
Building a modern web application in the cloud partnercon
Building a modern web application in the cloud partnerconBuilding a modern web application in the cloud partnercon
Building a modern web application in the cloud partnercon
 
Blazing fast sites using Blaze, Hybrid CMS NYC
Blazing fast sites using Blaze, Hybrid CMS NYCBlazing fast sites using Blaze, Hybrid CMS NYC
Blazing fast sites using Blaze, Hybrid CMS NYC
 
Writing a slack chatbot seattle
Writing a slack chatbot seattleWriting a slack chatbot seattle
Writing a slack chatbot seattle
 
Building a Modern Web Application in the Cloud TecNerd
Building a Modern Web Application in the Cloud TecNerdBuilding a Modern Web Application in the Cloud TecNerd
Building a Modern Web Application in the Cloud TecNerd
 
How to keep Drupal relevant in the Git-based and API-driven CMS era Florida
How to keep Drupal relevant in the Git-based and API-driven CMS era FloridaHow to keep Drupal relevant in the Git-based and API-driven CMS era Florida
How to keep Drupal relevant in the Git-based and API-driven CMS era Florida
 
How to keep Drupal relevant in the Git-based and API-driven CMS era DrupalCampNJ
How to keep Drupal relevant in the Git-based and API-driven CMS era DrupalCampNJHow to keep Drupal relevant in the Git-based and API-driven CMS era DrupalCampNJ
How to keep Drupal relevant in the Git-based and API-driven CMS era DrupalCampNJ
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 Edition
 
Creating a modern web application using Symfony API Platform Atlanta
Creating a modern web application using  Symfony API Platform AtlantaCreating a modern web application using  Symfony API Platform Atlanta
Creating a modern web application using Symfony API Platform Atlanta
 
Battle of the CMS DrupalCampLA
Battle of the CMS DrupalCampLABattle of the CMS DrupalCampLA
Battle of the CMS DrupalCampLA
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
 
Writing a slack chatbot DrupalCampLA
Writing a slack chatbot DrupalCampLAWriting a slack chatbot DrupalCampLA
Writing a slack chatbot DrupalCampLA
 
Improving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLAImproving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLA
 
Writing a slack chatbot mxlos
Writing a slack chatbot mxlosWriting a slack chatbot mxlos
Writing a slack chatbot mxlos
 

Dernier

21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
rahulmanepalli02
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
IJECEIAES
 
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdfALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
Madan Karki
 
1893-part-1-2016 for Earthquake load design
1893-part-1-2016 for Earthquake load design1893-part-1-2016 for Earthquake load design
1893-part-1-2016 for Earthquake load design
AshishSingh1301
 

Dernier (20)

Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
Introduction to Arduino Programming: Features of Arduino
Introduction to Arduino Programming: Features of ArduinoIntroduction to Arduino Programming: Features of Arduino
Introduction to Arduino Programming: Features of Arduino
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptx
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdfALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdf
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
1893-part-1-2016 for Earthquake load design
1893-part-1-2016 for Earthquake load design1893-part-1-2016 for Earthquake load design
1893-part-1-2016 for Earthquake load design
 

Embracing the modern web using Drupal as a Headless CMS with Gatsby BADCamp