SlideShare a Scribd company logo
1 of 50
Download to read offline
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 🤍

More Related Content

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

Using the WordPress REST API and Gatsby.js
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
 
Harness The Power Of ACF For Gatsby and WordPress
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
 
Build Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyImran Sayed
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05Mani Chaubey
 
Top 8 react static site generators for 2020
Top 8 react static site generators for 2020Top 8 react static site generators for 2020
Top 8 react static site generators for 2020Katy Slemon
 
Untangling spring week5
Untangling spring week5Untangling spring week5
Untangling spring week5Derek Jacoby
 
Top React Static Site Generators for 2022.pdf
Top React Static Site Generators for 2022.pdfTop React Static Site Generators for 2022.pdf
Top React Static Site Generators for 2022.pdfKaty Slemon
 
GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0Tobias Meixner
 
JAMstack with gatsby, contentful and netlify aka the dream stack
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 stackzonathen
 
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...
Build Your Blazing Fast Site with Gatsby and WordPress @ WordSesh by Muhammad...rtCamp
 
Pre-render Blazor WebAssembly on static web hosting at publishing time
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 timeJun-ichi Sakamoto
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05Vivek chan
 
Contentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshopContentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshopIvo Lukac
 
Cis363 a all ilabs devry university
Cis363 a all ilabs devry universityCis363 a all ilabs devry university
Cis363 a all ilabs devry universityCIS363A
 
Cis363 all i labs devry university
Cis363 all i labs devry universityCis363 all i labs devry university
Cis363 all i labs devry universityjkkjhdy798iyi
 
Cis363 all i labs devry university
Cis363 all i labs devry universityCis363 all i labs devry university
Cis363 all i labs devry universityCIS363A
 
Cis363 a all ilabs devry university
Cis363 a all ilabs devry universityCis363 a all ilabs devry university
Cis363 a all ilabs devry universityCIS363A
 
Page object from the ground up.ppt
Page object from the ground up.pptPage object from the ground up.ppt
Page object from the ground up.pptJoseph Beale
 

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

Using the WordPress REST API and Gatsby.js
Using the WordPress REST API and Gatsby.jsUsing the WordPress REST API and Gatsby.js
Using the WordPress REST API and Gatsby.js
 
Harness The Power Of ACF For Gatsby and WordPress
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
 
Build Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With Gatsby
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05
 
Top 8 react static site generators for 2020
Top 8 react static site generators for 2020Top 8 react static site generators for 2020
Top 8 react static site generators for 2020
 
Untangling spring week5
Untangling spring week5Untangling spring week5
Untangling spring week5
 
Top React Static Site Generators for 2022.pdf
Top React Static Site Generators for 2022.pdfTop React Static Site Generators for 2022.pdf
Top React Static Site Generators for 2022.pdf
 
GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0
 
JAMstack with gatsby, contentful and netlify aka the dream stack
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
 
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...
Build Your Blazing Fast Site with Gatsby and WordPress @ WordSesh by Muhammad...
 
Pre-render Blazor WebAssembly on static web hosting at publishing time
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
 
Meetup gitbook
Meetup gitbookMeetup gitbook
Meetup gitbook
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05
 
Contentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshopContentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshop
 
Cis363 a all ilabs devry university
Cis363 a all ilabs devry universityCis363 a all ilabs devry university
Cis363 a all ilabs devry university
 
Cis363 all i labs devry university
Cis363 all i labs devry universityCis363 all i labs devry university
Cis363 all i labs devry university
 
Cis363 all i labs devry university
Cis363 all i labs devry universityCis363 all i labs devry university
Cis363 all i labs devry university
 
Cis363 a all ilabs devry university
Cis363 a all ilabs devry universityCis363 a all ilabs devry university
Cis363 a all ilabs devry university
 
Gatsby intro
Gatsby introGatsby intro
Gatsby intro
 
Page object from the ground up.ppt
Page object from the ground up.pptPage object from the ground up.ppt
Page object from the ground up.ppt
 

More from OdessaFrontend

Викторина | Odessa Frontend Meetup #19
Викторина | Odessa Frontend Meetup #19Викторина | Odessa Frontend Meetup #19
Викторина | Odessa Frontend Meetup #19OdessaFrontend
 
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...OdessaFrontend
 
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...OdessaFrontend
 
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18OdessaFrontend
 
Викторина | Odessa Frontend Meetup #17
Викторина | Odessa Frontend Meetup #17Викторина | Odessa Frontend Meetup #17
Викторина | Odessa Frontend Meetup #17OdessaFrontend
 
Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17OdessaFrontend
 
Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17
Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17
Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17OdessaFrontend
 
OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17
OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17
OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17OdessaFrontend
 
Объекты в ECMAScript | Odessa Frontend Meetup #16
Объекты в ECMAScript | Odessa Frontend Meetup #16Объекты в ECMAScript | Odessa Frontend Meetup #16
Объекты в ECMAScript | Odessa Frontend Meetup #16OdessaFrontend
 
Фриланс как профессиональная деградация | Odessa Frontend Meetup #16
Фриланс как профессиональная деградация | Odessa Frontend Meetup #16Фриланс как профессиональная деградация | Odessa Frontend Meetup #16
Фриланс как профессиональная деградация | Odessa Frontend Meetup #16OdessaFrontend
 
Cлайдер на CSS | Odessa Frontend Meetup #16
Cлайдер на CSS | Odessa Frontend Meetup #16Cлайдер на CSS | Odessa Frontend Meetup #16
Cлайдер на CSS | Odessa Frontend Meetup #16OdessaFrontend
 
Современный станок верстальщика
Современный станок верстальщикаСовременный станок верстальщика
Современный станок верстальщикаOdessaFrontend
 
Викторина | Odessa Frontend Meetup #15
Викторина | Odessa Frontend Meetup #15Викторина | Odessa Frontend Meetup #15
Викторина | Odessa Frontend Meetup #15OdessaFrontend
 
DRY’им Vuex | Odessa Frontend Meetup #15
DRY’им Vuex | Odessa Frontend Meetup #15DRY’им Vuex | Odessa Frontend Meetup #15
DRY’им Vuex | Odessa Frontend Meetup #15OdessaFrontend
 
А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15
А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15
А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15OdessaFrontend
 
Пощупать 3д в браузере | Odessa Frontend Meetup #15
Пощупать 3д в браузере | Odessa Frontend Meetup #15Пощупать 3д в браузере | Odessa Frontend Meetup #15
Пощупать 3д в браузере | Odessa Frontend Meetup #15OdessaFrontend
 
Викторина | Odessa Frontend Meetup #14
Викторина | Odessa Frontend Meetup #14Викторина | Odessa Frontend Meetup #14
Викторина | Odessa Frontend Meetup #14OdessaFrontend
 
Викторина | Odessa Frontend Meetup #13
Викторина | Odessa Frontend Meetup #13Викторина | Odessa Frontend Meetup #13
Викторина | Odessa Frontend Meetup #13OdessaFrontend
 
Структуры данных в JavaScript | Odessa Frontend Meetup #13
Структуры данных в JavaScript | Odessa Frontend Meetup #13Структуры данных в JavaScript | Odessa Frontend Meetup #13
Структуры данных в JavaScript | Odessa Frontend Meetup #13OdessaFrontend
 
Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13
Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13
Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13OdessaFrontend
 

More from OdessaFrontend (20)

Викторина | Odessa Frontend Meetup #19
Викторина | Odessa Frontend Meetup #19Викторина | Odessa Frontend Meetup #19
Викторина | Odessa Frontend Meetup #19
 
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...
Использование Recoil в React и React Native приложениях | Odessa Frontend Mee...
 
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...
Функциональное программирование с использованием библиотеки fp-ts | Odessa Fr...
 
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18
Canvas API как инструмент для работы с графикой | Odessa Frontend Meetup #18
 
Викторина | Odessa Frontend Meetup #17
Викторина | Odessa Frontend Meetup #17Викторина | Odessa Frontend Meetup #17
Викторина | Odessa Frontend Meetup #17
 
Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17
 
Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17
Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17
Частые ошибки при разработке фронтенда | Odessa Frontend Meetup #17
 
OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17
OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17
OAuth2 и OpenID Connect простым языком | Odessa Frontend Meetup #17
 
Объекты в ECMAScript | Odessa Frontend Meetup #16
Объекты в ECMAScript | Odessa Frontend Meetup #16Объекты в ECMAScript | Odessa Frontend Meetup #16
Объекты в ECMAScript | Odessa Frontend Meetup #16
 
Фриланс как профессиональная деградация | Odessa Frontend Meetup #16
Фриланс как профессиональная деградация | Odessa Frontend Meetup #16Фриланс как профессиональная деградация | Odessa Frontend Meetup #16
Фриланс как профессиональная деградация | Odessa Frontend Meetup #16
 
Cлайдер на CSS | Odessa Frontend Meetup #16
Cлайдер на CSS | Odessa Frontend Meetup #16Cлайдер на CSS | Odessa Frontend Meetup #16
Cлайдер на CSS | Odessa Frontend Meetup #16
 
Современный станок верстальщика
Современный станок верстальщикаСовременный станок верстальщика
Современный станок верстальщика
 
Викторина | Odessa Frontend Meetup #15
Викторина | Odessa Frontend Meetup #15Викторина | Odessa Frontend Meetup #15
Викторина | Odessa Frontend Meetup #15
 
DRY’им Vuex | Odessa Frontend Meetup #15
DRY’им Vuex | Odessa Frontend Meetup #15DRY’им Vuex | Odessa Frontend Meetup #15
DRY’им Vuex | Odessa Frontend Meetup #15
 
А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15
А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15
А/Б тестирование: Что? Как? Зачем? | Odessa Frontend Meetup #15
 
Пощупать 3д в браузере | Odessa Frontend Meetup #15
Пощупать 3д в браузере | Odessa Frontend Meetup #15Пощупать 3д в браузере | Odessa Frontend Meetup #15
Пощупать 3д в браузере | Odessa Frontend Meetup #15
 
Викторина | Odessa Frontend Meetup #14
Викторина | Odessa Frontend Meetup #14Викторина | Odessa Frontend Meetup #14
Викторина | Odessa Frontend Meetup #14
 
Викторина | Odessa Frontend Meetup #13
Викторина | Odessa Frontend Meetup #13Викторина | Odessa Frontend Meetup #13
Викторина | Odessa Frontend Meetup #13
 
Структуры данных в JavaScript | Odessa Frontend Meetup #13
Структуры данных в JavaScript | Odessa Frontend Meetup #13Структуры данных в JavaScript | Odessa Frontend Meetup #13
Структуры данных в JavaScript | Odessa Frontend Meetup #13
 
Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13
Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13
Эффективность с большой буквы Э… или любой другой | Odessa Frontend Meetup #13
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Великолепный 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