halostatue

halostatue

TableauRedirectsExtension - Cool URIs don't change with Tableau

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.

TableauRedirectsExtension is a Tableau extension for generating redirects because Cool URIs don’t change. Redirects are specified in configuration and content metadata and can generate HTML redirects or a JSON redirect map to produce redirect configurations for Caddy, nginx, Apache, or other servers.

HTML Meta-Refresh Redirects

When serving a Tableau site via AWS S3 or similar scenarios, it is often necessary to produce browser-based redirects using HTML files with the “meta refresh” approach. This is generated for directory-style paths and HTML-like files (.html, .htm, and .php). Other redirects configured (redirecting a .jpg to a .svg, for example) will not be written in this way.

config :tableau, TableauRedirectsExtension,
  redirects: %{"/old-url/" => "/new-url/"}
<!DOCTYPE html>
<!-- /old-url/index.html -->
<meta charset="utf-8">
<title>Redirecting to /new-url/…</title>
<link rel="canonical" href="/new-url/">
<meta http-equiv="refresh" content="0; url=/new-url/">
<p>Redirecting to <a href="/new-url/">/new-url/</a>…</p>

JSON Manifest Redirects

When a Tableau site is behind another server like Caddy, Apache, or nginx it is often better to use the generated redirects.json to generate appropriate redirect configuration files. The configuration (and content metadata) produce the mapping:

config :tableau, TableauRedirectsExtension,
  redirects: %{"/old-url/" => "/new-url/"}
{
  "permanent_redirects": [
    {
      "from": ["/old", "/old/", "/old/index.html"],
      "type": "path",
      "to": "/new/",
      "target_type": "internal"
    }
  ]
}

Which can then be converted into a Caddyfile for inclusion:

redir /old-url /new-url permanent
redir /old-url/ /new-url permanent
redir /old-url/index.html /new-url permanent

Configuration

Configuration may be either global (for content that has been removed but redirects to somewhere that is either useful or explains) or specified in the content frontmatter metadata.

Global Redirects

config :tableau, TableauRedirectsExtension,
  enabled: true,
  html: %{enabled: true, message: "Redirecting..."},
  json: %{enabled: true},
  redirects: %{
    "/old-path/" => "/new-path/",
    "/external/" => "https://example.com",
    "/bad-info/" => "/removed/#bad-info"
  }

Frontmatter Redirects

---
title: My Post
permalink: /posts/my-post/
redirects:
  aliases:
    - /blog/old-post
    - /old-location/post
  fragments:
    /other-old-post: "#new-section"
---

An alias redirect goes to the content’s permalink, whereas a fragment redirect goes to the content’s permalink at a specific URI fragment.

https://github.com/halostatue/tableau_redirects_extension

Where Next?

Popular in Announcing Top

OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
brainlid
LangChain is short for Language Chain. An LLM, or Large Language Model, is the “Language” part. This library makes it easier for Elixir a...
New
mbuhot
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs. Generate and serve a JSON Open API ...
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
josevalim
Hello everyone, We have just released NimbleCSV which is a small and fast CSV parsing library for Elixir. It allows developers to define...
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 10978 107
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement