Skip to content

Instantly share code, notes, and snippets.

View daviddarnes's full-sized avatar
🧱
he/him

David Darnes daviddarnes

🧱
he/him
View GitHub Profile
@daviddarnes
daviddarnes / last-month-day.liquid
Created February 1, 2022 17:08
Calculate the last day of the month using liquid only
{%- capture current_month %}{{ site.time | date: '%m' }}{% endcapture -%}
{%- capture future_date %}{{ site.time | date: '%Y' }}-{% if current_month == 12 %}01{% else %}{{ current_month | plus: 1 }}{% endif %}-01{% endcapture -%}
{%- capture epoc_end_month_date %}{{ future_date | date: '%s' }}{% endcapture -%}
{{ epoc_end_month_date | minus: 86400 | date: "%B" }}{{ " " }}
{%- assign day = epoc_end_month_date | minus: 86400 | date: "%-d" -%}
{%- case day -%}
{%- when '1' or '21' or '31' -%}{{ day }}st
{%- when '2' or '22' -%}{{ day }}nd
{%- when '3' or '23' -%}{{ day }}rd
{%- else %}{{ day }}th
@daviddarnes
daviddarnes / clips.json
Created January 28, 2022 14:28
Example clips file for Nova editor
{
"clips": [
{
"content": "The content of the $1 clip ${1:placeholder}",
"name": "Example single clip",
"syntax": "html",
"trigger": "example"
},
{
"name": "Clips group example",
@daviddarnes
daviddarnes / .eleventy.js
Created January 20, 2022 09:14
Scrape URLs and display card like HTML using a nunjucks shortcode
// require all the metascraper rules at the top of the config file
const metascraper = require("metascraper")([
require("metascraper-image")(),
require("metascraper-logo")(),
require("metascraper-logo-favicon")(),
require("metascraper-publisher")(),
require("metascraper-title")(),
require("metascraper-url")(),
]);
@daviddarnes
daviddarnes / skip-eleventy-files-dev.js
Created January 14, 2022 14:57
Skip template files in development if they're too large
if (process.env.ELEVENTY_ENV === "development") {
// Skipping the search index file speeds up local builds
console.log("Skipping ./src/search.njk")
eleventyConfig.ignores.add("./src/search.njk")
}

Hey,

Due to the nature of your business I'm afraid I'll have to decline your offer. Cryptocurrencies are accelerating the destruction of our planet, and create no value in return beyond speculation. Helping a crypto company doesn't meet my standards for ethical consulting, so I will not be engaging with you.

All the best.

@daviddarnes
daviddarnes / email.md
Created November 14, 2021 17:17
Cold email recruiter email template

Hey,

Can you tell me where you got my details, my name and email, from? Legally you must provide this information. Also you’re breaking data protection law by storing my information without my consent, so please remove it or else I’ll need to report you to the ICO.

Thanks

@daviddarnes
daviddarnes / .eleventy.js
Last active August 7, 2021 09:41
Create SVG sprites in Eleventy using a directory SVG files as a reference, credit to @patrickxchong and @maxboeck for the performance technique and original implementation respectively
module.exports = (eleventyConfig) => {
// ...
// Icon Sprite
eleventyConfig.addWatchTarget("src/assets/svgs/");
eleventyConfig.on("beforeBuild", svgsprite);
eleventyConfig.addNunjucksAsyncShortcode("svgsprite", svgsprite);
eleventyConfig.addShortcode("icon", (name) => {
return `<svg class="icon icon--${name}" role="img" aria-hidden="true" width="24" height="24"><use xlink:href="#icon-${name}" fill="currentColor"></use></svg>`;
@daviddarnes
daviddarnes / pluralise.twig
Created October 31, 2017 13:11
Pluralising with Twig
{% spaceless %}
{% if integer > 1 %}
{{ plural }}
{% else %}
{{ singular }}
{% endif %}
{% endspaceless %}
@daviddarnes
daviddarnes / Anchor Custom Background Image Field
Last active October 22, 2020 17:30
Custom Image field for Anchor CMS themes.
<div class="bg-header"
<?php
/*
This is to show a custom field from an article.
It will need to be created in the metadata section before it can be used in the post edit area.
In this case the custom field will need to be called 'image' and be set as an image custom field in the dropdown for type.
*/
$image = article_custom_field('image'); // Applying a variable to the custom field, so it can be reused with ease
if ( !empty($image) ) : // Check if the field is empty, if it is the process stops here
?>
@daviddarnes
daviddarnes / head.html
Last active January 20, 2020 10:27
Redirect Ghost preview links to your JAMstack site
<script type="text/javascript">
if (location.hostname.includes('ghost.io') && !location.href.includes('ghost.io/p/')) {
location.hostname = 'my-jamstack-site.com';
}
</script>