Skip to content

Instantly share code, notes, and snippets.

View DirtyF's full-sized avatar
😷
Home

Frank Taillandier DirtyF

😷
Home
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active November 15, 2024 15:20
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@MichaelCurrin
MichaelCurrin / README.md
Last active August 25, 2024 22:29
Jekyll - how to build a REST API

Jekyll - how to build a REST API

Serve your data as static JSON

How to make a read-only JSON REST API using Jekyll.

This doesn't need any Ruby plugins - you just use some built-in templating features in Jekyll 3 or 4.

You will end up with a single JSON file contains data for all pages on the site, and another JSON file of just posts. Alternatively, you can replace every HTML page and post with a JSON version.

@siakaramalegos
siakaramalegos / webmentions.njk
Created November 22, 2019 21:06
Version of my webmentions nunjucks file used when writing my post about Webmentions and Eleventy
<div class="webmentions content-grid-sibling" id="webmentions">
{% set mentions = webmentions | getWebmentionsForUrl(metadata.url + webmentionUrl) %}
{% set reposts = mentions | webmentionsByType('repost-of') %}
{% set repostsSize = reposts | size %}
{% set likes = mentions | webmentionsByType('like-of') %}
{% set likesSize = likes | size %}
{% set replies = mentions | webmentionsByType('in-reply-to') %}
{% set repliesSize = replies | size %}
@romansorin
romansorin / .storybook
Created November 10, 2019 00:52
Gatsby, TailwindCSS, Storybook configuration
- addons.js
- config.js
- webpack.config.js
/**
* This is an example gulpfile.js for orchestrating a Webpack build alongside the Hugo static site generator.
*
* This example assumes you already have Webpack installed and configured in your project.
*
* To get started, install Gulp and BrowserSync with the following command:
* npm install gulp browser-sync
*
* Then add this file to your project and name it gulpfile.js
*/
@kmelve
kmelve / sanityToMarkdownPosts.js
Created March 16, 2019 16:11
Convert a post type in Sanity.io to markdown files with frontmatter
/* eslint-disable */
const fs = require('fs')
const sanityClient = require('@sanity/client')
const groq = require('groq')
const BlocksToMarkdown = require('@sanity/block-content-to-markdown')
const config = { projectId: '<YourID>', dataset: '<DatasetName>', useCdn: true }
const client = sanityClient(config)
const serializers = {
@drewm
drewm / shoot-sharing-image.js
Last active April 30, 2021 06:24
Dynamic Social Sharing Images
const puppeteer = require('puppeteer');
const imagemin = require('imagemin');
const imageminPngquant = require('imagemin-pngquant');
// Get the URL and the slug segment from it
const url = process.argv[2];
const segments = url.split('/');
const slug = segments[segments.length-2];
(async () => {
@Andy-set-studio
Andy-set-studio / example.md
Created December 15, 2018 14:35
Filter posts by a passed year
title year layout
An example
2018
example.njk
@budparr
budparr / hugo-search-index.json
Created October 16, 2018 14:21
#gohugo search index with "some" stop words removed
{{- $.Scratch.Add "index" slice -}}
{{$index := where .Site.RegularPages ".Section" "not in" (slice "links" "internal") }}
{{- range $index -}}
{{ with .Params.images }}
{{ $.Scratch.Set "image" (index . 0)}}
{{ else }}
{{ $.Scratch.Set "image" "/uploads/logo.jpg"}}
{{ end }}
{{ $image := printf "%s%s" (replace ($.Scratch.Get "image") "/uploads" .Site.Params.image_url) "?fit=crop&h=201&w=358" }}
{{- $content_filtered := replaceRE "(?m)(?i)(?s:\\ba\\b|\\band\\b|\\barchival\\b|\\bagain\\b|\\bin\\b|\\bto\\b|\\bis\\b|\\bno\\b|\\bor\\b|\\bthis\\b|\\bwell\\b|\\byes\\b|\\bthe\\b|\\bthere\\b|\\bthese\\b|\\bthen\\b)" "" (delimit .PlainWords " ") -}}
@thbar
thbar / _readme.md
Last active July 17, 2024 18:54
Using minitest to regression test your Jekyll static site

Using minitest to regression-test your Jekyll static site

I recently had to upgrade my blog, which involved changes such as:

  • Replacing a sitemap plugin
  • Upgrading from jekyll 2.5.3 to 3.8.4
  • Upgrading from jekyll-assets 0.7.8 to 3.0.11
  • (etc)

The upgrading process was not trivial, and some parts (e.g. RSS, sitemap, or twitter cards tags) are not immediately visible, so I decided to add unit tests on the generated content.