Skip to content

Generating "Categories" from data file, show content per category that has category in front matter #1882

Answered by pdehaan
madsem asked this question in Q&A
Discussion options

You must be logged in to vote

Re: collection... Not sure I'm following it completely. It seems to just be a sorted copy of the global data file.

  const topics = require("./site/_data/topics");

  // Topics collection
  config.addCollection("topics", () => {
    const list = new Set();

    topics.forEach((topic) => {
      list.add(topic);
    });

    return Array.from(list).sort();
  });

I believe you can initialize a Set with an array, so this could probably almost be reduced to:

const list = new Set(topics);
return Array.from(list).sort();

But then why bother convert from an Array to a Set then back to an Array [which is sorted]?

So why not:

return topics.sort();

Then we can just question why we need a global dat…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by madsem
Comment options

You must be logged in to vote
2 replies
@pdehaan
Comment options

@madsem
Comment options

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