Giter Club home page Giter Club logo

11ty-2552-merged's Introduction

11ty Merged Collections

This repo merges some mock "dynamically" fetched content via src/_data/posts.js, and merges it with some posts in the src/posts/*.njk directory and puts them all into a single collections.notes collection.

See the objectively boring src/posts/pagination.njk script, as well as it's front matter in the src/posts/pagination.11tydata.js template data file (since it uses some JavaScript for eleventyComputed values, and I prefer it to JavaScript front matter to shim the properties from the JSON data file into computed Eleventy properties).

Also note the src/posts/posts.11tydata.json directory data file, which sets a default layout and tags for each post in the ./src/posts/* directory.

Finally, there is a src/posts/tags.njk file which paginates over the collections.notesTags collection (see .eleventy.js) and creates tag archive pages for the posts that are in the "notes" collection.

Most interesting is the questionable use of collection hacking in .eleventy.js:

eleventyConfig.addCollection("dynamic", collectionApi => collectionApi);

When using Nunjucks syntax, this lets us do scary things like this gem in src/posts/tags.njk:

{# This weird live querying of collections only seems to work w/ Nunjucks syntax. #}
{%- set posts = collections.dynamic.getFilteredByTags("notes", tag) -%}

Is it a good idea? Probably not.
Did it work during my 3 minutes of testing? Sure.
Was it easier than re-building collections for every dynamically set tag? Ab-so-lutely.
Was it a good idea? Probably not.

11ty-2552-merged's People

Contributors

pdehaan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.