Skip to content

Instantly share code, notes, and snippets.

View bobmonsour's full-sized avatar

Bob Monsour bobmonsour

View GitHub Profile
@bobmonsour
bobmonsour / countclicks.js
Created February 5, 2024 22:44
A Netlify function to count outbound link clicks and storing them in Firebase (no longer used)
// /functions/countclicks.js - A Netlify function to count outbound link clicks
// Using a Firebase Firestore Database to store the click counts.
//
// The Firestore database has a collection called posts. In each post document
// there is a recordID (same as the Airtable recordID). Each record also has a
// count that will be incremented by 1 on each invocation of this function.
//
// Two query parameters are passed to this function:
// 1. itemid - the recordID of the post (required)
// 2. itemlink - the link to the post (for my viewing pleasure)
@bobmonsour
bobmonsour / feedsformulti.js
Last active January 19, 2024 07:28
Process an OPML file to generate an array of feeds
// Read from an OPML file and write to a JSON file, processing the OPML file
// and producing the following for each of the feed items in the file:
// name: title of the feed (from the title attribute)
// url: URL of the feed (from the htmlUrl attribute)
// feed: URL of the feed (from the xmlUrl attribute)
// feedtype: type of feed (from the type attribute)
//
// NOTE: This only extracts feeds from the "CSS" and "Eleventy" outlines.
// Remove that test if you wish to extract all of the feeds.
//
@bobmonsour
bobmonsour / getDescription.js
Created April 13, 2023 04:45
An Eleventy filter that extracts the meta description from within the <head> element of a web page
// getDescription - given a url, this Eleventy filter extracts the meta
// description from within the <head> element of a web page using the cheerio
// library.
//
// The full html content of the page is fetched using the eleventy-fetch plugin.
// If you have a lot of links from which you want to extract descriptions, the
// initial build time will be slow. However, the plugin will cache the content
// for a duration of your choosing (in this example, it's set to 1 day).
//
// The description is extracted from the <meta> element with the name attribute
@bobmonsour
bobmonsour / readingtime.js
Last active April 1, 2023 22:00
This code can be used as an eleventy filter to create the reading time (in minutes) of a piece of content.
/*
* Calculate the reading time, in minutes, of a post
*
* Assumptions:
* - average reading time is 240 words per minute
* source: https://bit.ly/3HCogSr, "Most Comprehensive
* Review To Date Finds The Average Person’s Reading
* Speed Is Slower Than Previously Thought"
*
* Output: