Skip to content
Discussion options

You must be logged in to vote

OK, I think you need eleventyComputed. Here's my modified ./src/projects/projectA.njk:

---js
{
  slug: "../projectA/",
  eleventyComputed: {
    index(data) {
      return data.projects.findIndex(x => x.url === data.slug);
    }
  }
}
---

index: {{ index }}

<a href="{{ projects[(index-1 + projects.length) % projects.length].url }}">previous project</a> 
<a href="{{ projects[(index+1 + projects.length) % projects.length].url }}">next project</a>

And the generated www/projects/projectA/index.html looks like this:

index: 0

<a href="../projectC/">previous project</a> 
<a href="../projectB/">next project</a>

Basically, I moved the hardcoded URL from the .findIndex() method into a slug front…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@pdehaan
Comment options

pdehaan Aug 17, 2022
Collaborator

Answer selected by maschinenzeitmaschine
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants