How do we add a redirect to a document in Wyam?

  • Page Owner: Not Set
  • Last Reviewed: 2019-05-02

I'm pulling in a bunch of documents through an XML api (no markdown/frontmeta). I'd like to add a shortcut to the final output pages. Does anyone know if this is possible with Wyam?

Comments

  • Explain "shortcut" a little better?
  • @DeaneBarker I think this is the best explanation: https://gohugo.io/content-management/urls/#aliases. It looks like wyam in theory has this support with the Redirect module, but very little doc and no examples.
  • I know how to do this in IIS, but isn't this dependent on the server platform on which the static website is hosted? How is Hugo returning a redirect from static HTML?
  • @DeaneBarker https://css-tricks.com/snippets/html/meta-refresh/
  • Oh, wow. I didn't think anyone did that anymore... I'll answer below.
  • @DeaneBarker https://wyam.io/modules/redirect - it pivots on this module in some way, so I'd love to see how it works.

Answer

Here is the code we worked out:

Redirect().WithMetaRefreshPages()  // You have to have the method call, apparently

Wyam didn't like it when we put that in an existing pipeline and tried to write both the redirect and the target file. So, we did a separate pipeline, just for redirects, like this:

Pipelines.Add("redirects",
   Documents("chapters"),  // You could load any docs here
   Redirect().WithMetaRefreshPages(),
   WriteFiles()
);

Comments

  • Worth noting that this only works if your documents have a Keys.RedirectFrom meta tag on them.