<?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: Pascal Andermatt</title>
    <description>The latest articles on DEV Community by Pascal Andermatt (@pandermatt).</description>
    <link>https://dev.to/pandermatt</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%2F1260404%2F2334ccbc-f00a-4418-8e56-f04e3132af57.jpeg</url>
      <title>DEV Community: Pascal Andermatt</title>
      <link>https://dev.to/pandermatt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pandermatt"/>
    <language>en</language>
    <item>
      <title>Personal URL shortener &amp; Dynamic QR Codes with Jekyll and GitHub Pages</title>
      <dc:creator>Pascal Andermatt</dc:creator>
      <pubDate>Sat, 27 Jan 2024 17:26:05 +0000</pubDate>
      <link>https://dev.to/pandermatt/personal-url-shortener-dynamic-qr-codes-with-jekyll-and-github-pages-a0a</link>
      <guid>https://dev.to/pandermatt/personal-url-shortener-dynamic-qr-codes-with-jekyll-and-github-pages-a0a</guid>
      <description>&lt;p&gt;Ever wondered how to create your very own URL shortener or generate dynamic QR codes? You might be surprised to learn that it's not only possible but also quite simple with GitHub Pages. In this post, I'll walk you through the steps to achieve this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Your GitHub Repository
&lt;/h2&gt;

&lt;p&gt;Begin by creating a new repository on GitHub. I named mine &lt;code&gt;u&lt;/code&gt; for a short and sweet URL like &lt;code&gt;pandermatt.ch/u/&lt;/code&gt;. This naming trick can really personalize your links!&lt;/p&gt;

&lt;p&gt;Don't have a custom domain? No worries! GitHub has got you covered with a default hosting option at &lt;code&gt;pandermatt.github.io/u/&lt;/code&gt;. Of course, if you have a custom domain, you can direct it to something catchy like &lt;code&gt;qr.pandermatt.ch&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic QR Codes
&lt;/h2&gt;

&lt;p&gt;Here’s where the fun begins. Imagine you’ve created a link such as &lt;code&gt;pandermatt.ch/u/123&lt;/code&gt;. Convert this into a QR code. The cool part? You can change where this QR code points to at any time!&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Essential Files
&lt;/h2&gt;

&lt;p&gt;Now that we've set the stage, it's time to create the magic. You'll need to add a couple of essential files to your GitHub repository. You can find the final code at &lt;a href="https://github.com/pandermatt/u_public"&gt;https://github.com/pandermatt/u_public&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_layouts/redirect.html&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This HTML file will handle the redirection logic for your custom URLs and QR codes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;{{ page.redirect }}&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;http-equiv=&lt;/span&gt;&lt;span class="s"&gt;"refresh"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"0;URL='{{ page.redirect }}'"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Gemfile&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source "https://rubygems.org"

gem "jekyll"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;_config.yml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;permalink: :title.html

exclude: [Url]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;index.md&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This file redirects your base URL (in this case, &lt;code&gt;pandermatt.ch/u&lt;/code&gt;) to a custom 404 page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
layout: redirect
redirect: '&amp;lt;YOUR-DOMAIN&amp;gt;/404'
---
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The &lt;code&gt;_posts&lt;/code&gt; folder
&lt;/h2&gt;

&lt;p&gt;Here, each entry corresponds to a specific redirect. For instance, to redirect &lt;code&gt;pandermatt.ch/u/github&lt;/code&gt; to your GitHub profile, you'd create a markdown file named &lt;code&gt;2024-01-27-github.md&lt;/code&gt; in the &lt;code&gt;_posts&lt;/code&gt; folder. This file contains similar front matter, directing users to the specified URL, which in this case is your GitHub page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_posts/2024-01-27-github.md&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
layout: redirect
redirect: 'https://github.com/pandermatt'
---
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy Your Changes
&lt;/h2&gt;

&lt;p&gt;Once you've created these files, push them to your GitHub repository. Then navigate to the GitHub Pages settings of your repository and configure it to build from the main branch.&lt;/p&gt;

&lt;h2&gt;
  
  
  🥳 Enjoy
&lt;/h2&gt;

&lt;p&gt;And that's it! With these simple steps, you've successfully transformed your GitHub Pages into a versatile platform for your custom URL shortener and dynamic QR code generator.&lt;/p&gt;

&lt;p&gt;Congratulations! You now have a powerful tool at your fingertips. Whether it's for personal branding, business, or just for fun, the possibilities are endless. Enjoy your new custom URL and dynamic QR code setup!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>githubactions</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
