<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Marc Frame</title>
    <description>The latest articles on DEV Community by Marc Frame (@marcdaframe).</description>
    <link>https://dev.to/marcdaframe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F809539%2F48dc5049-062b-4aec-919d-24f65a0bc3ce.jpg</url>
      <title>DEV Community: Marc Frame</title>
      <link>https://dev.to/marcdaframe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marcdaframe"/>
    <language>en</language>
    <item>
      <title>Hosting sveltekit on AWS Amplify</title>
      <dc:creator>Marc Frame</dc:creator>
      <pubDate>Tue, 17 May 2022 03:00:19 +0000</pubDate>
      <link>https://dev.to/marcdaframe/hosting-sveltekit-on-aws-amplify-7ec</link>
      <guid>https://dev.to/marcdaframe/hosting-sveltekit-on-aws-amplify-7ec</guid>
      <description>&lt;p&gt;If you are using the &lt;a href="https://www.npmjs.com/package/@sveltejs/adapter-static"&gt;&lt;code&gt;@sveltejs/adapter-static&lt;/code&gt;&lt;/a&gt; this might come in handy!&lt;/p&gt;

&lt;p&gt;Go to the AWS Amplify project, in the side bar click &lt;code&gt;App settings: Rewrites and redirects&lt;/code&gt;, Edit, Open Text Editor and paste the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;/^[^.]+$|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;.(?!(svelte|css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/index.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"200"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"condition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/&amp;lt;*&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"404-200"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"condition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;next add a &lt;code&gt;&amp;lt;base href="/" /&amp;gt;&lt;/code&gt; to the &lt;code&gt;&amp;lt;head /&amp;gt;&lt;/code&gt; tag in the &lt;code&gt;app.html&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Explanation
&lt;/h1&gt;

&lt;p&gt;The Amplify Redirect and Rewrite Config and the &lt;code&gt;&amp;lt;base href="/" /&amp;gt;&lt;/code&gt; directs all the failed responses back to the index file, making any request that fails fall back to the sveltekit router.&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>javascript</category>
      <category>aws</category>
      <category>webdev</category>
    </item>
    <item>
      <title>SvelteKit: Dynamic routes, static renderer</title>
      <dc:creator>Marc Frame</dc:creator>
      <pubDate>Sat, 26 Feb 2022 21:28:06 +0000</pubDate>
      <link>https://dev.to/marcdaframe/sveltekit-dynamic-routes-static-renderer-17dl</link>
      <guid>https://dev.to/marcdaframe/sveltekit-dynamic-routes-static-renderer-17dl</guid>
      <description>&lt;p&gt;I asked the following question on the Svelte discord, but was able to solve it before anyone had a chance to look at the question (classic).&lt;/p&gt;

&lt;h1&gt;
  
  
  Question
&lt;/h1&gt;

&lt;p&gt;I have a sveltekit app where I've defined a page as dynamic with the following svelte.config.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;adapter&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@sveltejs/adapter-static&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;kit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;prerender&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/portfolio&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because the page &lt;code&gt;/blogs&lt;/code&gt; and &lt;code&gt;/blog?file=/some/blog/file.md&lt;/code&gt; are populated by a fetch call to a rest API.&lt;/p&gt;

&lt;p&gt;if I don't include the &lt;code&gt;kit.prerender.entities&lt;/code&gt; I get the following error when I run &lt;code&gt;npm run build&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Error: Cannot access url.searchParams on a page with prerendering enabled&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The issue is, that when I refresh the page, or route directly to the &lt;code&gt;/blog?file=/some/blog/file.md&lt;/code&gt; it renders the index page instead of the blog page.&lt;/p&gt;

&lt;p&gt;How should I fix this?&lt;/p&gt;

&lt;p&gt;Here's an example &lt;a href="https://mframe.ca/blog?file=About%20this%20blog.md"&gt;https://mframe.ca/blog?file=About%20this%20blog.md&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;note it should render the blog, not my index page&lt;/li&gt;
&lt;li&gt;you can route to that blog ("About this blog") through &lt;a href="https://mframe.ca/blogs"&gt;https://mframe.ca/blogs&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's how the &lt;code&gt;/blog&lt;/code&gt; page works&lt;/p&gt;

&lt;h1&gt;
  
  
  Answer
&lt;/h1&gt;

&lt;p&gt;you have to run it in "SPA" mode. by providing a fallback to the adapter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;assets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fallback&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;precompress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}),&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The issue was that it was looking for a /blog/index.html file but it of course wasn't there.&lt;/p&gt;

&lt;h1&gt;
  
  
  A better way to selectively prerender
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script context="module"&amp;gt;
    export const prerender = true;
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;add this to the pages that you want to prerender, those without this declaration will not be prerendered. you will of course still have to 'run it in "SPA" mode' as noted above.&lt;/p&gt;

&lt;p&gt;This is cleaner than the above solution of editing the &lt;br&gt;
&lt;code&gt;congif.kit.prerender.entities&lt;/code&gt; in&lt;code&gt;svelte.config.js&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  More
&lt;/h1&gt;

&lt;h4&gt;
  
  
  Read more about the blog here:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://dev.to/marcdaframe/github-as-a-cms-for-your-blog-fhh"&gt;https://dev.to/marcdaframe/github-as-a-cms-for-your-blog-fhh&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  View the source code for the blog here:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://github.com/MarcDAFrame/SvelteGithubBlog"&gt;https://github.com/MarcDAFrame/SvelteGithubBlog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>devops</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Github as a CMS for your blog?</title>
      <dc:creator>Marc Frame</dc:creator>
      <pubDate>Fri, 04 Feb 2022 20:02:15 +0000</pubDate>
      <link>https://dev.to/marcdaframe/github-as-a-cms-for-your-blog-fhh</link>
      <guid>https://dev.to/marcdaframe/github-as-a-cms-for-your-blog-fhh</guid>
      <description>&lt;h1&gt;
  
  
  About this blog
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lbcgun2V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99hetg2e1u7fwpww6asu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lbcgun2V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99hetg2e1u7fwpww6asu.gif" alt="demo.gif" width="880" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This blog uses Github as the CMS, meaning github hosts the markdown and media files for the blog.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://mframe.ca/blogs"&gt;https://mframe.ca/blogs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Source Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/MarcDAFrame/SvelteGithubBlog"&gt;https://github.com/MarcDAFrame/SvelteGithubBlog&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;This is nifty because &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;you don't pay for a CMS / hosting&lt;/li&gt;
&lt;li&gt;your blogs can be version tracked&lt;/li&gt;
&lt;li&gt;you can write blogs with the same workflow as you write your code&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How?
&lt;/h2&gt;

&lt;p&gt;It's really dead simple&lt;/p&gt;

&lt;p&gt;The blog uses the &lt;code&gt;Github Rest API&lt;/code&gt; to query all the files in a repo, it then iterates through all the markdown files, building a tree view which is viewed on the &lt;code&gt;/blogs&lt;/code&gt; page.&lt;/p&gt;

&lt;p&gt;When a user clicks on the a blog they are linked to &lt;code&gt;/blog?file=[SOME FILE IN THE REPO]&lt;/code&gt; where a call is made to the &lt;code&gt;raw.githubusercontent.com&lt;/code&gt; endpoint to fetch the content for that file.&lt;/p&gt;

&lt;p&gt;The only complicated part of this is how images and links are handled. A custom &lt;code&gt;SvelteMarkdown&lt;/code&gt; renderer was created for both the Image and the Link which translated the image &lt;code&gt;src&lt;/code&gt; to be fetched from the &lt;code&gt;raw.githubusercontent.com&lt;/code&gt;, and translated the Link &lt;code&gt;href&lt;/code&gt; to be relative to the currently open file, linking to the relevant &lt;code&gt;/blog?file=[SOME FILE IN THE REPO]&lt;/code&gt; (if it was a relative link).&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;An individual, unauthenticated user can only make 60 requests an hour, which means the user can only refresh the page 60 times and can only view 60 blogs. The rate limiting is separate between the two domains (raw and api) which means viewing a blog, and viewing all the blogs have different rate limits.&lt;/p&gt;

&lt;p&gt;However, this isn't much of an issue as an individual user isn't going to be reading / refreshing your blog that much - and if they are then they probably deserve to be rate limited.&lt;/p&gt;

</description>
      <category>blog</category>
      <category>webdev</category>
      <category>svelte</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
