Today I Learned

Short notes on things I’ve learned recently. These are brief insights, code snippets, or concepts that I found interesting or useful.

Stashing Specific Files in Git

· Git · Development Tools

Today I learned how to stash specific files in Git instead of stashing all changes.

The Problem

Sometimes you’re working on multiple changes but only want to stash some of them. The standard git stash command stashes all modified files, which isn’t always what you want.

The Solution

You can use the git stash push command with specific file paths:

git stash push -m "My partial stash" path/to/file1.txt path/to/file2.js

This will only stash the changes to the specified files, leaving other modified files in your working directory.

Retrieving the Stash

You can retrieve the stash as usual:

git stash apply stash@{0}

Or pop it:

git stash pop stash@{0}

This technique is incredibly useful when you’re working on multiple features simultaneously and need to switch contexts quickly.

Creating Custom Hugo Shortcodes

· Hugo · Web Development

Today I learned how to create custom shortcodes in Hugo to make content creation more efficient.

What are Shortcodes?

Shortcodes are simple snippets inside your content files that Hugo will render using predefined templates. They’re a great way to add custom HTML or reusable components without writing raw HTML in your Markdown files.

Creating a Basic Shortcode

To create a shortcode, add an HTML file to the layouts/shortcodes/ directory. For example, to create a “notice” shortcode:

<div class="notice {{ .Get 0 }}">
  {{ .Inner }}
</div>

Using the Shortcode

You can then use it in your Markdown content like this:

{{% notice warning %}}
This is a warning notice with a yellow background.
{{% /notice %}}

Parameters

Shortcodes can accept positional and named parameters:

  • Positional: {{ .Get 0 }}, {{ .Get 1 }}
  • Named: {{ .Get "type" }}, {{ .Get "color" }}

This makes shortcodes extremely flexible for creating reusable content components.