Let me begin by being very clear. This is not a very good idea. I just got back from a much delayed honeymoon with my wife (apparently right before the mask mandates all come crashing back) and haven't written code for a while so perhaps I was a bit desperate to create something useless. That being said, working on this did let me kick the tires a bit on a few Eleventy things and that's always a good idea.
This post was inspired by a follower on Twitter who saw this announcement by the GitHub folks:
Releasing our first public project to the world! From our team within GitHub that explores the future of development, we're excited to share:
✨✨ Flat Data ✨✨
We asked ourselves:
How easy can we make it to work with live-updating data?
Check it out!https://t.co/njLvo3CxNj pic.twitter.com/jBDnnUD4y3
Ok, so let me start off by saying that a) I'm not sure this is a good idea and b) it may already exist and I just don't know about it. This all came about from me doing some research on an Eleventy tagged question on StackOverflow. If you aren't aware, Liquid has a tag built in called capture. It looks like so:
I'm on vacation this week (one of the benefits of working for Adobe are two shutdowns during the year) and haven't really had a chance to write a lick of code (been busy grinding levels in Black Ops multiplayer), but yesterday I found myself working on a small demo for no real important reason outside of just wanting to see what would happen. For folks outside of America, the MPA (formally the MPAA) is the Motion Picture Association. They're responsible for assigning ratings to movies released in America. There's a lot to be said about these ratings, and if you haven't seen it, I highly recommend "This Film is Not Yet Rated" as it details some of the hypocritical ratings giving out by the association.
One feature that some CMS systems have is the ability to handle short URLs that map to pages on the site. I'm not talking about services like TinyURL, but internal systems specific to a site. So for example, Adobe.com supports "go" URLs where you can go to this url: https://adobe.com/go/coldfusion and it maps to https://www.adobe.com/products/coldfusion-family.html. I decided to see if I could implement this with Eleventy. My demo is using Netlify but in theory could work anywhere that lets you specify redirects via a file.
A few weeks ago I shared a couple of blog posts describing how to add PDFs to your Jamstack site. The first talked about the using the Adobe PDF Embed API to give you more control over viewing PDFs in an Eleventy site. The second example took it a bit further by using Adobe's PDF Services API to generate thumbnails of the PDFs when the Eleventy site was generated. Since I wrote those posts, we (oh, I did tell you I work for Adobe, right?) released a new service, the PDF Extraction API.
Last year (sometimes that surprises me, time has been so weird with COVID) I wrote about using Algolia with Eleventy, and specifically how I added it here (Adding Algolia Search to Eleventy and Netlify - Part Two). A few weeks ago I discovered an issue with my implementation that caused the index on Algolia's side to be empty. I fixed that issue and updated my blog post with a detailed description on top. Everything was perfect.
A few days ago I posted ("Using Lunr with Eleventy via Netlify Serverless Functions") about how you could use Lunr via serverless functions. The thinking was that it would help make Lunr more useful for large content sites. In a "typical" Lunr example, you load your data and client all in the browser, which means indexing a lot of content wouldn't be very effecient. That post demonstrated that you absolutely could run Lunr in a serverless function, but it bothered me that the index was being recreated on every search.
Lunr is a great client-side search engine that works really well with the Jamstack. (Be sure to see my earlier posts on the topic: Adding Search to your Eleventy Static Site with Lunr, Integrating Navigation Search with Lunr and Eleventy, and Using Pre-Built Lunr Indexes with Eleventy) While I like the simplicity of Lunr, it requires that your searched data be loaded on the client-side. This makes it a bad fit for large sites. For example, my blog has over six thousand posts so I went Algolia instead. However, I was doing some thinking recently and realized that Lunr can also be used on the server as well. I decided to take a stab at trying this out and here's what I came up with.