Blog content: tagging my notebook files

Contents

Notebook files

The source material for this blog comes from my notebook files, a series of large markdown files that I’ve kept since 2010, one file for each year. In them I record things I’ve done, people I’ve met, places visited, and the like. Since I prefer to keep my private life private, I don’t want to include all of the notebook entries in the blog.

On Wednesday 11 September I went though my 2019 notebook. For every entry that I wanted in the blog, I added a line like the following:

% Nikola: tags=tag1, tag2, etc; date=YYYY-MM-DD

The leading % on the line is a comment, which is stripped out by the percent_comments extension for Python Markdown. (If you go looking for this extension on the web, you won’t find it. I wrote it primarily for my own use and haven’t yet posted it to GitHub.)

Program: mk-blog-content

I then wrote a program, mk-blog-content, to locate these entries in the notebook file and create individual markdown files for each entry. As is normal for me, the program started out small and grew. It now features:

  • Putting blog posts into a posts/YYYY directory, where YYYY is a year
  • Putting static content into a pages/ directory
  • Generating slugs from the title; e.g. the title Firefox "resource:///" pages gets the slug firefox-resource-pages
  • Generating UUIDs based on an SHA-256 digest of the post content
  • Adding a fake but consistent time (HH:MM:SS CST|CDT) to the post metadata. Nikola requires a full date and time, but I can’t generate a completely random times with every run of the program because Nikola notices the time has changed and rebuilds the page. So the generated time is derived from the SHA-256 digest. That way it remains consistent if the content is unchanged.
  • Adding table related CSS if the post contains a table
  • Adding a “Contents” section if the post has more than one section
  • Privatising information in the QRetail pages by changing names and locations
  • Generating a top-level index.md page with a link to the blog and links to the static pages
  • Automatically tagging posts with awk, bash, perl, python, sql, or sed if the post contains code in those languages

Tweaking the CSS to reduce the line height on certain blocks

The bootstrap4 theme uses a line height of 1.25 time normal height within code blocks that makes them easier to read. But it also breaks up text that use Unicode box drawing characters, as can be seen below:

┌──────────────────────────────────────────────────────────────────────────────┐
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░ Eglatine Gift Shop ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│2019/09/11                                                            20:31:36│
│/home/brian/projects/qretail/qr    QRetail                                    │
│/POS/                                by                                       │
│                         Cawley Storefront Software                           │
│                                                                              │
│                          * MAIN OFFICE MENU v3.0 *                           │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│EXIT Retail System                     Utility Menu                           │
│░File Maintenance Menu░░░░░░░░░░░░░    Configuration Menu                     │
│Inventory Transaction Menu             Start a Shell                          │
│Inventory Report Menu                  Report Spool Menu                      │
│Customer / Vendor Report Menu          Keyboard Help Display                  │
│Sales Report Menu                      Commissions/SPBDAY                     │
│Daily: Combine/Report/Post/Backup      Physical Inventory Menu                │
│End-of-Day Menu                        Purchase Order Menu                    │
│Match AR's                             Lookup Sales History                   │
│End-of-Month Menu                      Sales History Reports                  │
│End-of-Period Menu                     Lookup Inventory Transactions          │
│End-of-Year Menu                       PDT Data Menu                          │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘
░░░HELP-->Enter  Menu Selection after Positioning to your Choice░░░░░░░░░░░░░░░░

To fix this, I added a new directive for mk-blog-content to haandle.

% Nikola: pre.normal-line-height

That tells the program to take the blockquote or fennced code block that follows and generate an HTML <pre> block with a normal-line-height. The HTML is written to the blog post’s markdown file; the markdown processor will simply pass it through to the HTML file. To complete the presentation, I added the following to the custom CSS file:

/* For entries tagged with "% Nikola: normal-line-height" */
pre.normal-line-height {
        line-height: 1.00
}

The result is much closer to what is displayed on a terminal screen.

  ┌──────────────────────────────────────────────────────────────────────────────┐
  │░░░░░░░░░░░░░░░░░░░░░░░░░░░░ Eglatine Gift Shop ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
  │2019/09/11                                                            20:31:36│
  │/home/brian/projects/qretail/qr    QRetail                                    │
  │/POS/                                by                                       │
  │                         Cawley Storefront Software                           │
  │                                                                              │
  │                          * MAIN OFFICE MENU v3.0 *                           │
  ├──────────────────────────────────────────────────────────────────────────────┤
  │                                                                              │
  │EXIT Retail System                     Utility Menu                           │
  │░File Maintenance Menu░░░░░░░░░░░░░    Configuration Menu                     │
  │Inventory Transaction Menu             Start a Shell                          │
  │Inventory Report Menu                  Report Spool Menu                      │
  │Customer / Vendor Report Menu          Keyboard Help Display                  │
  │Sales Report Menu                      Commissions/SPBDAY                     │
  │Daily: Combine/Report/Post/Backup      Physical Inventory Menu                │
  │End-of-Day Menu                        Purchase Order Menu                    │
  │Match AR's                             Lookup Sales History                   │
  │End-of-Month Menu                      Sales History Reports                  │
  │End-of-Period Menu                     Lookup Inventory Transactions          │
  │End-of-Year Menu                       PDT Data Menu                          │
  │                                                                              │
  └──────────────────────────────────────────────────────────────────────────────┘
  ░░░HELP-->Enter  Menu Selection after Positioning to your Choice░░░░░░░░░░░░░░░░