{"id":372514,"date":"2024-05-21T05:14:20","date_gmt":"2024-05-21T05:14:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=372514"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T05:14:20","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=372514","title":{"rendered":"<span>Gatsby and its Greatness<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>I\u2019m Aleksei Volkov, a front-end engineer at\u00a0<a href=\"https:\/\/www.linkedin.com\/company\/luxoft-serbia\/\" rel=\"noopener noreferrer nofollow\">Luxoft<\/a>. Our clients often present new requirements, but our focus remains on cost savings. A single application can replace days of bureaucracy, and a single line of code can carry a hefty price tag.<\/p>\n<p>As part of my role, I prioritize choosing the right tools. To tackle server-related expenses, AWS bills, and Google FCP metrics, I\u2019ve delved into serverless technologies. My preferred way to showcase achievements? Blogging.<\/p>\n<hr\/>\n<h4>The Evolution of\u00a0Blogging<\/h4>\n<p>In the internet\u2019s early days, blogging was straightforward. A server with PHP and MySQL allowed you to share your thoughts globally. Even FTP access with an\u00a0<em>index.html<\/em>\u00a0file sufficed.<\/p>\n<p>However, as the web evolved, so did blogging requirements. Non-programmers needed user-friendly web interfaces, faster loading times, and seamless daily publishing. Platforms like Reddit, WordPress, and Tumblr emerged, but they faced a common issue: website ownership.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b1f\/bc5\/dd3\/b1fbc5dd3faa58c793196a6107b8de61.png\" alt=\"LinkedIn load up to 30 MB of JavaScript\" width=\"1600\" height=\"1250\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b1f\/bc5\/dd3\/b1fbc5dd3faa58c793196a6107b8de61.png\"\/><\/p>\n<div><figcaption>LinkedIn load up to 30 MB of JavaScript<\/figcaption><\/div>\n<\/figure>\n<p>Today, hosting a basic blog still requires purchasing MySQL and PHP hosting. Notably, popular personal sites like\u00a0<a href=\"https:\/\/tonsky.me\/blog\/js-bloat\/\" rel=\"noopener noreferrer nofollow\">LinkedIn load up to 30 MB of JavaScript<\/a>. But is there a simpler, nearly free way? Can we publish weekly serving just an HTML file and using a WYSIWYG editor? ?<\/p>\n<hr\/>\n<h4>A New Way of Storing and Distributing Content<\/h4>\n<p><a href=\"https:\/\/www.sanity.io\/\" rel=\"noopener noreferrer nofollow\"><strong>Sanity IO<\/strong><\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9d2\/373\/95c\/9d237395ca06f05aa26df68057437d7f.png\" alt=\"Sanity Editor\" width=\"1600\" height=\"1250\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d2\/373\/95c\/9d237395ca06f05aa26df68057437d7f.png\"\/><\/p>\n<div><figcaption>Sanity Editor<\/figcaption><\/div>\n<\/figure>\n<p><strong>Sanity IO<\/strong>\u00a0is a\u00a0<strong>headless CMS<\/strong>\u00a0that empowers you to create and host content exclusively under your control. Here\u2019s what makes it stand out:<\/p>\n<ol>\n<li>\n<p><strong>Customizable WYSIWYG<\/strong>: The WYSIWYG (What You See Is What You Get) editor is fully configurable. You decide how your content appears to your audience.<\/p>\n<\/li>\n<li>\n<p><strong>Portable Text<\/strong>: A novel way of distributing content, similar to old-school HTML. You create content blocks in the editor, and then these blocks can be rendered differently by various frontends based on their values and parameters.<\/p>\n<\/li>\n<li>\n<p><strong>Export and Import<\/strong>: Seamlessly move your content in and out of Sanity IO.<\/p>\n<\/li>\n<\/ol>\n<p>In essence, Sanity IO liberates content creators, developers, and users by providing a flexible and tailored content management experience.<\/p>\n<p><a href=\"https:\/\/www.gatsbyjs.com\/\" rel=\"noopener noreferrer nofollow\"><strong>GatsbyJS<\/strong><\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f9e\/b27\/529\/f9eb275291d9e9c89ee55e76e760e6b1.png\" alt=\"Gatsby deploy\" width=\"1600\" height=\"1421\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f9e\/b27\/529\/f9eb275291d9e9c89ee55e76e760e6b1.png\"\/><\/p>\n<div><figcaption>Gatsby deploy<\/figcaption><\/div>\n<\/figure>\n<p><strong>GatsbyJS<\/strong>\u00a0is a powerful\u00a0<strong>static site generator<\/strong>\u00a0that streamlines web development. Here\u2019s why it\u2019s a game-changer for bloggers and writers:<\/p>\n<ol>\n<li>\n<p><strong>Static HTML\/CSS\/JS Bundle<\/strong>: Gatsby fetches data, styles, and logic during the build process and compiles them into static files. Your blog becomes a collection of lightweight, pre-rendered pages, reducing server load and enhancing loading speed for readers.<\/p>\n<\/li>\n<li>\n<p><strong>Magic of Build Time<\/strong>: Similar to NextJS or server-side rendering techniques, Gatsby performs its magic during the build phase. When a user visits your site, their browser reads only the HTML and CSS\u200a\u2014\u200ano server-side processing required.<\/p>\n<\/li>\n<li>\n<p><strong>Perfect for Static Sites<\/strong>: Whether you\u2019re a blogger, writer, or running a content-focused site, Gatsby is an ideal choice. Plus, it plays well with GitHub Pages.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<h4>Installation and Configuration<\/h4>\n<p><strong>Sanity IO<\/strong><\/p>\n<ol>\n<li>\n<p><strong>Sign Up<\/strong>: Create an account on Sanity IO.<\/p>\n<\/li>\n<li>\n<p><strong>Project Creation<\/strong>: Set up a new project.<\/p>\n<\/li>\n<li>\n<p><strong>Schema Configuration<\/strong>: Define your content schema.<\/p>\n<\/li>\n<li>\n<p><strong>Start Creating<\/strong>: With everything set up, dive into content creation right away!<\/p>\n<\/li>\n<\/ol>\n<p>To get started, visit the\u00a0<a href=\"https:\/\/www.sanity.io\/headless-cms\" rel=\"noopener noreferrer nofollow\">Sanity documentation<\/a>\u00a0and install the command-line interface and Sanity Studio.<\/p>\n<pre><code class=\"bash\">npm install - global sanity@latest<\/code><\/pre>\n<p>Additionally, consider installing\u00a0<a href=\"https:\/\/www.npmjs.com\/package\/@sanity\/code-input\" rel=\"noopener noreferrer nofollow\"><em>@sanity\/code-input<\/em><\/a>\u00a0for pasting code examples.<\/p>\n<p>So your\u00a0<em>sanity.config.ts<\/em>\u00a0would be like next example. Rest plugins are not needed for now.<\/p>\n<pre><code class=\"typescript\">\/\/ sanity.config.ts import {structureTool} from 'sanity\/structure' import {schemaTypes} from '.\/schemaTypes' import {codeInput} from '@sanity\/code-input'  export default {   name: 'default',   title: 'My Sanity Project',    projectId: 'odwqzjob',   dataset: 'production',    plugins: [structureTool(), codeInput()],    schema: {     types: schemaTypes,   }, }<\/code><\/pre>\n<p>Hit\u00a0<em>npm run deploy<\/em>\u00a0to get an online Editor for your content (local writing is also possible). And finally\u00a0<em>npm run deploy-graphql<\/em>\u00a0to publish api for frontend part.<\/p>\n<p><strong>GatsbyJS<\/strong><\/p>\n<p>GatsbyJS requires a bit more setup. You\u2019ll need to install the Gatsby CLI, create a new site, and then configure your sources and plugins. However, once you\u2019ve done that, you can start building your site.<\/p>\n<p>Start with\u00a0<a href=\"https:\/\/www.gatsbyjs.com\/docs\/quick-start\/\" rel=\"noopener noreferrer nofollow\">documentation<\/a>\u00a0and install command line interface for GatsbyJS. For minimal start it\u2019s needed to configure main page, config file and single blog post file.<\/p>\n<pre><code class=\"bash\">npm init gatsby cd my-gatsby-site npm run develop<\/code><\/pre>\n<p>GatsbyJS uses GraphQL to fetch data, so use it to get sanity posts. Do the same for single post, but also get _rawBody field which represents Portable Text. It can be rendered with official plugin. Then, the only task is left is making post pages on build time\u200a\u2014\u200aso configure gatsby-node.ts.<\/p>\n<pre><code class=\"typescript\">\/\/ index.tsx import { HeadFC, PageProps, graphql } from \"gatsby\"; import React from \"react\";  function IndexPage({ data }: PageProps&lt;Queries.ArticlesQuery>) {   const articles = data.allSanityPost.nodes;   return (     &lt;div>       &lt;h1>Home Page&lt;\/h1>       &lt;ul>         {articles.map((article) => (           &lt;li key={article.id}>             &lt;a href={article.slug?.current}>{article.title}&lt;\/a> (             {article.publishedAt})           &lt;\/li>         ))}       &lt;\/ul>     &lt;\/div>   ); }  export default IndexPage;  export const Head: HeadFC = () => &lt;title>Home Page&lt;\/title>;  export const articlesQuery = graphql`   query Articles {     allSanityPost(sort: { publishedAt: DESC }, limit: 100) {       nodes {         slug {           current         }         title         id         publishedAt(formatString: \"DD.MM.YYYY\")       }     }   } `;<\/code><\/pre>\n<pre><code class=\"typescript\">\/\/ Post.tsx import * as React from \"react\"; import { graphql, Link, type HeadProps, HeadFC } from \"gatsby\"; import { PortableText } from \"@portabletext\/react\"; import type { PortableTextBlock } from \"@portabletext\/types\";  import portableTextComponents from \"..\/utils\/portableText\";  function Post({ data }: { data: Queries.PostQuery }) {   const post = data?.sanityPost;    if (post == null) {     return (       &lt;p>         Post not found. Go &lt;Link to=\"\/\">to home page&lt;\/Link>.       &lt;\/p>     );   }    return (     &lt;article>       &lt;header>         &lt;h1>{post.title}&lt;\/h1>         &lt;p>           &lt;time dateTime={post.publishedAt}>{post.publishedAt}&lt;\/time>         &lt;\/p>       &lt;\/header>       &lt;main>         {post._rawBody != null &amp;&amp; (           &lt;PortableText             value={post._rawBody as unknown as PortableTextBlock[]}             components={portableTextComponents}           \/>         )}       &lt;\/main>     &lt;\/article>   ); }  export default Post;  export const Head = ({ data }: HeadProps&lt;Queries.PostQuery>) => {   const postTitle = data.sanityPost?.title ?? \"\";    return &lt;title>{postTitle}&lt;\/title>; };  export const PostQuery = graphql`   query Post($slug: String!) {     sanityPost(slug: { current: { eq: $slug } }) {       id       title       publishedAt(formatString: \"DD.MM.YYYY\")       _rawBody     }   } `;<\/code><\/pre>\n<pre><code class=\"typescript\">\/\/ gatsby-node.ts import { type CreatePagesArgs, type GatsbyNode } from \"gatsby\"; import path from \"path\";  async function turnPostsIntoPages({   graphql,   actions, }: CreatePagesArgs): Promise&lt;void> {   \/\/ 1. Get a template for this page   const postTemplate = path.resolve(\".\/src\/templates\/Post.tsx\");   \/\/ 2. Query all posts   const {     data,   }: {     data?: {       allSanityPost: {         nodes;       };     };   } = await graphql(`     query AllPosts {       allSanityPost(sort: { publishedAt: DESC }, limit: 100) {         nodes {           title           slug {             current           }         }       }     }   `);    const posts = data?.allSanityPost?.nodes ?? [];   \/\/ 3. Loop over each post and create a page for that post   posts.forEach(function createPostPage(post) {     console.log(\"? Creating page for Article:\", post.title);     actions.createPage({       path: post.slug.current,       component: postTemplate,       context: {         slug: post.slug.current,       },     });   }); }  export const createPages: GatsbyNode[\"createPages\"] =   async function createPages(params) {     Promise.all([turnPostsIntoPages(params)])       .then(function logSuccess() {         console.log(\"\u2705 Finished creating pages.\");       })       .catch(function logError(error) {         console.error(\"\u274c Failed to create pages:\", error);       });   };<\/code><\/pre>\n<p>Done! You have Sanity Editor in the Internet, now you can publish Gatsby part in GitHub pages of in\u00a0<a href=\"https:\/\/www.netlify.com\/\" rel=\"noopener noreferrer nofollow\">Netlify<\/a>.<\/p>\n<hr\/>\n<h4>Conclusion<\/h4>\n<p>When comparing traditional blogging to static blogging, several key differences emerge.<\/p>\n<ol>\n<li>\n<p><strong>Traditional Blogging<\/strong>:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>Requires a constantly running server, which can be expensive.<\/p>\n<\/li>\n<li>\n<p>Involves fetching requests in React, potentially slowing down your site.<\/p>\n<\/li>\n<\/ul>\n<ol>\n<li>\n<p><strong>Static Blogging with Sanity IO and GatsbyJS<\/strong>:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>Eliminates the need for an always-on server.<\/p>\n<\/li>\n<li>\n<p>Stores content in a headless CMS and serves it as static files, reducing costs and improving load speed.<\/p>\n<\/li>\n<\/ul>\n<p>In 2024, services like Sanity IO and GatsbyJS empower content creators by offering database services, full content control, and zero-cost hosting for static HTML files. Why not give it a try? Create a Gatsby website today, fetch your existing data, and stay tuned for more insights from Luxoft! ?<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/804783\/\"> https:\/\/habr.com\/ru\/articles\/804783\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>I\u2019m Aleksei Volkov, a front-end engineer at\u00a0<a href=\"https:\/\/www.linkedin.com\/company\/luxoft-serbia\/\" rel=\"noopener noreferrer nofollow\">Luxoft<\/a>. Our clients often present new requirements, but our focus remains on cost savings. A single application can replace days of bureaucracy, and a single line of code can carry a hefty price tag.<\/p>\n<p>As part of my role, I prioritize choosing the right tools. To tackle server-related expenses, AWS bills, and Google FCP metrics, I\u2019ve delved into serverless technologies. My preferred way to showcase achievements? Blogging.<\/p>\n<hr\/>\n<h4>The Evolution of\u00a0Blogging<\/h4>\n<p>In the internet\u2019s early days, blogging was straightforward. A server with PHP and MySQL allowed you to share your thoughts globally. Even FTP access with an\u00a0<em>index.html<\/em>\u00a0file sufficed.<\/p>\n<p>However, as the web evolved, so did blogging requirements. Non-programmers needed user-friendly web interfaces, faster loading times, and seamless daily publishing. Platforms like Reddit, WordPress, and Tumblr emerged, but they faced a common issue: website ownership.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>LinkedIn load up to 30 MB of JavaScript<\/figcaption><\/div>\n<\/figure>\n<p>Today, hosting a basic blog still requires purchasing MySQL and PHP hosting. Notably, popular personal sites like\u00a0<a href=\"https:\/\/tonsky.me\/blog\/js-bloat\/\" rel=\"noopener noreferrer nofollow\">LinkedIn load up to 30 MB of JavaScript<\/a>. But is there a simpler, nearly free way? Can we publish weekly serving just an HTML file and using a WYSIWYG editor? ?<\/p>\n<hr\/>\n<h4>A New Way of Storing and Distributing Content<\/h4>\n<p><a href=\"https:\/\/www.sanity.io\/\" rel=\"noopener noreferrer nofollow\"><strong>Sanity IO<\/strong><\/a><\/p>\n<figure class=\"full-width\">\n<div><figcaption>Sanity Editor<\/figcaption><\/div>\n<\/figure>\n<p><strong>Sanity IO<\/strong>\u00a0is a\u00a0<strong>headless CMS<\/strong>\u00a0that empowers you to create and host content exclusively under your control. Here\u2019s what makes it stand out:<\/p>\n<ol>\n<li>\n<p><strong>Customizable WYSIWYG<\/strong>: The WYSIWYG (What You See Is What You Get) editor is fully configurable. You decide how your content appears to your audience.<\/p>\n<\/li>\n<li>\n<p><strong>Portable Text<\/strong>: A novel way of distributing content, similar to old-school HTML. You create content blocks in the editor, and then these blocks can be rendered differently by various frontends based on their values and parameters.<\/p>\n<\/li>\n<li>\n<p><strong>Export and Import<\/strong>: Seamlessly move your content in and out of Sanity IO.<\/p>\n<\/li>\n<\/ol>\n<p>In essence, Sanity IO liberates content creators, developers, and users by providing a flexible and tailored content management experience.<\/p>\n<p><a href=\"https:\/\/www.gatsbyjs.com\/\" rel=\"noopener noreferrer nofollow\"><strong>GatsbyJS<\/strong><\/a><\/p>\n<figure class=\"full-width\">\n<div><figcaption>Gatsby deploy<\/figcaption><\/div>\n<\/figure>\n<p><strong>GatsbyJS<\/strong>\u00a0is a powerful\u00a0<strong>static site generator<\/strong>\u00a0that streamlines web development. Here\u2019s why it\u2019s a game-changer for bloggers and writers:<\/p>\n<ol>\n<li>\n<p><strong>Static HTML\/CSS\/JS Bundle<\/strong>: Gatsby fetches data, styles, and logic during the build process and compiles them into static files. Your blog becomes a collection of lightweight, pre-rendered pages, reducing server load and enhancing loading speed for readers.<\/p>\n<\/li>\n<li>\n<p><strong>Magic of Build Time<\/strong>: Similar to NextJS or server-side rendering techniques, Gatsby performs its magic during the build phase. When a user visits your site, their browser reads only the HTML and CSS\u200a\u2014\u200ano server-side processing required.<\/p>\n<\/li>\n<li>\n<p><strong>Perfect for Static Sites<\/strong>: Whether you\u2019re a blogger, writer, or running a content-focused site, Gatsby is an ideal choice. Plus, it plays well with GitHub Pages.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<h4>Installation and Configuration<\/h4>\n<p><strong>Sanity IO<\/strong><\/p>\n<ol>\n<li>\n<p><strong>Sign Up<\/strong>: Create an account on Sanity IO.<\/p>\n<\/li>\n<li>\n<p><strong>Project Creation<\/strong>: Set up a new project.<\/p>\n<\/li>\n<li>\n<p><strong>Schema Configuration<\/strong>: Define your content schema.<\/p>\n<\/li>\n<li>\n<p><strong>Start Creating<\/strong>: With everything set up, dive into content creation right away!<\/p>\n<\/li>\n<\/ol>\n<p>To get started, visit the\u00a0<a href=\"https:\/\/www.sanity.io\/headless-cms\" rel=\"noopener noreferrer nofollow\">Sanity documentation<\/a>\u00a0and install the command-line interface and Sanity Studio.<\/p>\n<pre><code class=\"bash\">npm install - global sanity@latest<\/code><\/pre>\n<p>Additionally, consider installing\u00a0<a href=\"https:\/\/www.npmjs.com\/package\/@sanity\/code-input\" rel=\"noopener noreferrer nofollow\"><em>@sanity\/code-input<\/em><\/a>\u00a0for pasting code examples.<\/p>\n<p>So your\u00a0<em>sanity.config.ts<\/em>\u00a0would be like next example. Rest plugins are not needed for now.<\/p>\n<pre><code class=\"typescript\">\/\/ sanity.config.ts import {structureTool} from 'sanity\/structure' import {schemaTypes} from '.\/schemaTypes' import {codeInput} from '@sanity\/code-input'  export default {   name: 'default',   title: 'My Sanity Project',    projectId: 'odwqzjob',   dataset: 'production',    plugins: [structureTool(), codeInput()],    schema: {     types: schemaTypes,   }, }<\/code><\/pre>\n<p>Hit\u00a0<em>npm run deploy<\/em>\u00a0to get an online Editor for your content (local writing is also possible). And finally\u00a0<em>npm run deploy-graphql<\/em>\u00a0to publish api for frontend part.<\/p>\n<p><strong>GatsbyJS<\/strong><\/p>\n<p>GatsbyJS requires a bit more setup. You\u2019ll need to install the Gatsby CLI, create a new site, and then configure your sources and plugins. However, once you\u2019ve done that, you can start building your site.<\/p>\n<p>Start with\u00a0<a href=\"https:\/\/www.gatsbyjs.com\/docs\/quick-start\/\" rel=\"noopener noreferrer nofollow\">documentation<\/a>\u00a0and install command line interface for GatsbyJS. For minimal start it\u2019s needed to configure main page, config file and single blog post file.<\/p>\n<pre><code class=\"bash\">npm init gatsby cd my-gatsby-site npm run develop<\/code><\/pre>\n<p>GatsbyJS uses GraphQL to fetch data, so use it to get sanity posts. Do the same for single post, but also get _rawBody field which represents Portable Text. It can be rendered with official plugin. Then, the only task is left is making post pages on build time\u200a\u2014\u200aso configure gatsby-node.ts.<\/p>\n<pre><code class=\"typescript\">\/\/ index.tsx import { HeadFC, PageProps, graphql } from \"gatsby\"; import React from \"react\";  function IndexPage({ data }: PageProps&lt;Queries.ArticlesQuery>) {   const articles = data.allSanityPost.nodes;   return (     &lt;div>       &lt;h1>Home Page&lt;\/h1>       &lt;ul>         {articles.map((article) => (           &lt;li key={article.id}>             &lt;a href={article.slug?.current}>{article.title}&lt;\/a> (             {article.publishedAt})           &lt;\/li>         ))}       &lt;\/ul>     &lt;\/div>   ); }  export default IndexPage;  export const Head: HeadFC = () => &lt;title>Home Page&lt;\/title>;  export const articlesQuery = graphql`   query Articles {     allSanityPost(sort: { publishedAt: DESC }, limit: 100) {       nodes {         slug {           current         }         title         id         publishedAt(formatString: \"DD.MM.YYYY\")       }     }   } `;<\/code><\/pre>\n<pre><code class=\"typescript\">\/\/ Post.tsx import * as React from \"react\"; import { graphql, Link, type HeadProps, HeadFC } from \"gatsby\"; import { PortableText } from \"@portabletext\/react\"; import type { PortableTextBlock } from \"@portabletext\/types\";  import portableTextComponents from \"..\/utils\/portableText\";  function Post({ data }: { data: Queries.PostQuery }) {   const post = data?.sanityPost;    if (post == null) {     return (       &lt;p>         Post not found. Go &lt;Link to=\"\/\">to home page&lt;\/Link>.       &lt;\/p>     );   }    return (     &lt;article>       &lt;header>         &lt;h1>{post.title}&lt;\/h1>         &lt;p>           &lt;time dateTime={post.publishedAt}>{post.publishedAt}&lt;\/time>         &lt;\/p>       &lt;\/header>       &lt;main>         {post._rawBody != null &amp;&amp; (           &lt;PortableText             value={post._rawBody as unknown as PortableTextBlock[]}             components={portableTextComponents}           \/>         )}       &lt;\/main>     &lt;\/article>   ); }  export default Post;  export const Head = ({ data }: HeadProps&lt;Queries.PostQuery>) => {   const postTitle = data.sanityPost?.title ?? \"\";    return &lt;title>{postTitle}&lt;\/title>; };  export const PostQuery = graphql`   query Post($slug: String!) {     sanityPost(slug: { current: { eq: $slug } }) {       id       title       publishedAt(formatString: \"DD.MM.YYYY\")       _rawBody     }   } `;<\/code><\/pre>\n<pre><code class=\"typescript\">\/\/ gatsby-node.ts import { type CreatePagesArgs, type GatsbyNode } from \"gatsby\"; import path from \"path\";  async function turnPostsIntoPages({   graphql,   actions, }: CreatePagesArgs): Promise&lt;void> {   \/\/ 1. Get a template for this page   const postTemplate = path.resolve(\".\/src\/templates\/Post.tsx\");   \/\/ 2. Query all posts   const {     data,   }: {     data?: {       allSanityPost: {         nodes;       };     };   } = await graphql(`     query AllPosts {       allSanityPost(sort: { publishedAt: DESC }, limit: 100) {         nodes {           title           slug {             current           }         }       }     }   `);    const posts = data?.allSanityPost?.nodes ?? [];   \/\/ 3. Loop over each post and create a page for that post   posts.forEach(function createPostPage(post) {     console.log(\"? Creating page for Article:\", post.title);     actions.createPage({       path: post.slug.current,       component: postTemplate,       context: {         slug: post.slug.current,       },     });   }); }  export const createPages: GatsbyNode[\"createPages\"] =   async function createPages(params) {     Promise.all([turnPostsIntoPages(params)])       .then(function logSuccess() {         console.log(\"\u2705 Finished creating pages.\");       })       .catch(function logError(error) {         console.error(\"\u274c Failed to create pages:\", error);       });   };<\/code><\/pre>\n<p>Done! You have Sanity Editor in the Internet, now you can publish Gatsby part in GitHub pages of in\u00a0<a href=\"https:\/\/www.netlify.com\/\" rel=\"noopener noreferrer nofollow\">Netlify<\/a>.<\/p>\n<hr\/>\n<h4>Conclusion<\/h4>\n<p>When comparing traditional blogging to static blogging, several key differences emerge.<\/p>\n<ol>\n<li>\n<p><strong>Traditional Blogging<\/strong>:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>Requires a constantly running server, which can be expensive.<\/p>\n<\/li>\n<li>\n<p>Involves fetching requests in React, potentially slowing down your site.<\/p>\n<\/li>\n<\/ul>\n<ol>\n<li>\n<p><strong>Static Blogging with Sanity IO and GatsbyJS<\/strong>:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>Eliminates the need for an always-on server.<\/p>\n<\/li>\n<li>\n<p>Stores content in a headless CMS and serves it as static files, reducing costs and improving load speed.<\/p>\n<\/li>\n<\/ul>\n<p>In 2024, services like Sanity IO and GatsbyJS empower content creators by offering database services, full content control, and zero-cost hosting for static HTML files. Why not give it a try? Create a Gatsby website today, fetch your existing data, and stay tuned for more insights from Luxoft! ?<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/804783\/\"> https:\/\/habr.com\/ru\/articles\/804783\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-372514","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/372514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=372514"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/372514\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=372514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=372514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=372514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}