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 / index.njk
Created June 1, 2019 08:02
Eleventy blog from API
<h1>API post list</h1>
<ul>
{% for post in posts %}
<li>
<a href="/posts/{{ post.id }}/">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
@daviddarnes
daviddarnes / gulpfile.js
Last active June 10, 2023 01:17
Import your Ghost posts into a Jekyll project using Gulp
const File = require('vinyl');
const gulp = require("gulp");
const Handlebars = require('handlebars');
const streamArray = require('stream-array');
const ghostContentAPI = require("@tryghost/content-api");
const api = new ghostContentAPI({
url: 'https://demo.ghost.io',
key: '22444f78447824223cefc48062',
version: "v4"
@daviddarnes
daviddarnes / app.js
Created January 9, 2020 09:06
Mini Node server for triggering 11ty builds
const http = require('http');
const process = require('process');
const { exec } = require('child_process');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
console.log('Ghost content updated!');
process.chdir('../eleventy/');
@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>
@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 / 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

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 / .eleventy.js
Last active February 14, 2022 02:10
Compile JavaScript and Sass in Eleventy using UglifyJS and Sass lib
const terser = require("terser");
const sass = require("sass");
module.exports = (eleventyConfig) => {
// Compile Sass
eleventyConfig.addTemplateFormats("scss");
eleventyConfig.addExtension("scss", {
outputFileExtension: "css",
compile: function (contents, inputPath) {
@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")
}
@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")(),
]);