Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Post danielpost

View GitHub Profile
@danielpost
danielpost / .eleventy.config.js
Created Aug 11, 2020
Eleventy: Purge CSS for each html file
View .eleventy.config.js
const { PurgeCSS } = require('purgecss');
/**
* Remove any CSS not used on the page and inline the remaining CSS in the
* <head>.
*
* @see {@link https://github.com/FullHuman/purgecss}
*/
eleventyConfig.addTransform('purge-and-inline-css', async (content, outputPath) => {
if (process.env.ELEVENTY_ENV !== 'production' || !outputPath.endsWith('.html')) {
@danielpost
danielpost / gist:a7232c18ee541017184a7d23e20ede01
Created Jun 15, 2020
Installing Xdebug on RunCloud server
View gist:a7232c18ee541017184a7d23e20ede01
apt-get install autoconf libpcre3-dev
MODULE_NAME="xdebug"
MODULE_VERSION="2.9.6"
cd ~
wget https://xdebug.org/files/xdebug-2.9.6.tgz
@danielpost
danielpost / spinner.js
Last active May 29, 2020
WordPress SVG spinner. No more spinner.gif!
View spinner.js
/**
* WordPress dependencies
*/
import { SVG, Circle } from '@wordpress/primitives';
const spinner = (
<SVG fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36">
<Circle cx="18" cy="18" r="18" fill="#a2a2a2" />
<Circle cx="18" cy="8" r="4" fill="#f1f1f1">
<animateTransform
@danielpost
danielpost / class-importer.php
Last active May 28, 2020
WordPress API Importer
View class-importer.php
<?php
/**
* This class is an example of how to reliably fetch items from an external API
* using background processing. Make sure Action Scheduler is installed before
* instantiating this class.
*
* @link https://actionscheduler.org/
*/
class Importer {
const API_URL = 'https://api.openbrewerydb.org/breweries';
@danielpost
danielpost / blocks.js
Created Apr 8, 2020
WordPress Block Editor: Enable custom block only for certain post type(s)
View blocks.js
if (namespace.postType === 'post-type-slug') {
registerBlockType();
}
@danielpost
danielpost / contact-form-7.php
Last active May 21, 2019
WordPress Form Plugins: Get list of all available forms
View contact-form-7.php
<?php
$forms = get_posts(['post_type' => 'wpcf7_contact_form', 'posts_per_page' => -1]);
if (empty($forms)) {
return [];
}
return array_combine(wp_list_pluck($forms, 'ID'), wp_list_pluck($forms, 'post_title'));
@danielpost
danielpost / footnotesHighlight.scss
Last active Jan 10, 2019
Highlight focused footnotes
View footnotesHighlight.scss
@keyframes highlight {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
.footnotes li,
@danielpost
danielpost / accessibleFootnotes.js
Created Jan 10, 2019
Make Hugo's footnotes accessible to screen readers
View accessibleFootnotes.js
/**
* Make Hugo's footnotes accessible.
*/
/**
* Add a title to the footnotes wrapper.
*
* @param {Element} footnotes - Footnotes wrapper.
* @param {String} title - Text for the title element.
* @param {String} id - ID for the title element.
@danielpost
danielpost / AA_WHAT_IT_DOES.md
Last active Oct 30, 2018
Simplify ACF fields
View AA_WHAT_IT_DOES.md

Turns this:

[
    'subtitle',
    'video' => [
        'type' => 'oembed',
    ],
    'quote',
    'quote_author',
@danielpost
danielpost / Core.php
Last active Oct 22, 2018
WordPress theme setup
View Core.php
<?php
namespace Bahama;
class Core {
public function setup() {
add_action('after_setup_theme', [$this, 'i18n']);
add_action('after_setup_theme', [$this, 'theme_setup']);
add_action('wp_enqueue_scripts', [$this, 'scripts']);
add_action('wp_enqueue_scripts', [$this, 'styles']);
You can’t perform that action at this time.