eleventy-plugin-backlinks icon indicating copy to clipboard operation
eleventy-plugin-backlinks copied to clipboard

config.addcollection(notes) already exist

Open yazae opened this issue 1 year ago • 1 comments

Hi, following my question in your theme project eleventy-garden, I tried your plugin and got an error :

[11ty] 1. Error processing the `BacklinksPlugin` plugin (via EleventyPluginError)
[11ty] 2. config.addCollection(notes) already exists. Try a different name for your collection. (via UserConfigError)

My steps

  1. I added your plugin in my .eleventy.js :
const eleventyBacklinks = require('eleventy-plugin-backlinks');

module.exports = function(eleventyConfig) {
	
  // plugin to add backlinks
  eleventyConfig.addPlugin(eleventyBacklinks, {
		folder: '/notes', // The folder with your notes
                getData: 'description'
    });
[…]
}
  1. I installed the plugin with npm install eleventy-plugin-backlinks
  2. I commented notes.11tydata.js to avoid conflicts
  3. In the include backlinks.html, I tried to get the description passed through with getData ?
<hr>
<p class="larger" lang="en">
  Backlinks
</p>
{%- if backlinks.length > 0 -%}
<ul class="backlink">
  {%- for link in backlinks -%}
    <li class="backlink-note">
      <a href="{{- link.url -}}">
        <span class="larger">{{- link.title -}}</span>
          {{- link.preview | markdownify -}}
      </a>
    </li>
  {%- endfor -%}
</ul>
{%- else -%}
<p>
  Aucun <span lang="en">backlink</span> trouvé !
</p>
{%- endif -%}

And I got the collection error. Does your code is adding a collection note by itself then ? How do we do to resolve this collection conflict ?

My .eleventy.js is indeed adding a collection, I don’t know if it’s your theme or the code I picked elswhere, but I’m pretty sure it’s needed elswhere in the code :

  eleventyConfig.addCollection("notes", function (collection) {
    return collection.getFilteredByGlob(["notes/*.md", "notes/Journal/*.md", "notes/Fakes/*.md"])
    .sort((a, b) => b.data.date - a.data.date);
  });

If I comment the collection code, I get another error linked to your plugin : 

[11ty] options.getData is not a function (via TypeError)

Do I have to declare a getData function by myself to get the note.description I just want to get ?

Again, sorry for being such a newbie, I don’t understand js very well when it’s at this scope u_u

Thanks in advance,

Yazae

yazae avatar Aug 08 '23 08:08 yazae

Ok so I don’t need this plugin anymore since your theme works with the very simple modification I found at least, so you can close this issue if needed. I still feel that the documentation should be a bit clearer that the note collection is handled by your plugin, and how to modify the getData function, but yeah I’m a newbie.

Thanks for your works, plugins and theme, it helps a lot navigating in eleventy!

Yazae

yazae avatar Aug 08 '23 09:08 yazae