A simple navigation menu

7 views
Skip to first unread message

Alexey Beshenov

unread,
Aug 13, 2021, 6:09:05 PMAug 13
to hakyll
Hello,

I'm new to Hakyll and I'm trying to convert a simple website to it right now. I came across a rather standard issue, but I'm not sure about the way it can/should be solved in Hakyll.
(I think this issue is ignored in the example site that comes with the source.)

So let's say I have three pages foo, bar, baz, and I want to add to each page a menu like
  <ul>
    <li><a href="/foo.html">foo</a></li>
    <li><a href="/bar.html">bar</a></li>
    <li><a href="/baz.html">baz</a></li>
  </ul>
only WITHOUT adding a link to the page itself; e.g. foo.html should contain something like
  <ul>
    <li>foo</li>
    <li><a href="/bar.html">bar</a></li>
    <li><a href="/baz.html">baz</a></li>
  </ul>
and so on...


I thought it could be done in the template itself; however, the documentation seems to only mention checking if a key exists via $if(key)$ ... $else$ ... $endif$.

Thank you very much for any suggestions!

--
With best regards,
Alexey

Alexander Batischev

unread,
Aug 14, 2021, 10:48:08 AMAug 14
to hak...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi!

On Fri, Aug 13, 2021 at 03:09:05PM -0700, Alexey Beshenov wrote:
>So let's say I have three pages foo, bar, baz, and I want to add to
>each
>page a menu like
> <ul>
> <li><a href="/foo.html">foo</a></li>
> <li><a href="/bar.html">bar</a></li>
> <li><a href="/baz.html">baz</a></li>
> </ul>
>only WITHOUT adding a link to the page itself; e.g. foo.html should contain
>something like
> <ul>
> <li>foo</li>
> <li><a href="/bar.html">bar</a></li>
> <li><a href="/baz.html">baz</a></li>
> </ul>
>and so on...

I don't have a worked example for this, but I can point you at a couple
features that will probably help with this.

First of all, templates support loops; see $for$ in [1].
With that, you can add a list of pages to its context, and then use
a loop to enumerate them. The example in the docs show how to construct
the context; you'll probably use `listFieldWith`[2] and filter out the
current page's address.

1. https://hackage.haskell.org/package/hakyll-4.14.0.0/docs/Hakyll-Web-Template.html
2. https://hackage.haskell.org/package/hakyll-4.14.0.0/docs/Hakyll-Web-Template-Context.html#v:listFieldWith

Then you'll need a way to enumerate the pages. For that, you can use
`getMatches`[3], and then for each identifier call `getRoute`[4] to get
the filenames. You can look at Hakyll.Web.Tags module (and various tags
tutorials) to see how this could work.

3. https://hackage.haskell.org/package/hakyll-4.14.0.0/docs/Hakyll-Core-Metadata.html#v:getMatches
4. https://hackage.haskell.org/package/hakyll-4.14.0.0/docs/Hakyll-Core-Compiler.html#v:getRoute

Hope this helps.

- --
Regards,
Alexander Batischev

PGP key 356961A20C8BFD03
Fingerprint: CE6C 4307 9348 58E3 FD94 A00F 3569 61A2 0C8B FD03

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEzmxDB5NIWOP9lKAPNWlhogyL/QMFAmEX15kACgkQNWlhogyL
/QMXPQ/+LlTy8cJrUBxk0nViQewmnhhjJMAa859h9MqLajFfDhKB6StzS4CM+PAB
ygDLUZlz1RUh5exQGNk7pj7prznS4u9cR9ADjOdlw85YWH9l9CqbJKPpoE7z1qJ8
12PAW1KW9j3mzJ71LCu9eoB46YEfVCWleV6kOpcpL/sbKlyIqOCSNUnEYbLMBxNN
9aLMYW1TJM7KzFJgFzI+x2AgZ7gpMCnI1I+B1Im7G6n2Zq8qwsC7GyXydgGqT0+G
WxdWgkT/JTjLJ7DVNEpmCFjQPLuzF8zErDdrYT9FAAICuzk0sMkvzKQtT3VzSJrz
RFJ6gb2Z0cZW0iuZkh92tkV41Won8qWw9LFkcyUO/c5f6LqzBhJskcPaK97D7F/S
yo/0ywTXQyRg5VUuV0Gjx0cn+Td+UiqfIClgmR5AiP0vSA+7+wvOWA4XL59bzSYs
i6ZP0Er2wM9ZVU6vF6GoDQJepyrxHOxcWsn4qA5SGZc0IqNgAeR5O+dKY4nGH4d8
Mk9cnmdmKTCxOKJFeSPIab/+7xk83w0uATPlZXemE7C7vnoDXio2rGfCLByQv5dR
XB3GDcnQbbxz/NobMAkcpyQNiBU5U/4jBJr903v/niOR9DXbwul88cZrR0p8U7a0
aNHYK4xrMC8twnFUUNuNjD2vkdeSCmQukmJqSOzzxX9FN26IP5I=
=+3cv
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages