Swizec Teller - a geek with a hatswizec.com

Senior Mindset Book

Get promoted, earn a bigger salary, work for top companies

Senior Engineer Mindset cover
Learn more

    Are you annoyed by the extra space after your name [name|]?

    The extra space is no more! All fixed. Here's a little backstory that I hope inspires you to build more tools for yourself.

    R4Tg3Jpnga08ifc

    Back in 2018, I built TechLetter.App as part of a 24 hour challenge to build and launch an app. I wanted an easy to way to turn markdown into shippable newsletters and thought others might too.

    TechLetterApp in action

    They did not. TechLetter.App turned into the perfect example of Robin Sloane's An app can be a home-cooked meal. Gets about 30 visits per month. Mostly from me.

    I can't imagine living without this tool and ConvertKit's banner that they're sunsetting the old editor with a Paste HTML option fills me with dread.

    ConvertKit loves their new editor
    ConvertKit loves their new editor

    May have to change email providers over this 😅

    How it works

    TechLetter.App was one of the case studies peppered into Serverless Handbook.

    It takes markdown, uses the unist ecosystem to parse the input, pass it through a chain of custom plugins, and spit out a bunch of React components. The Export button then takes the raw HTML from the parent node of the rendered document.

    Plugins do the hard work. Some make calls to serverless functions that take screenshots, others transform text to other text.

    The core business logic looks like this:

    remark()
        .use(urlThumbnail, {
            domains: [
                "m.twitter.com",
                "twitter.com",
                "youtube.com",
                "youtu.be",
                "instagram.com",
                "codesandbox.io",
            ],
        })
        .use(twitterUserLinks)
        .use(codeScreenshot)
        .use(githubLinks)
        .use(remarkGiphySearch)
        .use(remarkNameOrFriend)
        .use(remarkSparkJoy)
        .use(remark2react, {
    	    // ...
    

    A chain of syntax tree transformations. Each .use() accepts a Remark plugin that transforms the syntax tree.

    The space-after-name bug

    Yes many readers complained about the extra space since I added the feature in August 2020. About one per quarter. It never quite made the priority list 😇

    I use a custom bit of markdown syntax – [name|something else] – to inject your name into the email. If the system knows your name, it uses that, otherwise the something else part.

    That happens via liquid syntax that ConvertKit and most other emailing systems understand. My custom Remark plugin finds the weird markdown syntax and turns it into liquid syntax.

    Like this:

    const nameOrFriend = /^\s*name\s*\|(.*)$/
    
    export function remarkNameOrFriend() {
      return (tree) => {
        visit(tree, "linkReference", (node, index, parent) => {
          if (node.label.match(nameOrFriend)) {
            node.type = "text"
    
            node.value = node.label.replace(
              nameOrFriend,
              '{% if subscriber.first_name != blank %} {{ subscriber.first_name | truncatewords: 1, "" | capitalize }} {% else %} $1 {% endif %}'
            )
            node.children = null
          }
        })
      }
    }
    

    Can you spot the bug?

    It's right here:

        '{% if subscriber.first_name != blank %} {{ subscriber.first_name | truncatewords: 1, "" | capitalize }} {% else %} $1 {% endif %}'
    

    That has spaces between the liquid tags 🤣

    Needs to be:

        '{% if subscriber.first_name != blank %}{{ subscriber.first_name | truncatewords: 1, "" | capitalize }}{% else %}$1{% endif %}'
    

    And that's the bug that took me 919 days to fix.

    Cheers,
    ~Swizec

    PS: getting this deployed was an ordeal because software breaks when you change it. But that's a post for another day

    Published on March 21st, 2023 in TechLetterApp, Serverless

    Did you enjoy this article?

    Continue reading about Are you annoyed by the extra space after your name [name|]?

    Semantically similar articles hand-picked by GPT-4

    Senior Mindset Book

    Get promoted, earn a bigger salary, work for top companies

    Learn more

    Have a burning question that you think I can answer? Hit me up on twitter and I'll do my best.

    Who am I and who do I help? I'm Swizec Teller and I turn coders into engineers with "Raw and honest from the heart!" writing. No bullshit. Real insights into the career and skills of a modern software engineer.

    Want to become a true senior engineer? Take ownership, have autonomy, and be a force multiplier on your team. The Senior Engineer Mindset ebook can help 👉 swizec.com/senior-mindset. These are the shifts in mindset that unlocked my career.

    Curious about Serverless and the modern backend? Check out Serverless Handbook, for frontend engineers 👉 ServerlessHandbook.dev

    Want to Stop copy pasting D3 examples and create data visualizations of your own? Learn how to build scalable dataviz React components your whole team can understand with React for Data Visualization

    Want to get my best emails on JavaScript, React, Serverless, Fullstack Web, or Indie Hacking? Check out swizec.com/collections

    Did someone amazing share this letter with you? Wonderful! You can sign up for my weekly letters for software engineers on their path to greatness, here: swizec.com/blog

    Want to brush up on your modern JavaScript syntax? Check out my interactive cheatsheet: es6cheatsheet.com

    By the way, just in case no one has told you it yet today: I love and appreciate you for who you are ❤️

    Created by Swizec with ❤️