Skip to content

Instantly share code, notes, and snippets.

@waako
waako / gulpfile.js
Created June 15, 2017 03:46
Gulp workflow for optimising and compressing static site html and assets.
/* Load plugins */
var gulp = require('gulp'),
watch = require('gulp-watch'),
notify = require('gulp-notify'),
uncss = require('gulp-uncss'),
zopfli = require("gulp-zopfli"),
connect = require('gulp-connect'),
htmlmin = require('gulp-htmlmin'),
inlinesource = require('gulp-inline-source'),
imagemin = require('gulp-imagemin'),
@waako
waako / gulpfile.js
Created February 20, 2017 18:42
Build Script for SideCarMT.com
var gulp = require('gulp');
var fs = require('fs');
var del = require('del');
var htmlreplace = require('gulp-html-replace');
var uglify = require('gulp-uglify');
var minifyHTML = require('gulp-minify-html');
var minifyCSS = require('gulp-minify-css');
var rename = require("gulp-rename");
var bowerSrc = require('gulp-bower-src');
var gulpFilter = require('gulp-filter');
@waako
waako / gulpfile.js
Created February 20, 2017 18:07
Gulpfile.js v4
var gulp = require('gulp'),
fs = require('fs'),
path = require('path'),
naturalSort = require('gulp-natural-sort'),
browserSync = require('browser-sync'),
cp = require('child_process'),
rsync = require('gulp-rsync'),
rev = require('gulp-rev'),
del = require('del'),
collect = require('gulp-rev-collector'),
@waako
waako / .csscomb.json
Created January 19, 2017 15:51
Gulp workflow for Drupal 8 theme. Includes csscomb for Drupal CSS Code Standards and Sass Lint
{
"exclude": [
".git/**",
"misc/**",
"modules/**",
"profiles/**",
"themes/**",
"node_modules/**",
"bower_components/**"
],
@waako
waako / configuration.yaml
Created November 19, 2016 21:05
Home Assistant config for Emon stuff
homeassistant:
# Name of the location where Home Assistant is running
name: emonPi Demo
# C for Celcius, F for Fahrenheit
temperature_unit: C
# Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
time_zone: Europe/London
# Location required to calculate the time the sun rises and sets
latitude: 56.14286
longitude: -4.15401
@waako
waako / themename.theme.php
Last active October 6, 2016 10:59
Drupal 8 Block and Menu template suggestions
<?php
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function THEMENAME_theme_suggestions_block_alter(array &$suggestions, array $variables) {
$block_id = $variables['elements']['#id'];
// See if block ID contains the word mobile.
$is_mobile_block = strpos($block_id, 'mobile');
$block = \Drupal\block\Entity\Block::load($block_id);
@waako
waako / themename.theme.php
Last active August 31, 2016 20:30
Get value of field from a node inside region
<?php
/**
* Implements hook_preprocess_HOOK() for region templates.
*/
function themename_preprocess_region__region_name(&$variables) {
// Check if current page is a node.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
// Check if node has the field site_section.
if ($node->hasField('field_site_section')) {
@waako
waako / .htaccess
Created July 14, 2016 15:16
redirect all traffic to https, except one page, and ensure that page is served on http
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/who-we-are/careers$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Ensure that Careers page is not forced over HTTPS
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/who-we-are/careers$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@waako
waako / themename.theme.php
Created June 19, 2016 16:48
Drupal 8: get a block's parent node title and absolute url and pass it as variable
<?php
/**
* Implements hook_preprocess_HOOK() for block.html.twig.
*/
function themename_preprocess_block(&$variables) {
// Get Title of Block's parent Node.
$request = \Drupal::request();
$route_match = \Drupal::routeMatch();
@waako
waako / theme.php
Created June 3, 2016 12:11
Drupal Paragraphs get image url with image style
<?php
use Drupal\image\Entity\ImageStyle;
/**
* Implements hook_preprocess_HOOK() for paragraph--para-slide.html.twig.
*/
function themename_preprocess_paragraph__para_slide(&$variables) {
$paragraph = $variables['paragraph'];
if (!$paragraph->field_image->isEmpty()) {