<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Posts tagged #ssg</title><description>The latest posts tagged with ssg on queen.raae.codes</description><link>https://queen.raae.codes/tag/ssg/</link><item><title>🦜 📄 ~ Gatsby Parrot Pages</title><link>https://queen.raae.codes/2022-01-13-parrot-pages/</link><guid isPermaLink="true">https://queen.raae.codes/2022-01-13-parrot-pages/</guid><description>In the sharky waters around the Gatsby islands, we call the File System Route API SSG pages for Parrot Pages 🦜 as mentioned in Tuesday&apos;s email about SSG with…</description><pubDate>Thu, 13 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In the sharky waters around the Gatsby islands, we call the File System Route API SSG pages for Parrot Pages 🦜 as mentioned in Tuesday&apos;s email about &lt;a href=&quot;/2022-01-11-ssg/&quot;&gt;SSG with Gatsby&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./parrot-pages.jpeg&quot; alt=&quot;{} = parrots&quot; title=&quot;Drawing of `src/pages/{YouTube.id}.js` with {} as parrots&quot;&gt;&lt;/p&gt;
&lt;p&gt;Making abstract concepts like that come alive is one of Cap&apos;n Ola Vea&apos;s superpowers.&lt;/p&gt;
&lt;p&gt;Hear him present the naming to Ward Peters of Gatsby &lt;a href=&quot;https://youtu.be/TX5XPuHhz9o?t=3265&quot;&gt;in this live stream&lt;/a&gt; all about Parrot Pages.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/TX5XPuHhz9o?t=3265&quot;&gt;&lt;img src=&quot;./yt-screenshot.jpg&quot; alt=&quot;Screengrab of Ola presenting Parrot Pages&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What imagery would you choose for the &lt;a href=&quot;https://www.gatsbyjs.com/docs/reference/routing/file-system-route-api/#creating-client-only-routes&quot;&gt;File System Route API&lt;/a&gt; square bracket (&lt;code&gt;[]&lt;/code&gt;) pages?&lt;/p&gt;
&lt;p&gt;For a demonstration of both Parrot Pages and square bracket (&lt;code&gt;[]&lt;/code&gt;) pages side-by-side, check out the demo for &lt;a href=&quot;https://codesandbox.io/s/demo-ssr-fallback-route-9pteu?file=/README.md&quot;&gt;SSR Fallback routes with Gatsby&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
All the best,&lt;br&gt;
Queen Raae&lt;/p&gt;
</content:encoded></item><item><title>🔴 👩‍🏫 ~ Static Site Generation (SSG) with Gatsby</title><link>https://queen.raae.codes/2022-01-11-ssg/</link><guid isPermaLink="true">https://queen.raae.codes/2022-01-11-ssg/</guid><description>Static Site Generation (SSG) is Gatsby&apos;s default rendering mode. SSG is the default rendering mode in Gatsby. While the name has the word “static” in it, it…</description><pubDate>Tue, 11 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Static Site Generation (SSG) is Gatsby&apos;s default rendering mode.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;SSG is the default rendering mode in Gatsby. While the name has the word “static” in it, it doesn’t at all mean boring or lifeless. It simply means the entire site is pre-rendered into HTML, CSS, and JavaScript at build time, which then get served as static assets to the browser. Because all of that HTML, CSS, and JS is preprocessed and rendered at build time, Static Site Generation serves websites to users in the fastest possible way—your content is ready to go before the visitor even visits the site. (&lt;a href=&quot;https://www.gatsbyjs.com/docs/conceptual/rendering-options/#static-site-generation-ssg&quot;&gt;Gatsby Docs about Rendering Options&lt;/a&gt;).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.gatsbyjs.com/docs/conceptual/rendering-options/#static-site-generation-ssg&quot;&gt;&lt;img src=&quot;./ssg-diagram.jpg&quot; alt=&quot;SSG Diagram&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;But how do we SSG?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://youtu.be/D_03KW4AkSk&quot;&gt;Watch the Live Screeencast&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;SSG with Gatsby three ways&lt;/h2&gt;
&lt;p&gt;Read more in the &lt;a href=&quot;https://www.gatsbyjs.com/docs/reference/routing/creating-routes/&quot;&gt;Gatsby Docs about Routing&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;1. React component in &lt;code&gt;src/pages&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The file generates a single page with the file&apos;s name as the path.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// src/pages/demo.js

import React from &amp;quot;react&amp;quot;;

const DemoPage = () =&amp;gt; {
  return (
    &amp;lt;main&amp;gt;
      &amp;lt;h1&amp;gt;Static Site Generation (SSG)&amp;lt;/h1&amp;gt;
    &amp;lt;/main&amp;gt;
  );
};

export default DemoPage;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Generates a page at the path &lt;code&gt;/demo/&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;2. File System Route API&lt;/h3&gt;
&lt;p&gt;The file generates a page for each YouTube node in the data layer with the node&apos;s id as the path.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// src/pages/{YouTube.id}.js

import React from &amp;quot;react&amp;quot;;

const YouTubeFileSystemApiPage = () =&amp;gt; {
  return (
    &amp;lt;main&amp;gt;
      &amp;lt;h1&amp;gt;File System Route API Page&amp;lt;/h1&amp;gt;
    &amp;lt;/main&amp;gt;
  );
};

export default YouTubeFileSystemApiPage;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Generates a page at the path &lt;code&gt;/u-gq8cn-n-tbw-i/&lt;/code&gt; for the YouTube node with id: &lt;code&gt;UGq8cnNTbwI&lt;/code&gt;, and similarly for all the other YouTube nodes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;3. &lt;code&gt;createPages&lt;/code&gt; in &lt;code&gt;gatsby-node.js&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The code generates a page for each YouTube node in the data layer with the node&apos;s id as the path using the supplied template. The template will be a file very similar to the file examples above.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// gatsby-node.js

const path = require(`path`);

exports.createPages = async ({graphql, actions}) =&amp;gt; {
  const {createPage} = actions;

  const result = await graphql(`
    {
      allYouTube {
        nodes {
          id
        }
      }
    }
  `);
  const templatePath = path.resolve(`./src/templates/youtube-template.js`);

  result.data.allYouTube.nodes.forEach((node) =&amp;gt; {
    createPage({
      path: node.id,
      component: templatePath,
      context: {
        id: node.id,
      },
    });
  });
};
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Generates a page at the path &lt;code&gt;/UGq8cnNTbwI/&lt;/code&gt; for the YouTube node with id: &lt;code&gt;UGq8cnNTbwI&lt;/code&gt;, and similarly for all the other YouTube nodes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Notice how the path here is a little different; &lt;code&gt;/UGq8cnNTbwI/&lt;/code&gt; vs &lt;code&gt;/u-gq8cn-n-tbw-i/&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The File System Route API will run the id through the @sindresorhus/slugify package before using it as a path. While with &lt;code&gt;createPage&lt;/code&gt; we are responsible for making unique and valid paths ourselves.&lt;/p&gt;
&lt;h2&gt;Content from the Gatsby Data Layer&lt;/h2&gt;
&lt;p&gt;You can, and probably want to, sprinkle in content from the Gatsby Data Layer for all three ways of creating SSG pages. The Gatsby Data Layer holds all the data sourced at build time, making the content available when the site is statically generated.&lt;/p&gt;
&lt;p&gt;The typical example would be to query for the YouTube Content Node corresponding to the page created:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// src/{YouTube.id}.js
// src/templates/youtube-template.js

import React from &amp;quot;react&amp;quot;;
import {graphql} from &amp;quot;gatsby&amp;quot;;

const YouTubePage = ({data}) =&amp;gt; {
  const {title} = data.youTube;
  return (
    &amp;lt;main&amp;gt;
      &amp;lt;h1&amp;gt;{title}&amp;lt;/h1&amp;gt;
    &amp;lt;/main&amp;gt;
  );
};

export const query = graphql`
  query ($eq: String) {
    youTube(id: {eq: $eq}) {
      title
    }
  }
`;

export default YouTubePage;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But you can also query for content for pages created as Rect Components in &lt;code&gt;src/pages&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// src/pages/demo.js

import React from &amp;quot;react&amp;quot;;
import {graphql, Link} from &amp;quot;gatsby&amp;quot;;

const DemoPage = ({data}) =&amp;gt; {
  return (
    &amp;lt;main&amp;gt;
      &amp;lt;h1&amp;gt;Static Site Generation (SSG)&amp;lt;/h1&amp;gt;

      {data.allYouTube.nodes.map((node) =&amp;gt; {
        return (
          &amp;lt;Link to={node.id} key={node.id}&amp;gt;
            &amp;lt;img alt={node.title} src={node.thumbnail_url} /&amp;gt;
          &amp;lt;/Link&amp;gt;
        );
      })}
    &amp;lt;/main&amp;gt;
  );
};

export const query = graphql`
  {
    allYouTube {
      nodes {
        id
        title
        thumbnail_url
      }
    }
  }
`;

export default DemoPage;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Oh boy, this was longer and more difficult to demo than I imagined. If you have any questions, reply or add them as a comment &lt;a href=&quot;https://youtu.be/D_03KW4AkSk&quot;&gt;on the video&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
All the best,&lt;br&gt;
Queen Raae&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
&lt;strong&gt;PS:&lt;/strong&gt; In the sharky waters around the Gatsby islands we call the File System Route API pages for parrot pages 🦜 More on that later!&lt;/p&gt;
</content:encoded></item><item><title>💀📄 ~ SSG even for authenticated routes in Gatsby</title><link>https://queen.raae.codes/2022-01-07-skeleton/</link><guid isPermaLink="true">https://queen.raae.codes/2022-01-07-skeleton/</guid><description>In yesterday&apos;s email, I alluded to a different approach for authenticated routes. Instead of reaching for client-side only routes I more often utilize…</description><pubDate>Fri, 07 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In &lt;a href=&quot;/2022-01-06-client-only-routes/&quot;&gt;yesterday&apos;s email&lt;/a&gt;, I alluded to a different approach for authenticated routes.&lt;/p&gt;
&lt;p&gt;Instead of reaching for &lt;a href=&quot;https://www.gatsbyjs.com/docs/how-to/routing/client-only-routes-and-user-authentication/#adjusting-routes-to-account-for-authenticated-users&quot;&gt;client-side only routes&lt;/a&gt; I more often utilize statically generated pages even for the authenticated routes these days.&lt;/p&gt;
&lt;p&gt;You can protect these routes the same way Gatsby documents for client-side only routes. However, this does not consider a visitor refreshing a page while on an authenticated route. The code will kick the visitor off the page before the authentication status is determined.&lt;/p&gt;
&lt;p&gt;Instead, I recommend assuming the visitor is supposed to be there if they hit an authenticated route. While waiting for the data to load, I will show a skeleton version of the page. If it turns out the visitor is not supposed to be there, I kick them off.&lt;/p&gt;
&lt;p&gt;A skeleton version of a page is as much of the user interface as is possible without the data only available client-side. There is often a lot to show, menus, headers, icons, etc.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://my.usepow.app/profile/&quot;&gt;&lt;img src=&quot;./skeleton.jpg&quot; alt=&quot;Skeleton Profile page&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can see the skeleton version of a profile page in action for &lt;a href=&quot;https://my.usepow.app/profile/&quot;&gt;POW!&lt;/a&gt;. If you get kicked off too soon, disable javascript to see it.&lt;/p&gt;
&lt;p&gt;This approach gives a better experience for visitors using your app correctly; they will get a smooth transition from skeleton to the page filled with data. Visitors testing out routes they should not be on will get a flash of skeleton page before being kicked off, a slightly subpar experience.&lt;/p&gt;
&lt;p&gt;Incidentally, the same topic of discussion, and pair programming, as on yesterday&apos;s &lt;a href=&quot;https://youtu.be/WzrjHVy134M&quot;&gt;unauthorized and rum-fueled treasure hunt&lt;/a&gt; in the sharky waters around the Gatsby islands, helping Mirjam with Conference Buddy v2.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/WzrjHVy134M&quot;&gt;&lt;img src=&quot;./yt-screenshot.jpg&quot; alt=&quot;Screengrab of the intro&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
Did any of this make sense?
Reply to let me know either way...&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
All the best,&lt;br&gt;
Queen Raae&lt;/p&gt;
</content:encoded></item><item><title>🎇 ∞ ~ Server Side Rendered (SSR) fallback routes with Gatsby</title><link>https://queen.raae.codes/2021-12-31-fallback-routes/</link><guid isPermaLink="true">https://queen.raae.codes/2021-12-31-fallback-routes/</guid><description>The unauthorized and rum-fueled treasure hunts in the sharky waters around the Gatsby islands Conference Buddy edition is back. And on yesterday&apos;s stream…</description><pubDate>Fri, 31 Dec 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The unauthorized and rum-fueled treasure hunts in the sharky waters around the Gatsby islands Conference Buddy edition is back.&lt;/p&gt;
&lt;p&gt;And on &lt;a href=&quot;https://youtu.be/d834JE_bFog&quot;&gt;yesterday&apos;s stream&lt;/a&gt; helping Mirjam source conference data from Supabase, we briefly touched on fallback routes.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/d834JE_bFog&quot;&gt;&lt;img src=&quot;./yt-screenshot.jpg&quot; alt=&quot;Screengrab of the intro&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;What are fallback routes?&lt;/h2&gt;
&lt;p&gt;It&apos;s a way to render pages for data that Gatsby does not yet sourced.&lt;/p&gt;
&lt;p&gt;In Mirjam&apos;s case with Conference Buddy there will be a period between a user submits a conference and a fresh build picks up the conference for static generation.&lt;/p&gt;
&lt;p&gt;In that interim time, we can rely on fallback routes using either CSR (Client Side Rendering) or SSR (Server Side Rendering).&lt;/p&gt;
&lt;p&gt;I was not sure if SSR fallback route would be allowed, so I spun up a contrived demo using SSG (Static Site Generation) for sourced YouTube videos and SSR for non-sourced YouTube videos.&lt;/p&gt;
&lt;p&gt;The Gatsby docs does not mention SSR for fallback routes, but it builds and serves locally on my machine. However I must admit I have not yet tested deployment...&lt;/p&gt;
&lt;h3&gt;SSG Page Code&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;// src/pages/yt/{youTubeEmbed.id}.js

import React from &amp;quot;react&amp;quot;;
import { graphql } from &amp;quot;gatsby&amp;quot;;

import VideoLayout from &amp;quot;../../components/video-layout&amp;quot;;

const SSGVideoPage = ({ data }) =&amp;gt; {
  return &amp;lt;VideoLayout {...data.youTubeEmbed} /&amp;gt;;
};

export default SSGVideoPage;

export const query = graphql`
  query ($id: String) {
    youTubeEmbed(id: { eq: $id }) {
      title
      html
    }
  }
`;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Fallback SSR Page Code&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;// src/pages/yt/[youTubeId].js

import React from &amp;quot;react&amp;quot;;

import { fetchEmbed } from &amp;quot;../../services/oembed&amp;quot;;
import VideoLayout from &amp;quot;../../components/video-layout&amp;quot;;
import NotFoundPage from &amp;quot;../404&amp;quot;;

const SSRVideoPage = ({ serverData }) =&amp;gt; {
  if (serverData) {
    return &amp;lt;VideoLayout {...serverData} /&amp;gt;;
  } else {
    return &amp;lt;NotFoundPage /&amp;gt;;
  }
};

export default SSRVideoPage;

export async function getServerData({ params }) {
  console.log(&amp;quot;SERVER SIDE RENDERING Page for &amp;quot;, params.youTubeId);

  const embedData = await fetchEmbed(params.youTubeId, console);

  return {
    props: embedData,
  };
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Links&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Gatsby&apos;s official documentation on &lt;a href=&quot;https://www.gatsbyjs.com/docs/reference/routing/file-system-route-api/#collection-route--fallback&quot;&gt;Fallback Routes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The contrived example on &lt;a href=&quot;https://codesandbox.io/s/demo-ssr-fallback-route-9pteu?file=/src/pages/index.mdx&quot;&gt;CodeSandbox&lt;/a&gt; (CodeSandbox is a little buggy with Gatsby so give it some time/reloads if its messing up...)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;br&gt;
Have you ever used fallback routes in a real-world project?&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
All the best,&lt;br&gt;
Queen Raae&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
&lt;strong&gt;PS:&lt;/strong&gt; Godt Nytt År (Happy New Year) 🎇&lt;/p&gt;
</content:encoded></item></channel></rss>