<?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 #astro</title><description>All posts tagged with astro on queen.raae.codes</description><link>https://queen.raae.codes/tag/astro/</link><item><title>📝 ✨ ~ Remote Astro Collections (sort of)</title><link>https://queen.raae.codes/2024-03-11-remote-astro-collections/</link><guid isPermaLink="true">https://queen.raae.codes/2024-03-11-remote-astro-collections/</guid><description>You may also watch us figure this approach out live on YouTube. After adding the &quot;most popular&quot; episodes section to our Astro podcast website the local DX took…</description><pubDate>Mon, 11 Mar 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&amp;lt;aside class=&amp;quot;notice&amp;quot;&amp;gt;&lt;/p&gt;
&lt;p&gt;You may also watch us figure this approach out &lt;a href=&quot;https://youtube.com/live/yTNr3Y1xGbU&quot;&gt;live on YouTube&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;lt;/aside&amp;gt;&lt;/p&gt;
&lt;p&gt;After adding the &amp;quot;most popular&amp;quot; episodes section to &lt;a href=&quot;https://github.com/olavea/Our-podcast-websites&quot;&gt;our Astro podcast website&lt;/a&gt; the local DX took a nose dive!&lt;/p&gt;
&lt;p&gt;Building the home page took 3789ms, that&apos;s almost 4 seconds 🤦‍♀️&lt;/p&gt;
&lt;p&gt;Fetching all the analytics data from the Transistor API, looping through and calculating the total download numbers for each episode, and then sorting the episodes by popularity takes time.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We could probably optimize the code, but it would still slow down the build.&lt;/li&gt;
&lt;li&gt;We could skip picking out the most popular episodes in development, but then it be hard to design that section.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And neither would solve the issue that fetching the data from the Transistor API also needs to happen in the single episode page template (&lt;code&gt;/src/pages/episodes/[slug].astro&lt;/code&gt;) and the paginated archive pages (&lt;code&gt;/src/pages/episodes/[...page].astro&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;At this point, I really missed the Gatsby Data Layer 😢 I deep-dived into the Astro Collection docs hoping I&apos;d missed the option to source remote data as an Astro Collection. I had not, but I did notice Astro collection can be of type &lt;code&gt;data&lt;/code&gt;, meaning .json or .yml files in addition to type &lt;code&gt;content&lt;/code&gt; meaning .md, .mdx and .markdoc files.&lt;/p&gt;
&lt;p&gt;So I decided to explore fetching all the data, and calculating the total download numbers, ahead of time! Writing the response from the Transistor API as .json files to disk; one for each episode.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;import { join } from &amp;quot;node:path&amp;quot;;
import { writeFile } from &amp;quot;node:fs/promises&amp;quot;;
import { fetchAllEpisodes, fetchAllEpisodeAnalytics } from &amp;quot;./transistor.js&amp;quot;;

try {
  const DIR = join(process.cwd() + &amp;quot;/src/content/episodes/&amp;quot;);

  const episodeData = await fetchAllEpisodes();
  const episodeAnalytics = await fetchAllEpisodeAnalytics();

  const episodeFilePromises = episodeData.map((episode) =&amp;gt; {
    const analytics = episodeAnalytics.attributes.episodes.find((a) =&amp;gt; {
      return parseInt(a.id) === parseInt(episode.id);
    });

    const totalDownloads = analytics.downloads.reduce(
      (acc, day) =&amp;gt; acc + day.downloads,
      0
    );

    return writeFile(
      join(DIR + `/${episode.id}.json`),
      JSON.stringify(
        {
          ...episode.attributes,
          totalDownloads,
        },
        null,
        2
      )
    );
  });

  const files = await Promise.all(episodeFilePromises);
  console.log(`Episode entries written ${files.length} to ${DIR}.`);
} catch (error) {
  console.error(error);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;And holy moly, it worked!&lt;/strong&gt;&lt;br&gt;
Build time for the home page went from 3789ms to 148ms 🎉🎉🎉&lt;/p&gt;
&lt;p&gt;In addition to the build time improvement, I also got the added benefit of Astro&apos;s built-in collection validation. I decided to skip typescript for the data fetching code above, and rather rely on the collection schema to catch any errors.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;import { defineCollection, z } from &amp;quot;astro:content&amp;quot;;

const episodeCollection = defineCollection({
  type: &amp;quot;data&amp;quot;,
  schema: z.object({
    title: z.string(),
    slug: z.string(),
    totalDownloads: z.number(),
    description: z.string(),
    embed_html: z.string(),
    // and more as we build out the site
  }),
});

export const collections = {
  episodes: episodeCollection,
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My gut feeling is that we&apos;ll see support for remote collection in Astro pretty soon, but for now, I&apos;m happy with the solution I&apos;ve come up with.&lt;/p&gt;
&lt;p&gt;Let me know if you have any questions or suggestions for improvements. I&apos;m &lt;a href=&quot;https://twitter.com/raae&quot;&gt;@raae&lt;/a&gt; on Twitter.&lt;/p&gt;
</content:encoded></item><item><title>📝 ✨ ~ Two Week Build is on 🚀</title><link>https://queen.raae.codes/2024-02-29-two-week-build/</link><guid isPermaLink="true">https://queen.raae.codes/2024-02-29-two-week-build/</guid><description>I signed up for Amy&apos;s inaugural Two-Week Build Challenge. And there is still time for you to sign up! Let me know if you need some added accountability. We…</description><pubDate>Thu, 29 Feb 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I signed up for Amy&apos;s inaugural &lt;a href=&quot;https://www.twoweekbuild.com/&quot;&gt;Two-Week Build Challenge&lt;/a&gt;. And there is still time for you to sign up!&lt;/p&gt;
&lt;p&gt;Let me know if you need some added accountability. We could set up co-working sessions 🎉&lt;/p&gt;
&lt;h2&gt;How It Works&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Pick Something to Build&lt;/li&gt;
&lt;li&gt;Build it in 2 Weeks&lt;/li&gt;
&lt;li&gt;Ship it&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Rules and Guidelines&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Have fun.&lt;/li&gt;
&lt;li&gt;Don’t overthink it.&lt;/li&gt;
&lt;li&gt;Don’t start until March 1, 2024.&lt;/li&gt;
&lt;li&gt;You can build anything. Write an ebook. Design a UI library. Build a web application.&lt;/li&gt;
&lt;li&gt;At the end of 2 weeks, ship what you have.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&apos;m building a, Astro website for our podcast Data in the Wild launching in April now that all episodes of season 1 are recorded.&lt;/p&gt;
&lt;p&gt;And I plan on &lt;a href=&quot;https://youtube.com/QueenRaae/live&quot;&gt;live streaming&lt;/a&gt; every day starting Monday, the 4th.&lt;/p&gt;
&lt;p&gt;But if I fold or skip some, that is also okay...&lt;/p&gt;
&lt;p&gt;👷‍♀️&lt;/p&gt;
</content:encoded></item><item><title>📝 ✨ ~ Remix, Astro, or Eleventy?</title><link>https://queen.raae.codes/2023-09-11-what-now/</link><guid isPermaLink="true">https://queen.raae.codes/2023-09-11-what-now/</guid><description>We are, of course, hoping Gatsby gets a second wind, but as a content creator, it seems Gatsby will not get the piratical family and me anywhere these days 😬…</description><pubDate>Mon, 11 Sep 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;We are, of course, hoping Gatsby gets a second wind, but as a content creator, it seems Gatsby will not get the piratical family and me anywhere these days 😬&lt;/p&gt;
&lt;p&gt;So my question to you is:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Would you like to learn a new Jamstack framework with us, and if so, which one: Astro, Remix, or Eleventy?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Or is there something else entirely you would like to see from us?&lt;/p&gt;
&lt;p&gt;All the best,
Raae&lt;/p&gt;
&lt;p&gt;PS: Remember to move your Gatsby Cloud sites within the next month(ish).&lt;/p&gt;
</content:encoded></item></channel></rss>