TableauExcerptExtension - Extract excerpts from your Tableau posts

Over the last several months, I’ve been using Tableau to rebuild my long-neglected website. Tableau is part of the Elixir Tools project headed by @mhanberg, and is built on top of MDEx by @leandrocp. This library is one of ten libraries and Elixir extensions that I built. Most of these were built with the assistance of Kiro.

TableauExcerptExtensions is a Tableau extension that works with Tableau.PostExtension and automatically extracts excerpts from posts for use in index pages. Posts with an existing excerpt field will
be unmodified, and there are three strategies for excerpt extraction.

  1. Excerpt Range Markers can excerpt specific content from anywhere in the post.
---
title: My Post
---

Opening paragraph.

<!--excerpt:start-->This specific section becomes the excerpt.<!--excerpt:end-->

More content.

This extracts only the marked content as the excerpt:

%{excerpt: "This specific section becomes the excerpt."}
  1. Excerpt Split Marker extracts all content before the split marker.
---
title: My Post
---

This is the first paragraph that will become the excerpt.<!--more-->

This is the rest of the post content.

This extracts whatever content is before <!--more-->:

%{excerpt: "This is the first paragraph that will become the excerpt."}
  1. Structural Excerpt Extraction is used as a fallback when no markers are found. This configurable strategy will extract the first N paragraphs (:paragraph), the first N sentences (:sentence), or the first N words (:word). These are simple definitions based on the number of newlines, terminal punctuation, or words split by spaces.

When excerpts are pulled from Markdown content, there is some automatic cleaning:

  • Footnotes are removed from the excerpted text;
  • Reference links are converted to inline ([text][ref][text](url))
  • Whitespace is normalized

Rendering Excerpts

Excerpts are captured in the source content format, so it will be necessary to call the appropriate content formatter for the excerpt.

defmodule MySite.PostsPage do
  def template(assigns) do
    temple do
      for post <- posts do
        if post[:excerpt] do
          div class: "excerpt" do
            Tableau.markdown(post.excerpt)
          end
        end
      end
    end
  end
end
3 Likes