<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[My Awesome Blog]]></title><description><![CDATA[I write about code 'n stuff]]></description><link>https://alyssaphacker.com</link><image><url>https://alyssaphacker.com/icon.png</url><title>My Awesome Blog</title><link>https://alyssaphacker.com</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Nov 2020 16:27:25 GMT</lastBuildDate><atom:link href="https://alyssaphacker.com/rss.xml" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Mar 2020 04:00:00 GMT</pubDate><copyright><![CDATA[2020 Alyssa P. Hacker]]></copyright><language><![CDATA[en]]></language><managingEditor><![CDATA[alyssa@example.com]]></managingEditor><webMaster><![CDATA[alyssa@example.com]]></webMaster><ttl>60</ttl><item><title><![CDATA[Dan Abramov knows about Devii]]></title><description><![CDATA[<p>Dan Abramov knows about Devii!</p>
<blockquote>
  <p>Seems like it might be useful!
  — Dan Abramov, taken entirely out of context</p>
</blockquote>
<p>I don't want to brag, but Devii is kind of a big deal.</p>]]></description><link>https://alyssaphacker.com/blog/dan-abramov</link><guid isPermaLink="true">https://alyssaphacker.com/blog/dan-abramov</guid><category><![CDATA[Dan Abramov]]></category><dc:creator><![CDATA[Colin McDonnell]]></dc:creator><pubDate>Fri, 10 Jul 2020 23:51:18 GMT</pubDate></item><item><title><![CDATA[Choosing a tech stack for my personal dev blog in 2020]]></title><description><![CDATA[<blockquote>
  <p>Originally published at <a href="https://colinhacks.com/essays/devii">https://colinhacks.com/essays/devii</a>. Check out the HN <del>roast</del> discussion <a href="https://news.ycombinator.com/item?id=23309002">here</a>! 🤗</p>
</blockquote>
<p>I recently set out to build my personal website — the one you're reading now, as it happens!</p>
<p>Surprisingly, it was much harder than expected to put together a "tech stack" that met my criteria. My criteria are pretty straightforward; I would expect most React devs to have a similar list. Yet it was surprisingly hard to put all these pieces together.</p>
<p>Given the lack of a decent out-of-the-box solution, I worry that many developers are settling for static-site generators that place limits on the interactivity and flexibility of your website. We can do better.</p>
<blockquote>
  <p>Clone the repo here to get started with this setup: https://github.com/colinhacks/devii</p>
</blockquote>
<p>Let's quickly run through my list of design goals:</p>
<h3 id="reacttypescript">React (+ TypeScript)</h3>
<p>I want to build the site with React and TypeScript. I love them both wholeheartedly, I use them for my day job, and they're gonna be around for a long time. Plus writing untyped JS makes me feel dirty.</p>
<p>I don't want limitations on what my personal website can be/become. Sure, at present my site consists of two simple, static blog posts. But down the road, I may want to build a page that contains an interactive visualization, a filterable table, or a demo of a React component I'm open-sourcing. Even something simple (like the email newsletter signup form at the bottom of this page) was much more pleasant to implement in React; how did we use to build forms again?</p>
<p>Plus: I want access to the npm ecosystem and all my favorite UI, animation, and styling libraries. I sincerely hope I never write another line of raw CSS ever again; CSS-in-JS 4 lyfe baby. If you want to start a Twitter feud with me about this, by all means <a href="https://twitter.com/colinhacks">at me</a>.</p>
<h3 id="goodauthoringexperience">Good authoring experience</h3>
<p>If it's obnoxious to write new blog posts, I won't do it. That's a regrettable law of the universe. Even writing blog posts with plain HTML — just a bunch of <code>&lt;p&gt;</code> tags in a div — is just annoying enough to bug me. The answer: Markdown of course!</p>
<p>Static site generators (SSGs) like Hugo and Jekyll provide an undeniably wonderful authoring experience. All you have to do is <code>touch</code> a new .md file in the proper directory and get to writing. Unfortunately all Markdown-based SSGs I know of are too restrictive. Mixing React and Markdown on the same page is either impossible or tricky. If it's possible, it likely requires some plugin/module/extension, config file, blob of boilerplate, or egregious hack. Sorry Hugo, I'm not going to re-write my React code using <code>React.createElement</code> like it's 2015.</p>
<p>Well, that doesn't work for me. I want my website to be React-first, with a sprinkling of Markdown when it makes my life easier.</p>
<h3 id="staticgeneration">Static generation</h3>
<p>As much as I love the Jamstack, it doesn't cut it from an SEO perspective. Many blogs powered by a "headless CMS" require two round trips before rendering the blog content (one to fetch the static JS bundle and another to fetch the blog content from a CMS). This degrades page load speeds and user experience, which accordingly degrades your rankings on Google.</p>
<p>Instead I want every page of my site to be pre-rendered to a set of fully static assets, so I can deploy them to a CDN and get fast page loads everywhere. You could get the same benefits with server-side rendering, but that requires an actual server and worldwide load balancing to achieve comparable page load speeds. I love overengineering things as much as the next guy, even I have a line. 😅</p>
<h2 id="mysolution">My solution</h2>
<p>I describe my final architecture design below, along with my rationale for each choice. I distilled this setup into a website starter/boilerplate available here: https://github.com/colinhacks/devii. Below, I allude to certain files/functions I implemented; to see the source code of these, just clone the repo <code>git clone git@github.com:colinhacks/devii.git</code></p>
<h3 id="nextjs">Next.js</h3>
<p>I chose to build my site with Next.js. This won't be a surprising decision to anyone who's played with statically-rendered or server-side rendered React in recent years. Next.js is quickly eating everyone else's lunch in this market, especially Gatsby's (sorry Gatsby fans).</p>
<p>Next.js is by far the most elegant way (for now) to do any static generation or server-side rendering with React. They just released their next-generation (pun intended) static site generator in the <a href="https://nextjs.org/blog/next-9-3">9.3 release</a> back in March. So in the spirit of using technologies <a href="https://www.youtube.com/watch?v=eBAX8MbRYFA">in the spring of their life</a>, Next.js is a no-brainer.</p>
<p>Here's a quick breakdown of the project structure. No need to understand every piece of it; but it may be useful to refer to throughout the rest of this post.</p>
<pre><code>.
├── README.md
├── public // all static files (images, etc) go here
├── pages // every .tsx component in this dir becomes a page of the final site
|   ├── index.tsx // the home page (which has access to the list of all blog posts)
|   ├── blog
|       ├── [blog].md // a template component that renders the blog posts under `/md/blog`
├── md
|   ├── blog
|       ├── devii.md // this page!
        ├── whatever.md // every MD file in this directory becomes a blog post
├── components
|   ├── Code.tsx
|   ├── Markdown.tsx
|   ├── &lt;various others&gt;
├── loader.ts // contains utility functions for loading/parsing Markdown
├── node_modules
├── tsconfig.json
├── package.json
├── next.config.js
├── next-env.d.ts
├── .gitignore
</code></pre>
<!-- Check out the Next.js documentation [here](https://nextjs.org/docs) to make sure it's the right choice for your project. -->
<h3 id="typescriptreact">TypeScript + React</h3>
<p>Both React and TypeScript are baked into the DNA of Next.js, so you get these for free when you set up a Next.js project.</p>
<p>Gatsby, on the other hand, has a special plugin for TypeScript support, but it's not officially supported and seems to be <a href="https://github.com/gatsbyjs/gatsby/issues/18983">low on their priority list</a>. Also, after messing with it for an hour I couldn't get it to play nice with hot reload.</p>
<h3 id="markdownauthoring">Markdown authoring</h3>
<p>Using Next's special <code>getStaticProps</code> hook and glorious <a href="https://nextjs.org/docs/advanced-features/dynamic-import#with-no-ssr">dynamic imports</a>, it's trivial to a Markdown file and pass its contents into your React components as a prop. This achieves the holy grail I was searching for: the ability to easily mix React and Markdown.</p>
<h4 id="frontmattersupport">Frontmatter support</h4>
<p>Every Markdown file can include a "frontmatter block" containing metadata. I implemented a simple utility function (<code>loadPost</code>) that loads a Markdown file, parses its contents, and returns a TypeScript object with the following signature:</p>
<pre><code class="ts language-ts">type PostData = {
  path: string; // the relative URL to this page, can be used as an href
  content: string; // the body of the MD file
  title?: string;
  subtitle?: string;
  date?: number;
  author?: string;
  authorPhoto?: string;
  authorTwitter?: string;
  tags?: string[];
  bannerPhoto?: string;
  thumbnailPhoto?: string;
};
</code></pre>
<p>I implemented a separate function <code>loadPosts</code> that loads <em>all</em> the Markdown files under <code>/md/blog</code> and returns them as an array (<code>PostData[]</code>). I use <code>loadPosts</code> on this site's home page to render a list of all posts I've written.</p>
<h3 id="mediuminspireddesign">Medium-inspired design</h3>
<p>I used the wonderful <a href="https://github.com/rexxars/react-markdown"><code>react-markdown</code></a> package to render Markdown as a React component. My Markdown rendered component (<code>/components/Markdown.tsx</code>) provides some default styles inspired by Medium's design. Just modify the <code>style</code> pros in <code>Markdown.tsx</code> to customize the design to your liking.</p>
<h3 id="githubstylecodeblocks">GitHub-style code blocks</h3>
<p>You can easily drop code blocks into your blog posts using triple-backtick syntax. Specify the programming language with a "language tag", <a href="https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks">just like GitHub</a>!</p>
<p>To achieve this I implemented a custom <code>code</code> renderer (<code>/components/Code.tsx</code>) for <code>react-markdown</code> that uses <a href="https://github.com/conorhastings/react-syntax-highlighter#readme">react-syntax-highlighter</a> to handle the highlighting. So this:</p>
<!-- I landed on this solution after wasting hours playing with other options. CodeMirror has bad React support (the only React wrapper for it is inauspiciously named `react-codemirror2`) and [bizarre selection issues](https://github.com/codemirror/CodeMirror/issues/1099) for `readonly` code blocks. The popular `highlight.js` project requires you to [initialize the library](https://github.com/highlightjs/highlight.js/issues/925) in `componentDidMount` like its 2015 :/  -->
<pre><pre><code class="ts language-ts">// pretty neat huh?
const test = (arg: string) =&gt; {
  return arg.length &gt; 5;
};
</code></pre></pre>
<p>turns into this:</p>
<pre><code class="ts language-ts">// pretty neat huh?
const test = (arg: string) =&gt; {
  return arg.length &gt; 5;
};
</code></pre>
<h3 id="rssfeedgeneration">RSS feed generation</h3>
<p>An RSS feed is auto-generated from your blog post feed. This feed is generated using the <code>rss</code> module (for converting JSON to RSS format) and <code>showdown</code> for converting the markdown files to RSS-compatible HTML. The feed is generated during the build step and written as a static file to <code>/rss.xml</code> in your static assets folder. It's dead simple. That's the joy of being able to easily write custom build scripts on top of Next.js's <code>getStaticProps</code> hooks!</p>
<h3 id="seo">SEO</h3>
<p>Every blog post page automatically populated meta tags based on the post metadata. This includes a <code>title</code> tag, <code>meta</code> tags, <code>og:</code> tags, Twitter metadata, and a <code>link</code> tag containing the canonical URL. You can modify/augment this in the <code>PostMeta.ts</code> component.</p>
<h3 id="staticgeneration-1">Static generation</h3>
<p>You can generate a fully static version of your site using <code>yarn build &amp;&amp; yarn export</code>. This step is entirely powered by Next.js. The static site is exported to the <code>out</code> directory.</p>
<p>After its generated, use your static file hosting service of choice (Firebase Hosting, Vercel, Netlify) to deploy your site.</p>
<h3 id="insanelycustomizable">Insanely customizable</h3>
<p>There's nothing "under the hood" here. You can view and modify all the files that provide the functionality described above. Devii just provides a project scaffold, some Markdown-loading loading utilities (in <code>loader.ts</code>), and some sensible styling defaults (especially in <code>Markdown.tsx</code>).</p>
<p>To start customizing, modify <code>index.tsx</code> (the home page), <code>Essay.tsx</code> (the blog post template), and <code>Markdown.tsx</code> (the Markdown renderer).</p>
<h2 id="getstarted">Get started</h2>
<p>Head to the GitHub repo to get started: <a href="https://github.com/colinhacks/devii">https://github.com/colinhacks/devii</a>. If you like this project, leave a ⭐️star⭐️ to help more people find Devii! 😎</p>
<p>To jump straight into the code, clone the repo and start the development server like so:</p>
<pre><code class="sh language-sh">git clone git@github.com:colinhacks/devii.git mysite
cd mysite
yarn
yarn dev
</code></pre>]]></description><link>https://alyssaphacker.com/blog/the-ultimate-tech-stack</link><guid isPermaLink="true">https://alyssaphacker.com/blog/the-ultimate-tech-stack</guid><category><![CDATA[Static Site Generators]]></category><category><![CDATA[React]]></category><category><![CDATA[Next.js]]></category><dc:creator><![CDATA[Colin McDonnell]]></dc:creator><pubDate>Tue, 26 May 2020 03:18:56 GMT</pubDate></item><item><title><![CDATA[Devii's killer features]]></title><description><![CDATA[<p>This page is built with Devii! Check out the source code for this under <code>/md/blog/test.md</code>.</p>
<p>Devii is a starter kit for building a personal website with the best tools 2020 has to offer.</p>
<ul>
<li><strong>Markdown-based</strong>: Just add a Markdown file to <code>/md/blog</code> to add a new post to your blog!</li>
<li><strong>TypeScript + React</strong>: aside from the parts that are rendered Markdown, everything else is fully built with TypeScript and functional React components. Implementing any sort of interactive widget is often hard using existing Markdown-centric static-site generators, but Devii makes it easy to mix Markdown and React on the same page.</li>
<li><strong>Frontmatter support</strong>: Every post can include a frontmatter block containing metadata: <code>title</code>, <code>subtitle</code>, <code>datePublished</code> (timestamp), <code>author</code>, <code>authorPhoto</code>, and <code>bannerPhoto</code>.</li>
<li><strong>Medium-inspired styles</strong>: The Markdown renderer (<code>Markdown.tsx</code>) contains default styles inspired by Medium.</li>
<li><strong>Static generation</strong>: you can generate a fully static version of your site using <code>yarn build &amp;&amp; yarn export</code>. Powered by Next.js.</li>
<li><strong>GitHub-style code blocks</strong>: with syntax highlighting powered by <a href="https://github.com/conorhastings/react-syntax-highlighter">react-syntax-highlighter</a>. Works out-of-the-box for all programming languages. Just use Markdown's triple backtick syntax with a "language identifier", <a href="https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks">just like GitHub</a>.</li>
</ul>
<pre><code class="ts language-ts">  // pretty neat huh?
  const test: (arg: string) =&gt; boolean = (arg) =&gt; {
    return arg.length &gt; 5;
  };
</code></pre>
<ul>
<li><strong>Utterly customizable</strong>: We provide a minimal interface to get you started, but you can customize every aspect of the rendering and styling by just modifying <code>index.tsx</code> (the home page), <code>BlogPost.tsx</code> (the blog post template), and <code>Markdown.tsx</code> (the Markdown renderer). And of course you can add entirely new pages as well!</li>
</ul>
<p>Head to the GitHub repo to get started: <a href="https://github.com/colinhacks/devii">https://github.com/colinhacks/devii</a>. If you like this project, leave a ⭐️star⭐️ to help more people find Devii 😎</p>]]></description><link>https://alyssaphacker.com/blog/devii</link><guid isPermaLink="true">https://alyssaphacker.com/blog/devii</guid><category><![CDATA[Devii]]></category><category><![CDATA[Blogs]]></category><dc:creator><![CDATA[Ben Bitdiddle]]></dc:creator><pubDate>Sat, 09 May 2020 22:48:42 GMT</pubDate></item></channel></rss>