Tableau.PostExtension (tableau v0.24.0)
View SourceContent files (with YAML frontmatter) in the configured posts directory will be automatically compiled into Tableau pages.
Certain frontmatter keys are required and all keys are passed as options to the Tableau.Page
.
Options
Frontmatter is compiled with yaml_elixir
and all keys are converted to atoms.
:title
- The title of the post.:permalink
- The permalink of the post.:title
will be replaced with the posts title and non alphanumeric characters removed. Optional.:date
- A string representation of an ElixirNaiveDateTime
, often presented as asigil_N
. This will be converted to your configured timezone.:layout
- A string representation of a Tableau layout module.:converter
- A string representation of a converter module. (optional)
Example
id: "Update.Volume3"
title: "The elixir-tools Update Vol. 3"
permalink: "/news/:title"
date: "~N[2023-09-19 01:00:00]"
layout: "ElixirTools.PostLayout"
converter: "MyConverter"
Permalink
The permalink is a string with colon prefixed template variables.
These variables will be swapped with the corresponding YAML Frontmatter key, with the result being piped through to_string/1
.
In addition, there are :year
, :month
, and :day
template variables.
Configuration
:enabled
- boolean - Extension is active or not.:dir
- string or list of strings - Directories to scan for markdown files. Defaults to_posts
:future
- boolean - Show posts that have dates later than the current timestamp, or time at which the site is generated.:permalink
- string - Default output path for posts. Accepts:title
as a replacement keyword, replaced with the post's provided title. If a post has a:permalink
provided, that will override this value for that post.:layout
- string - Elixir module providing page layout for posts. Default is nil
Example
config :tableau, Tableau.PostExtension,
enabled: true,
dir: "_articles",
future: true,
permalink: "/articles/:year/:month/:day/:title",
layout: "MyApp.PostLayout"
Content formats
If you're interested in authoring your content in something other than markdown (or you want to use a different markdown parser), you can configure a converter for your format in the global configuration.
Currently the Tableau.MDExConverter
is the only builtin converter, but you are free to write your own!
# configs/config.exs
config :tableau, :config,
converters: [
md: Tableau.MDExConverter,
adoc: MySite.AsciiDocConverter
],
As noted above, a converter can be overridden on a specific page, using the frontmatter :converter
key.
Summary
Types
@type post() :: %{ body: String.t(), file: String.t(), layout: module(), date: DateTime.t() }