Tableau.TagExtension (tableau v0.30.0)
View SourceCreates pages for tags found in posts created by the Tableau.PostExtension.
The :tags key provided on every page in the assigns is described by tags/0.
The @page assign passed to the layout provided in the configuration is described by page/0.
Unless a tag has a slug defined in the plugin tags map, tag names will be converted to slugs using Slug.slugify/2 with options provided in Tableau configuration. These slugs will be used to build the permalink.
Configuration
:enabled- boolean - Extension is active or not.
:layout- module - TheTableau.Layoutimplementation to use.:permalink- string - The permalink prefix to use for the tag page, will be joined with the tag name.:tags- map - A map of tag display values to slug options. Supported options::slug- string - The slug to use for the displayed tag
Configuring Manual Tag Slugs
config :tableau, Tableau.TagExtension,
enabled: true,
tags: %{
"C++" => [slug: "c-plus-plus"]
}With this configuration, the tag C++ will be have a permalink slug of c-plus-plus,
Eixir will be elixir, and Bun.sh will be bun-sh.
Layout and Page
To take advantage of tag extension, you'll need to define a layout that will render each "tag page" and a normal Tableau.Page that lists all tags on your site.
Layout to render a tag page
defmodule MySite.TagLayout do
use Tableau.Layout, layout: MySite.RootLayout
def template(assigns) do
~H"""
<div>
<h1>Tag: #{@page.tag}</h1>
<ul>
<li :for={post <- @page.posts}>
<a href={post.permalink}> {post.title}</a>
</li>
</ul>
</div>
"""
end
endPage to render all tags
This example page shows listing all takes, sorting them by the number of posts for each tag.
defmodule MySite.TagPage do
use Tableau.Page,
layout: MySite.RootLayout,
permalink: "/tags",
title: "Tags"
def template(assigns) do
sorted_tags = Enum.sort_by(assigns.tags, fn {_, p} -> length(p) end, :desc)
assigns = Map.put(assigns, :tags, sorted_tags)
~H"""
<div>
<h1>Tags</h1>
<ul>
<li :for={{tag, posts} <- @tags}>
<a href={tag.permalink}>tag.tag</a>
<span>- {length(posts)}</span>
</li>
</ul>
</div>
"""
end
end
Summary
Types
@type page() :: %{ title: String.t(), tag: String.t(), permalink: String.t(), posts: [Tableau.PostExtension.post()] }
@type tags() :: %{required(tag()) => [Tableau.PostExtension.post()]}