How do I duplicate an old directory structure with pages ending in .html?

Hello all,

I have a website that’s in sore need of a refresh, so I’m test driving Zola as a replacement.

My old scheme was organically grown writing raw HTML and m4 macros. This was fun to do at the time, but I got sick of the fragile build system. One difference I’ve noticed between my old homegrown system and Zola is that I made heavy use of pages ending with .html, whereas Zola does not end webpages with .html. My intent was to preserve the directory and filename structure so previous links to my website across the internet don’t break.

I learned about aliases in front-matter earlier today, but try as I might, I am unable to get aliases to work in at least two capacities:

  1. My blog on my deployed website exists at (link limit) https :// www . wdj-consulting . com / blog.html. Since I want to use the functionality, I use a Zola section to sort all the blog posts under content/blog; sections do not have a concept of an alias, so I can’t map content/blog/_index.md to http://127.0.0.1:1111/blog.
    To remedy this, I tried creating a content/blog/index.md with a template that appends
    section.content, with render = false in content/blog/_index.md, but apparently the template doesn’t have access to section.content for some reason (I don’t have an example of this to share, it’s possible I messed up setting this up properly).

  2. I created a dummy content/blog/hello.md post, which shows up under blog/hello, since Zola creates an index.html. I am unable to get Zola to generate a redirect with the following aliases front matter:

aliases=["hello.html"]

I would expect a redirect from http://127.0.0.1:1111/blog/hello.html to http://127.0.0.1:1111/blog/hello, but Zola does not generate such a redirect and instead emits a 404.

Assuming I want to take advantage of Zola sections to automatically sort blog posts, and make sure that the remaining blog posts original locations are still valid (even via redirect), what options do I have to make Zola preserve my old directory structure?

Okay in my contrived hello.md post, if I want a redirect from http://127.0.0.1:1111/blog/hello.html to http://127.0.0.1:1111/blog/hello, I need to do aliases=["blog/hello.html"].

However, aliases=["hello.html"] still does not generate a redirect. Based on my current understanding, a redirect page from http://127.0.0.1:1111/hello.html to http://127.0.0.1:1111/blog/hello should be generated, but Zola does not generate such a redirect. Why is that?

This is weird, trying it on the zola docs it does work. I get:

<!DOCTYPE html>
<html>
    <head>
        <link rel="canonical" href="https://www.getzola.org/documentation/content/linking/" />
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta http-equiv="refresh" content="0;url=https://www.getzola.org/documentation/content/linking/" />
    </head>
</html>

when in public/hello.html when adding an alias to the linking doc. Do you have the repo up somewhere?

Do you have the repo up somewhere?

Sure. I do have the repo up here. hello.md is here.

I’m not sure what happened, but as of this morning, the alias for hello.html started working. As of matter of fact, I removed the extra alias to “blog/hello.html” without stopping the Zola binary, and that alias still works after Zola regenerates the site. It seems that Zola only will honor changes in aliases for me when I fully stop and restart the binary. Is this the correct/intended behavior (but perhaps I missed it in the documentation)?

Btw, here is some relevant system information that I forgot :slight_smile:

William@William-THINK  ~/prj/Consult/website2
$ zola -V
zola 0.7.0

William@William-THINK  ~/prj/Consult/website2
$ uname -a
MSYS_NT-6.1-7601 William-THINK 3.0.7-338.x86_64 2019-05-24 10:50 UTC x86_64 Msys

William@William-THINK  ~/prj/Consult/website2
$ rustc -V
rustc 1.36.0-nightly (8869ee03d 2019-05-23)

Secondly, how should I handle an alias to blog.html if sections cannot have aliases? Is this a feature that can be possibly added in a limited capacity for people like me :stuck_out_tongue:?

For now, I’ve just put a rewrite rule on the nginx server for this. That way, people with the old link to my blog can still access it while I transition to the index.html-only way of how Zola does things. Not exactly ideal for me, but it’ll do for now.

Aliases can be added to sections and it should be easy to implement.

I’ve added aliases to sections, it will be there in 0.8.0

1 Like