Великолепный Gatsby.js | Odessa Frontend Meetup #19

OdessaFrontend
OdessaFrontendOdessaFrontend
Why do front-end


developers 💜 Gatsby.js
Hello,
my name is Katya and I’m front-end dev in Boosta.
Why do front-end


developers 💜 Gatsby.js
What is Gatsby.js
• Gatsby widely known as a Static Site Generator (SSG)


• Uses a combination of React & GraphQL


• Gatsby calls itself a Modern Site Generator
Static Site Generatorors
• Generates static HTML pages using a combo of templates, components & data.
Static Websites


• Uses static HTML pages (with maybe JS & CSS)


• Pages uploaded to a CDN / web host
Drawbacks


• Hard to update / maintain pages (re-writing a lot of the same code on every page)


• Fresh request to the server for every page (slows website down)


• Generally do not contain dynamic data
Server
page request
Types of Websites
SEO


Speed


Easy to update
Types of Websites
Single Page Applications


• Typical React / Vue website


• Only a single server request mode for the initial HTML page (empty)


• Everything else (routing, data) is handled by the SPA in the browser
SEO


Speed


Easy to update
Drawbacks


• Web pages are not SEO friendly (initial request is for a blank HTML page)
Server
initial request only
Types of Websites
Server Side Rendered (SSR)


• Pages rendered on the server after every request


• Server sources data (e.g. mongodb) & uses templates to render HTML pages


• Resulting pages are sent back to the browser
SEO


Speed


Easy to update
Drawbacks


• Fresh request needs to be made for every page


• Server can take time getting data and rendering pages
Server
page requests
renders pages using


templates & data
Types of Websites
Static Site Generator (Gatsby)


• Static pages are compiled at build-time (before deployment)


• Gatsby sites / pages are made using React components


• Static pages are then deployed to the web


• After initial request, the site behaves more like an SPA
SEO


Speed


Easy to update
Server
initial request
(fully rendered – good for SEO)
How Gatsby Works
Make 💜, not 💩
Make 💜, not 💩
in 5 baby steps
0. Set Up Your Development Environment → Create Your First Gatsby Site
npm install -g gatsby-cli
gatsby new my-awesome-project
https://github.com/gatsbyjs/gatsby-starter-hello-world
cd my-awesome-project
Installing CLI and creating new project
Using CLI to Run, Build and Serve project
gatsby develop
gatsby build
gatsby serve
1. Create and Deploy Your First Gatsby Site
2. Use and Style React Components
Create a page component
Task: Update the home page content
localhost:8000
2. Use and Style React Components
Task: Create a new page component for an About page
localhost:8000/about
2. Use and Style React Components
Use the <Link> component
Task: On the Home page, import the Link component from the Gatsby package
2. Use and Style React Components
Create a reusable layout component
Task: Create a new
fi
le called src/components/layout.js
2. Use and Style React Components
Task: Update your Home page component to use the Layout component instead of the
hard-coded Link component you added in the previous section
2. Use and Style React Components
Style components with CSS Modules
Task: Create a new
fi
le: src/components/layout.module.css
2. Use and Style React Components
Task: Then import that class into your Layout component .js 
fi
le, and use the className prop to
assign it to the top-level <div> element:
3. Add Features with Plugins
3. Add Features with Plugins
Task: Use gatsby-plugin-image to add a static image to your home page
npm install gatsby-plugin-image gatsby-plugin-sharp gatsby-source-
fi
lesystem
3. Add Features with Plugins
Task: Use gatsby-plugin-image to add a static image to your home page
4. Query for Data with GraphQL
4. Query for Data with GraphQL
Use GraphiQL to explore the data layer and write GraphQL queries
http://localhost:8000/___graphql
4. Query for Data with GraphQL
Task: Use GraphiQL to build the query
• In your web browser, go to localhost:8000/___graphiql to see the GraphiQL interface.


• In the Explorer pane, open the dropdown for the site 
fi
eld.


• Within the site 
fi
eld, open the second dropdown for the siteMetadata 
fi
eld (the blue one). This corresponds to
the siteMetadata object in your gatsby-con
fi
g.js 
fi
le.
4. Query for Data with GraphQL
Task: Use useStaticQuery to pull the site title into the Layout component
Import the useStaticQuery function and the graphql tag from the Gatsby package.
4. Query for Data with GraphQL
Task: Use useStaticQuery to pull the site title into the Layout component
Call useStaticQuery and pass it the query you created in GraphiQL. Be sure to use the graphql tag so Gatsby
knows that the string you’re passing in is a GraphQL query. Store the return value from useStaticQuery in a
variable.
4. Query for Data with GraphQL
Task: Use useStaticQuery to pull the site title into the Layout component
Now that you have a variable with the results of your query, you can render the title of your site in the JSX
for your Layout component. 
4. Query for Data with GraphQL
Task: Create a new blog page
Create a new
fi
le: src/pages/blog.js. De
fi
ne and export a new page component for your blog page.
Use your existing Layout component to add some basic structure.
4. Query for Data with GraphQL
Task: Create a new blog page
Add a link to your new blog page to the navigation bar in your Layout component:
4. Query for Data with GraphQL
Task: Create some MDX blog posts
• Create a new directory called blog at the top level of your project folder.


• Create three new
fi
les in the blog directory: one for each post.
4. Query for Data with GraphQL
Task: Use GraphiQL to build the query
• Now that you have some posts saved to your local
fi
lesystem, it’s time to pull those
fi
les into the
Gatsby data layer. To do that, you’ll use a plugin called gatsby-source-
fi
lesystem.


• Con
fi
gure gatsby-source-
fi
lesystem in your gatsby-con
fi
g.js 
fi
le. Since gatsby-source-
fi
lesystem requires some additional con
fi
guration options, you’ll use a con
fi
guration object instead
of a string. The code example below shows how to “source”
fi
les from your blog directory (in other
words, how to add them to the data layer).
4. Query for Data with GraphQL
Task: Use GraphiQL to build the query
• Restart your local development server to make sure it picks up the con
fi
guration changes and
adds your
fi
les to the data layer.


• You can use the allFile 
fi
eld to request data about multiple
fi
les at once. In GraphiQL, try exploring
the different
fi
elds within allFile to see what sorts of data you get back. Then build a query using
the allFile 
fi
eld to get the name of all the
fi
les in your blog folder:
4. Query for Data with GraphQL
Task: Use a page query to pull the list of post
fi
lenames into your blog page
Import the graphql tag from the Gatsby package.
4. Query for Data with GraphQL
Task: Use a page query to pull the list of post
fi
lenames into your blog page
De
fi
ne and export your page query. Copy over the query you built in GraphiQL
4. Query for Data with GraphQL
Task: Use a page query to pull the list of post
fi
lenames into your blog page
Add in the data prop to the function de
fi
nition.
5. Transform Data to Use MDX
4. Query for Data with GraphQL
Some example posts that you can use for inspiration:
4. Query for Data with GraphQL
Render each post’s contents on the Blog page
Now that you have some MDX content inside your blog posts, it’s time set up
the gatsby-plugin-mdx transformer plugin.


The gatsby-plugin-mdx plugin provides some new tools for you to use in your site:


• The allMdx and mdx 
fi
elds (for your GraphQL queries)


• An MDXRenderer component (for processing and displaying MDX content)
4. Query for Data with GraphQL
Task: Install and con
fi
gure the MDX transformer plugin (and dependencies)
npm install gatsby-plugin-mdx @mdx-js/mdx @mdx-js/react
4. Query for Data with GraphQL
Task: Update the Blog page query to use the allMdx 
fi
eld instead of allFile
4. Query for Data with GraphQL
Task: Use the MDXRenderer component to render your post’s contents in your Blog page
4. Query for Data with GraphQL
Task: Use the MDXRenderer component to render your post’s contents in your Blog page
Next, update the JSX for your Blog page to use the data
fi
elds of your response.
Start by rendering just the title and date for each post.
4. Query for Data with GraphQL
Task: Use the MDXRenderer component to render your post’s contents in your Blog page
The
fi
nal step in this part of the Tutorial is to render the actual contents of your MDX blog posts.
To do that, you’ll need to use a component from gatsby-plugin-mdx called MDXRenderer. Start by
importing the component into your Blog page:
4. Query for Data with GraphQL
Task: Use the MDXRenderer component to render your post’s contents in your Blog page
In the JSX for your Blog page, use the MDXRenderer component to wrap the contents of the body 
fi
eld
for each node:
Gatsby pros
Gatsby cons
Don’t use Gatsby if:


• There will be a lot of content – for example, if it’s a large blog, generating a static website can
take up to 15 minutes. However, for those using Gatsby Cloud, there is a solution called
Incremental Builds which shortens build time up to 1000x, but it’s not free (cost starts from $19/
month)


• You need to update content a lot – because those updates won’t be visible instantly as in, for
example, WordPress


• It’s a corporate-size webshop – this point is similar to the
fi
rst one because the more content
you have, the longer the build time will be. Although the solution is Gatsby cloud,
fi
rst of all, you
have to pay for this, and second of all, any updates still won’t be visible right away
Thank you ✌
Sincerely yours 🤍
1 of 50

Recommended

Rendering: Or why your perfectly optimized content doesn't rank by
Rendering: Or why your perfectly optimized content doesn't rankRendering: Or why your perfectly optimized content doesn't rank
Rendering: Or why your perfectly optimized content doesn't rankWeLoveSEO
40 views69 slides
02 integrate highchart by
02 integrate highchart02 integrate highchart
02 integrate highchartErhwen Kuo
2.5K views54 slides
Automated Duplicate Content Consolidation with Google Cloud Functions by
Automated Duplicate Content Consolidation with Google Cloud FunctionsAutomated Duplicate Content Consolidation with Google Cloud Functions
Automated Duplicate Content Consolidation with Google Cloud FunctionsWeLoveSEO
102 views51 slides
VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline by
VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline Jan Jongboom
1.4K views74 slides
A Power User's Intro to jQuery Awesomeness in SharePoint by
A Power User's Intro to jQuery Awesomeness in SharePointA Power User's Intro to jQuery Awesomeness in SharePoint
A Power User's Intro to jQuery Awesomeness in SharePointMark Rackley
1.1K views24 slides
Modern Automated Site Provisioning for SharePoint Online by
Modern Automated Site Provisioning for SharePoint OnlineModern Automated Site Provisioning for SharePoint Online
Modern Automated Site Provisioning for SharePoint OnlineDocFluix, LLC
4.3K views32 slides

More Related Content

Similar to Великолепный Gatsby.js | Odessa Frontend Meetup #19

Using the WordPress REST API and Gatsby.js by
Using the WordPress REST API and Gatsby.jsUsing the WordPress REST API and Gatsby.js
Using the WordPress REST API and Gatsby.jsIndigo Tree Digital
6.2K views42 slides
Harness The Power Of ACF For Gatsby and WordPress by
Harness The Power Of ACF For Gatsby and WordPressHarness The Power Of ACF For Gatsby and WordPress
Harness The Power Of ACF For Gatsby and WordPressImran Sayed
1.4K views34 slides
Build Fast WordPress Site With Gatsby by
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyImran Sayed
1.3K views76 slides
04 asp.net session05 by
04 asp.net session0504 asp.net session05
04 asp.net session05Mani Chaubey
271 views18 slides
Top 8 react static site generators for 2020 by
Top 8 react static site generators for 2020Top 8 react static site generators for 2020
Top 8 react static site generators for 2020Katy Slemon
40 views34 slides
Untangling spring week5 by
Untangling spring week5Untangling spring week5
Untangling spring week5Derek Jacoby
436 views26 slides

Similar to Великолепный Gatsby.js | Odessa Frontend Meetup #19(20)

Harness The Power Of ACF For Gatsby and WordPress by Imran Sayed
Harness The Power Of ACF For Gatsby and WordPressHarness The Power Of ACF For Gatsby and WordPress
Harness The Power Of ACF For Gatsby and WordPress
Imran Sayed1.4K views
Build Fast WordPress Site With Gatsby by Imran Sayed
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With Gatsby
Imran Sayed1.3K views
04 asp.net session05 by Mani Chaubey
04 asp.net session0504 asp.net session05
04 asp.net session05
Mani Chaubey271 views
Top 8 react static site generators for 2020 by Katy Slemon
Top 8 react static site generators for 2020Top 8 react static site generators for 2020
Top 8 react static site generators for 2020
Katy Slemon40 views
Untangling spring week5 by Derek Jacoby
Untangling spring week5Untangling spring week5
Untangling spring week5
Derek Jacoby436 views
JAMstack with gatsby, contentful and netlify aka the dream stack by zonathen
JAMstack with gatsby, contentful and netlify aka the dream stackJAMstack with gatsby, contentful and netlify aka the dream stack
JAMstack with gatsby, contentful and netlify aka the dream stack
zonathen282 views
Build Your Blazing Fast Site with Gatsby and WordPress @ WordSesh by Muhammad... by rtCamp
Build Your Blazing Fast Site with Gatsby and WordPress @ WordSesh by Muhammad...Build Your Blazing Fast Site with Gatsby and WordPress @ WordSesh by Muhammad...
Build Your Blazing Fast Site with Gatsby and WordPress @ WordSesh by Muhammad...
rtCamp 2.5K views
Pre-render Blazor WebAssembly on static web hosting at publishing time by Jun-ichi Sakamoto
Pre-render Blazor WebAssembly on static web hosting at publishing timePre-render Blazor WebAssembly on static web hosting at publishing time
Pre-render Blazor WebAssembly on static web hosting at publishing time
Jun-ichi Sakamoto1.1K views
04 asp.net session05 by Vivek chan
04 asp.net session0504 asp.net session05
04 asp.net session05
Vivek chan113 views
Contentful with Netgen Layouts workshop by Ivo Lukac
Contentful with Netgen Layouts workshopContentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshop
Ivo Lukac519 views
Cis363 all i labs devry university by jkkjhdy798iyi
Cis363 all i labs devry universityCis363 all i labs devry university
Cis363 all i labs devry university
jkkjhdy798iyi1.2K views
Cis363 a all ilabs devry university by CIS363A
Cis363 a all ilabs devry universityCis363 a all ilabs devry university
Cis363 a all ilabs devry university
CIS363A170 views
Cis363 a all ilabs devry university by CIS363A
Cis363 a all ilabs devry universityCis363 a all ilabs devry university
Cis363 a all ilabs devry university
CIS363A2.2K views
Cis363 all i labs devry university by CIS363A
Cis363 all i labs devry universityCis363 all i labs devry university
Cis363 all i labs devry university
CIS363A855 views
Page object from the ground up by Joe Beale by QA or the Highway
Page object from the ground up by Joe BealePage object from the ground up by Joe Beale
Page object from the ground up by Joe Beale
QA or the Highway479 views
Page object from the ground up.ppt by Joseph Beale
Page object from the ground up.pptPage object from the ground up.ppt
Page object from the ground up.ppt
Joseph Beale46 views

More from OdessaFrontend

Викторина | Odessa Frontend Meetup #19 by
Викторина | Odessa Frontend Meetup #19Викторина | Odessa Frontend Meetup #19
Викторина | Odessa Frontend Meetup #19OdessaFrontend
139 views20 slides
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee... by
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...OdessaFrontend
151 views34 slides
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr... by
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...OdessaFrontend
214 views73 slides
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18 by
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18OdessaFrontend
82 views19 slides
Викторина | Odessa Frontend Meetup #17 by
Викторина | Odessa Frontend Meetup #17Викторина | Odessa Frontend Meetup #17
Викторина | Odessa Frontend Meetup #17OdessaFrontend
150 views23 slides
Антихрупкий TypeScript | Odessa Frontend Meetup #17 by
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17OdessaFrontend
107 views60 slides

More from OdessaFrontend(20)

Викторина | Odessa Frontend Meetup #19 by OdessaFrontend
Викторина | Odessa Frontend Meetup #19Викторина | Odessa Frontend Meetup #19
Викторина | Odessa Frontend Meetup #19
OdessaFrontend139 views
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee... by OdessaFrontend
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...
OdessaFrontend151 views
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr... by OdessaFrontend
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...
OdessaFrontend214 views
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18 by OdessaFrontend
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18
OdessaFrontend82 views
Викторина | Odessa Frontend Meetup #17 by OdessaFrontend
Викторина | Odessa Frontend Meetup #17Викторина | Odessa Frontend Meetup #17
Викторина | Odessa Frontend Meetup #17
OdessaFrontend150 views
Антихрупкий TypeScript | Odessa Frontend Meetup #17 by OdessaFrontend
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17
OdessaFrontend107 views
Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17 by OdessaFrontend
Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17
Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17
OdessaFrontend84 views
OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17 by OdessaFrontend
OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17
OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17
OdessaFrontend254 views
Объекты в ECMAScript | Odessa Frontend Meetup #16 by OdessaFrontend
Объекты в ECMAScript | Odessa Frontend Meetup #16Объекты в ECMAScript | Odessa Frontend Meetup #16
Объекты в ECMAScript | Odessa Frontend Meetup #16
OdessaFrontend169 views
Фриланс как профессиональная деградация | Odessa Frontend Meetup #16 by OdessaFrontend
Фриланс как профессиональная деградация | Odessa Frontend Meetup #16Фриланс как профессиональная деградация | Odessa Frontend Meetup #16
Фриланс как профессиональная деградация | Odessa Frontend Meetup #16
OdessaFrontend159 views
Cлайдер на CSS | Odessa Frontend Meetup #16 by OdessaFrontend
Cлайдер на CSS | Odessa Frontend Meetup #16Cлайдер на CSS | Odessa Frontend Meetup #16
Cлайдер на CSS | Odessa Frontend Meetup #16
OdessaFrontend148 views
Современный станок верстальщика by OdessaFrontend
Современный станок верстальщикаСовременный станок верстальщика
Современный станок верстальщика
OdessaFrontend188 views
Викторина | Odessa Frontend Meetup #15 by OdessaFrontend
Викторина | Odessa Frontend Meetup #15Викторина | Odessa Frontend Meetup #15
Викторина | Odessa Frontend Meetup #15
OdessaFrontend87 views
DRY’им Vuex | Odessa Frontend Meetup #15 by OdessaFrontend
DRY’им Vuex | Odessa Frontend Meetup #15DRY’им Vuex | Odessa Frontend Meetup #15
DRY’им Vuex | Odessa Frontend Meetup #15
OdessaFrontend64 views
А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15 by OdessaFrontend
А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15
А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15
OdessaFrontend109 views
Пощупать 3д в браузере | Odessa Frontend Meetup #15 by OdessaFrontend
Пощупать 3д в браузере | Odessa Frontend Meetup #15Пощупать 3д в браузере | Odessa Frontend Meetup #15
Пощупать 3д в браузере | Odessa Frontend Meetup #15
OdessaFrontend126 views
Викторина | Odessa Frontend Meetup #14 by OdessaFrontend
Викторина | Odessa Frontend Meetup #14Викторина | Odessa Frontend Meetup #14
Викторина | Odessa Frontend Meetup #14
OdessaFrontend83 views
Викторина | Odessa Frontend Meetup #13 by OdessaFrontend
Викторина | Odessa Frontend Meetup #13Викторина | Odessa Frontend Meetup #13
Викторина | Odessa Frontend Meetup #13
OdessaFrontend147 views
Структуры данных в JavaScript | Odessa Frontend Meetup #13 by OdessaFrontend
Структуры данных в JavaScript | Odessa Frontend Meetup #13Структуры данных в JavaScript | Odessa Frontend Meetup #13
Структуры данных в JavaScript | Odessa Frontend Meetup #13
OdessaFrontend1.6K views
Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13 by OdessaFrontend
Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13
Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13
OdessaFrontend184 views

Recently uploaded

Zero to Automated in Under a Year by
Zero to Automated in Under a YearZero to Automated in Under a Year
Zero to Automated in Under a YearNetwork Automation Forum
15 views23 slides
Microsoft Power Platform.pptx by
Microsoft Power Platform.pptxMicrosoft Power Platform.pptx
Microsoft Power Platform.pptxUni Systems S.M.S.A.
53 views38 slides
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Safe Software
280 views86 slides
PRODUCT PRESENTATION.pptx by
PRODUCT PRESENTATION.pptxPRODUCT PRESENTATION.pptx
PRODUCT PRESENTATION.pptxangelicacueva6
15 views1 slide
Serverless computing with Google Cloud (2023-24) by
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)wesley chun
11 views33 slides
Uni Systems for Power Platform.pptx by
Uni Systems for Power Platform.pptxUni Systems for Power Platform.pptx
Uni Systems for Power Platform.pptxUni Systems S.M.S.A.
56 views21 slides

Recently uploaded(20)

Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software280 views
Serverless computing with Google Cloud (2023-24) by wesley chun
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)
wesley chun11 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays17 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi132 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10300 views
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56115 views

Великолепный Gatsby.js | Odessa Frontend Meetup #19

  • 2. Hello, my name is Katya and I’m front-end dev in Boosta.
  • 4. What is Gatsby.js • Gatsby widely known as a Static Site Generator (SSG) • Uses a combination of React & GraphQL • Gatsby calls itself a Modern Site Generator
  • 5. Static Site Generatorors • Generates static HTML pages using a combo of templates, components & data.
  • 6. Static Websites • Uses static HTML pages (with maybe JS & CSS) • Pages uploaded to a CDN / web host Drawbacks • Hard to update / maintain pages (re-writing a lot of the same code on every page) • Fresh request to the server for every page (slows website down) • Generally do not contain dynamic data Server page request Types of Websites SEO Speed Easy to update
  • 7. Types of Websites Single Page Applications • Typical React / Vue website • Only a single server request mode for the initial HTML page (empty) • Everything else (routing, data) is handled by the SPA in the browser SEO Speed Easy to update Drawbacks • Web pages are not SEO friendly (initial request is for a blank HTML page) Server initial request only
  • 8. Types of Websites Server Side Rendered (SSR) • Pages rendered on the server after every request • Server sources data (e.g. mongodb) & uses templates to render HTML pages • Resulting pages are sent back to the browser SEO Speed Easy to update Drawbacks • Fresh request needs to be made for every page • Server can take time getting data and rendering pages Server page requests renders pages using templates & data
  • 9. Types of Websites Static Site Generator (Gatsby) • Static pages are compiled at build-time (before deployment) • Gatsby sites / pages are made using React components • Static pages are then deployed to the web • After initial request, the site behaves more like an SPA SEO Speed Easy to update Server initial request (fully rendered – good for SEO)
  • 12. Make 💜, not 💩 in 5 baby steps
  • 13. 0. Set Up Your Development Environment → Create Your First Gatsby Site npm install -g gatsby-cli gatsby new my-awesome-project https://github.com/gatsbyjs/gatsby-starter-hello-world cd my-awesome-project Installing CLI and creating new project Using CLI to Run, Build and Serve project gatsby develop gatsby build gatsby serve
  • 14. 1. Create and Deploy Your First Gatsby Site
  • 15. 2. Use and Style React Components Create a page component Task: Update the home page content localhost:8000
  • 16. 2. Use and Style React Components Task: Create a new page component for an About page localhost:8000/about
  • 17. 2. Use and Style React Components Use the <Link> component Task: On the Home page, import the Link component from the Gatsby package
  • 18. 2. Use and Style React Components Create a reusable layout component Task: Create a new fi le called src/components/layout.js
  • 19. 2. Use and Style React Components Task: Update your Home page component to use the Layout component instead of the hard-coded Link component you added in the previous section
  • 20. 2. Use and Style React Components Style components with CSS Modules Task: Create a new fi le: src/components/layout.module.css
  • 21. 2. Use and Style React Components Task: Then import that class into your Layout component .js  fi le, and use the className prop to assign it to the top-level <div> element:
  • 22. 3. Add Features with Plugins
  • 23. 3. Add Features with Plugins Task: Use gatsby-plugin-image to add a static image to your home page npm install gatsby-plugin-image gatsby-plugin-sharp gatsby-source- fi lesystem
  • 24. 3. Add Features with Plugins Task: Use gatsby-plugin-image to add a static image to your home page
  • 25. 4. Query for Data with GraphQL
  • 26. 4. Query for Data with GraphQL Use GraphiQL to explore the data layer and write GraphQL queries http://localhost:8000/___graphql
  • 27. 4. Query for Data with GraphQL Task: Use GraphiQL to build the query • In your web browser, go to localhost:8000/___graphiql to see the GraphiQL interface. • In the Explorer pane, open the dropdown for the site  fi eld. • Within the site  fi eld, open the second dropdown for the siteMetadata  fi eld (the blue one). This corresponds to the siteMetadata object in your gatsby-con fi g.js  fi le.
  • 28. 4. Query for Data with GraphQL Task: Use useStaticQuery to pull the site title into the Layout component Import the useStaticQuery function and the graphql tag from the Gatsby package.
  • 29. 4. Query for Data with GraphQL Task: Use useStaticQuery to pull the site title into the Layout component Call useStaticQuery and pass it the query you created in GraphiQL. Be sure to use the graphql tag so Gatsby knows that the string you’re passing in is a GraphQL query. Store the return value from useStaticQuery in a variable.
  • 30. 4. Query for Data with GraphQL Task: Use useStaticQuery to pull the site title into the Layout component Now that you have a variable with the results of your query, you can render the title of your site in the JSX for your Layout component. 
  • 31. 4. Query for Data with GraphQL Task: Create a new blog page Create a new fi le: src/pages/blog.js. De fi ne and export a new page component for your blog page. Use your existing Layout component to add some basic structure.
  • 32. 4. Query for Data with GraphQL Task: Create a new blog page Add a link to your new blog page to the navigation bar in your Layout component:
  • 33. 4. Query for Data with GraphQL Task: Create some MDX blog posts • Create a new directory called blog at the top level of your project folder. • Create three new fi les in the blog directory: one for each post.
  • 34. 4. Query for Data with GraphQL Task: Use GraphiQL to build the query • Now that you have some posts saved to your local fi lesystem, it’s time to pull those fi les into the Gatsby data layer. To do that, you’ll use a plugin called gatsby-source- fi lesystem. • Con fi gure gatsby-source- fi lesystem in your gatsby-con fi g.js  fi le. Since gatsby-source- fi lesystem requires some additional con fi guration options, you’ll use a con fi guration object instead of a string. The code example below shows how to “source” fi les from your blog directory (in other words, how to add them to the data layer).
  • 35. 4. Query for Data with GraphQL Task: Use GraphiQL to build the query • Restart your local development server to make sure it picks up the con fi guration changes and adds your fi les to the data layer. • You can use the allFile  fi eld to request data about multiple fi les at once. In GraphiQL, try exploring the different fi elds within allFile to see what sorts of data you get back. Then build a query using the allFile  fi eld to get the name of all the fi les in your blog folder:
  • 36. 4. Query for Data with GraphQL Task: Use a page query to pull the list of post fi lenames into your blog page Import the graphql tag from the Gatsby package.
  • 37. 4. Query for Data with GraphQL Task: Use a page query to pull the list of post fi lenames into your blog page De fi ne and export your page query. Copy over the query you built in GraphiQL
  • 38. 4. Query for Data with GraphQL Task: Use a page query to pull the list of post fi lenames into your blog page Add in the data prop to the function de fi nition.
  • 39. 5. Transform Data to Use MDX
  • 40. 4. Query for Data with GraphQL Some example posts that you can use for inspiration:
  • 41. 4. Query for Data with GraphQL Render each post’s contents on the Blog page Now that you have some MDX content inside your blog posts, it’s time set up the gatsby-plugin-mdx transformer plugin. The gatsby-plugin-mdx plugin provides some new tools for you to use in your site: • The allMdx and mdx  fi elds (for your GraphQL queries) • An MDXRenderer component (for processing and displaying MDX content)
  • 42. 4. Query for Data with GraphQL Task: Install and con fi gure the MDX transformer plugin (and dependencies) npm install gatsby-plugin-mdx @mdx-js/mdx @mdx-js/react
  • 43. 4. Query for Data with GraphQL Task: Update the Blog page query to use the allMdx  fi eld instead of allFile
  • 44. 4. Query for Data with GraphQL Task: Use the MDXRenderer component to render your post’s contents in your Blog page
  • 45. 4. Query for Data with GraphQL Task: Use the MDXRenderer component to render your post’s contents in your Blog page Next, update the JSX for your Blog page to use the data fi elds of your response. Start by rendering just the title and date for each post.
  • 46. 4. Query for Data with GraphQL Task: Use the MDXRenderer component to render your post’s contents in your Blog page The fi nal step in this part of the Tutorial is to render the actual contents of your MDX blog posts. To do that, you’ll need to use a component from gatsby-plugin-mdx called MDXRenderer. Start by importing the component into your Blog page:
  • 47. 4. Query for Data with GraphQL Task: Use the MDXRenderer component to render your post’s contents in your Blog page In the JSX for your Blog page, use the MDXRenderer component to wrap the contents of the body  fi eld for each node:
  • 49. Gatsby cons Don’t use Gatsby if: • There will be a lot of content – for example, if it’s a large blog, generating a static website can take up to 15 minutes. However, for those using Gatsby Cloud, there is a solution called Incremental Builds which shortens build time up to 1000x, but it’s not free (cost starts from $19/ month) • You need to update content a lot – because those updates won’t be visible instantly as in, for example, WordPress • It’s a corporate-size webshop – this point is similar to the fi rst one because the more content you have, the longer the build time will be. Although the solution is Gatsby cloud, fi rst of all, you have to pay for this, and second of all, any updates still won’t be visible right away