Skip to content

Instantly share code, notes, and snippets.

View nternetinspired's full-sized avatar

Seth Warburton nternetinspired

View GitHub Profile
const HEADERS = [
"content-security-policy-report-only",
"content-security-policy",
"feature-policy",
"nel",
"report-to",
"accept-ch",
"referrer-policy",
"strict-transport-security",
"link"
@stenvdb
stenvdb / img-macros.twig
Last active July 4, 2022 10:49
Macro collection for Imager in Craft CMS
{#
# USAGE:
# (transform can either be an object, or an array of objects, aka srcset)
#
# {{ macro.regular(entry.image.one(), { width: 50, height: 50 }, 'class="block"') }}
# ➡️ <img src="..." width="50" height="50" alt="..." class="block" />
#
# {{ macro.url(entry.image.one(), { width: 50, height: 50 }) }}
# ➡️ /uploads_c/../{...}.jpg
#
@croxton
croxton / google_cloud_storage_craft_3.md
Last active September 24, 2022 07:31
How to provision Google Cloud Storage buckets for Craft CMS 3.x

Create the bucket

  1. Open the console https://console.cloud.google.com
  2. If you haven't already, setup your Cloud billing account
  3. From the drop down at the top of the screen, create new project for your client, e.g. my-client
  4. Make a note of the Project number on the project Home screen (Craft refers to this as the Project ID)
  5. In the sidebar go to APIs & Services > Credentials, click the + Create credentials button and choose the Service Account type
  • Set account name to craft-cms or similar
  • Set role to Owner
  • Save
  1. Click on the newly created service account email to edit it, then click the Keys tab and click Add key > Create new key and select the JSON format
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active May 3, 2024 12:55
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@JonathanDoughty
JonathanDoughty / img-srcset.html
Last active September 5, 2019 17:23
Hugo partial for generating <picture> with responsive image
{{/* Adapted from https://gist.github.com/randallmlough/98c9c949b25f2a41259029e03dd037f3 */}}
{{- $image := replaceRE "^https?://[^/]+/(.*)" "$1" ($.Scratch.Get "image") -}}
{{- $media := (.Site.GetPage "page" "media").Resources -}}
{{- $original := index ($media.Match (printf "%s" $image)) 0 -}}
{{- $width := $original.Width -}}
{{- $intWidth := int $width -}}
{{- $sizes := $.Param "sizes" -}}
{{- $options := $.Param "options" -}}
{{- $usePicture := false -}}{{/* true: Use picture element with source definitions */}}
{{- $multipleSizes := true -}}{{/* true: Provide multiple img sizes attribute */}}
{# @var craft \craft\web\twig\variables\CraftVariable #}
{# @var entry \craft\elements\Entry #}
{% set image = opt.data %}
{% set options = opt.imager %}
{% set defaults = {
sizes: [
{ width: 1440 },
{ width: 900 },
@randallmlough
randallmlough / hugo-img-partial.html
Last active June 21, 2021 01:36
Complete hugo img partial using page resources
{{ $image := .Params.image}}
{{ $media := (.Site.GetPage "page" "media").Resources }}
{{ $original := index ($media.Match (printf "%s" $image)) 0 }}
{{ $width := $original.Width}}
{{ $intWidth := int $width }}
{{ $sizes := .Params.sizes}}
{{ $options := .Params.options}}
{{ if le (len $sizes) 1 }}
{{ $oneSize := index $sizes 0}}
@randallmlough
randallmlough / hugo-img-srcset.html
Last active May 8, 2021 12:31
A hugo img srcset partial that auto resizes images
<style>
img {
max-width: 100%;
}
</style>
<h1>Creating a srcset loop based on Resources</h1>
<!--
NOTE: This requires Hugo 0.32
@pgilad
pgilad / Instructions.md
Last active March 27, 2024 12:59
Generate SSL Certificate for use with Webpack Dev Server (OSX)

Generate private key

$ openssl genrsa -out private.key 4096

Generate a Certificate Signing Request

openssl req -new -sha256 \
@sjelfull
sjelfull / _lazyFocusImager.twig
Created April 6, 2017 12:51 — forked from hendrikeng/_lazyFocusImager.twig
Twig/Craft macro for lazy responsive images/bgimages with Imager and Focuspoint
{#
// lazyLoaded Image/bgImages, optimized with Imager and Focuspoint
---------------------------------------------------------------------------
https://nystudio107.com/blog/creating-optimized-images-in-craft-cms
https://github.com/aelvan/Imager-Craft
https://github.com/smcyr/Craft-FocusPoint
for the bgImage intrinsic ratio classname creation check:
https://github.com/inuitcss/inuitcss/blob/develop/objects/_objects.ratio.scss