Skip to content

Instantly share code, notes, and snippets.

@mattbrailsford
mattbrailsford / ContentExtensions.cs
Last active March 23, 2021 16:57
Converts an IContent element to IPublishedContent in Umbraco v8
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Strings;
using Umbraco.Web.Composing;
public class ProductComponent : IComponent
{
private readonly IExamineManager _examineManager;
private readonly ProductIndexCreator _productIndexCreator;
public ProductComponent (IExamineManager examineManager, ProductIndexCreator productIndexCreator)
{
_examineManager = examineManager;
_productIndexCreator = productIndexCreator;
}
@mattbrailsford
mattbrailsford / aspect-ratio.js
Last active January 18, 2019 18:55
Tailwind CSS Aspect Ratio plugin
const _ = require('lodash');
module.exports = function({ ratios, options, variants }) {
return function({ addUtilities, e }) {
const opts = Object.assign({}, {
orientedRatios: false,
invertedRatios: false
}, options);
@dawoe
dawoe / DefaultController.cs
Created November 7, 2017 08:20
Donut Cache examples from Umbraco UK Festival talk "The need for speed"
public class DefaultController : RenderMvcController
{
[UmbracoDonutOutputCache(CacheProfile = "LongPageCache",
Options = OutputCacheOptions.NoCacheLookupForPosts &
OutputCacheOptions.ReplaceDonutsInChildActions, Order = 100)]
public override ActionResult Index(RenderModel model)
{
return base.Index(model);
}
}
@Heydon
Heydon / observe.js
Last active December 18, 2020 11:52
// Elements with `data-observe` toggle `data-visible`
// between `true` and `false`
if ('IntersectionObserver' in window) {
const callback = (entries, observer) => {
entries.forEach(entry => {
entry.target.setAttribute('data-visible', entry.isIntersecting)
})
}
@leekelleher
leekelleher / MarkdownPropertyDescriptions.cs
Last active February 5, 2020 06:52
Umbraco - Converts a property's description using markdown
using Umbraco.Core;
using Umbraco.Web.Editors;
namespace Our.Umbraco
{
public class MyBootstrapper : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
EditorModelEventManager.SendingContentModel += (sender, e) =>
@abjerner
abjerner / ExaminePublishedContent.cs
Created October 11, 2016 21:17
Convert SearchResult into IPublishedContent
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Examine;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
namespace Skybrud.ExamineDevStuff {
@jbreuer
jbreuer / ContentExtensions.cs
Created May 18, 2016 14:59
An extension method to convert an IContent to an IPublishedContent.
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ContentExtensions.cs" company="Colours B.V.">
// © Colours B.V. 2015
// </copyright>
// <summary>
// The content extensions.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Project.Web.Core.Extensions