Skip to content

Instantly share code, notes, and snippets.

View tristolliday's full-sized avatar

Tris Tolliday tristolliday

  • Bournemouth
View GitHub Profile
@tristolliday
tristolliday / optimisedImage.cshtml
Last active November 8, 2021 17:37
Umbraco 8 Optimised image
@*
Image Processor's WebP plugin must be installed via nuget first.
https://www.nuget.org/packages/ImageProcessor.Plugins.WebP/
*@
<picture>
<source srcset="@Model.Image.GetCropUrl(300, 300, furtherOptions: "&format=webp&quality=80")" type="image/webp">
<img src="@Model.Image.GetCropUrl(300, 300)" width="300" height="300" loading="lazy" alt="@Model.Image.Name" />
</picture>
@tristolliday
tristolliday / Umbraco9Images.cshtml
Last active November 8, 2021 17:38
Responsive, high performance images in umbraco 9
@* /Views/Partials/ResponsiveImage.cshtml *@
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@using Umbraco.Cms.Core.Media
@using Umbraco.Cms.Core.Models.PublishedContent
@using Umbraco.Cms.Core.Routing
@{
var publishedContent = @ViewData["publishedContent"] as IPublishedContent ?? null;
var lazyLoading = @ViewData["lazyLoading"] ?? false;
$(document).ready(function () {
var lazyloadBgImages = document.querySelectorAll(".lazybg");
if ("IntersectionObserver" in window) {
var bgImageObserver = new IntersectionObserver(function (entries, observer) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
var image = entry.target;
image.style["background-image"] = "url('" + image.dataset.bgsrc + "')";
image.classList.remove("lazybg");
bgImageObserver.unobserve(image);
@tristolliday
tristolliday / QandA.cshtml
Created December 28, 2019 16:35
Newtonsoft Json.NET for Structured Data - Google Rich Snippets and Enhanced SEO
@using Newtonsoft.Json.Linq
@{
var questions = Model.Value<IEnumerable<IPublishedElement>>("questions");
}
<script type="application/ld+json">
@{
var structuredData =
new JObject(
new JProperty("@context", "https://schema.org"),
@tristolliday
tristolliday / package.json
Created December 17, 2019 09:33
A Package to do with our Firebase Function index.js
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
@tristolliday
tristolliday / index.js
Created December 17, 2019 09:31
Simple Firebase Function for Actions on Google Fulfillment on Dialogflow
'use strict';
// So that you have access to the dialogflow and conversation object
const { dialogflow } = require('actions-on-google');
// So you have access to the request response stuff >> functions.https.onRequest(app)
const functions = require('firebase-functions');
// Create an instance of dialogflow for your app
const app = dialogflow({debug: true});
@tristolliday
tristolliday / gulp3-to-gulp4.js
Last active October 31, 2019 11:43
Migrate a gulp 3 task to gulp 4
// Gulp 3 Task
var gulp = require("gulp");
var rename = require('gulp-rename');
var coreScripts = []; // your main scripts
gulp.task('scripts', function () {
return gulp.src(coreScripts)
.pipe(concat('global.js'))
.pipe(gulp.dest('blah/html/js'))
.pipe(rename('global.min.js'))
.pipe(gulp.dest('blah/html/js'))
@tristolliday
tristolliday / msbuildTask.js
Created October 31, 2019 10:40
an example of using msbuild in a gulp 4 task
// ReadMe in msbuild repo: https://github.com/jhaker/nodejs-msbuild
var gulp = require("gulp");
var _msbuild = require('msbuild');
var config = require("./gulp-config.json"); // use this to store all your .csproj/.sln related project details
const msbuildTask = function (cb) {
var msbuild = new _msbuild(cb);
msbuild.sourcePath = config.project;
msbuild.config('version', '16.0');
msbuild.configuration = config.buildConfiguration;
@tristolliday
tristolliday / FAQ.cshtml
Created May 28, 2019 11:20
Newtonsoft-Linq Structured Data(Json-LD) for FAQ Pages
<script type="application/ld+json">
@{
JObject structuredData =
new JObject(
new JProperty("@context", "https://schema.org"),
new JProperty("@type", "FAQPage"),
new JProperty("mainEntity",
new JArray(
from item in questions
select new JObject(
@tristolliday
tristolliday / gulpfile.js
Created April 11, 2019 15:01
Use gulp to create individual CSS files for each SCSS file
const gulp = require('gulp');
// SCSS related requires
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const sassCompiler = require('./gulp-tasks/scss-compiler');
const changed = require('gulp-changed');
const defaulSCSSTasks = gulp.parallel(
sassCompiler(gulp, sass, changed, autoprefixer, 'scss/*.scss'),