How To Show Post Excerpts on Blogger when Writing with Markdown, Pandoc and Minify


Awesome Tips Series about Blogger

The Problem

I want to show partial posts in homepage, label page, search page or index pages.

I write posts with Markdown using Atom Editor, then use Pandoc to convert it to HTML, then use minify to remove commented draft content and minified the html and CSS to reduce the html size.

We can do this by add insert jump break button in Blogger:

It’s equivalent to add <!--more--> in the html code in the Markdown file.

How to Keep the Jump Break(Read More) block in Minify

By default minify removes all comments, so it will also remove the <!--more-->.

Luckily, we can use minify’s –html-keep-conditional-comments feature to keep the <!--more-->.

We can create the following conditional comments that will actually exist in all browser:(if browser’s type is not XYZ)

Bonus: Add a Snippet in Atom Editor

CLICK ME to EXPAND To add this easily in Atom Editor, we can define the following snippet by Applications: Open Your Snippets in the command palette (cmd+shift+p):

Add Read More Block Automatically After TOC

It’s a good place to add Read More after TOC(table of contents).

We can use pandoc --toc --toc-depth=4 to generate TOC for all h1, h2, h3 and h4 headers.
We can add toc:true(false) in the Markdown yaml-meta-block to control whether add TOC or not.

---
toc: true
---

To make it Pandoc automatically Read More after TOC, we can generate our own template based on default template: pandoc -D html >$HOME/.pandoc/templates/default.html.
Then update default.html to change the if(toc) block like below:

Last but not least, there is one problem in the generate TOC, it uses relative url: <a href=#the_anchor_id>the_text</a>, but it will not work when it shows in label page, search page etc, as the base url is (for example https://lifelongprogrammer.blogspot.com/2019/07), not the url of the post.

Base tag would not work: as only the first base tag works, and it affects all relative links.

We can use javascript to iterate all TOC links: find its post title, and change tTOC link’s base to the post title’s url.

Bonus: Blogger Conditional Tags for different page types

Minifier

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)