Skip to content

Instantly share code, notes, and snippets.


Deane Barker deanebarker

View GitHub Profile
deanebarker / Startup.cs
Created May 3, 2022
The simplest webhook system for Optimizely Content Cloud
View Startup.cs
public void Configuration(IAppBuilder app)
// This is the URL template to call
// The placeholders are optional -- they will be replaced with data specific to the content that is published
var webhookUrl = "{id}&type={type}&version={version}";
// Here is an example URL that would be called for this example:
var events = ServiceLocator.Current.GetInstance<IContentEvents>();
deanebarker / ExtractFragmentMiddleware.cs
Last active Apr 1, 2022
Replace the body of a response with HTML extracted from that same body
View ExtractFragmentMiddleware.cs
using AngleSharp.Html.Parser;
using Microsoft.AspNetCore.Http;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace DeaneBarker.Optimizely.Middleware
public class ExtractFragmentMiddleware
deanebarker / Editor.js
Last active Feb 16, 2022
The world's simplest code editor for Optimizely Content Cloud
View Editor.js
This is specifically designed to do as little as possible and have no dependencies.
1. It's styled sort of like a code editor (?)
2. Spellchecking is turned off (no red squiggly lines -- I hate those!)
3. The TAB key will insert 2 spaces, instead of moving focus
4. When you press enter, it will add leading spaces to match the leading spaces on the prior line
...and that's all it does.
deanebarker / QueryValue.cs
Last active Jan 3, 2022
An example of a custom FluidValue to enable fluent(-ish) query specification
View QueryValue.cs
// Example:
// {% assign people = query.sortby['lastname'].direction['desc'].limit[2] %}
public class QueryValue : FluidValue
// This is only needed for testing
// In production, the query would be of some external resource
private IEnumerable<Person> _items;
// This is an anonymous method that handles the index
deanebarker / XmlValue.cs
Last active Oct 11, 2021
An custom value type for Fluid that allows for easy access of XML element content
View XmlValue.cs
public class XmlValue : FluidValue
// The accessor to retrieve the text content of an element
public static string TextAccessor { get; set; } = "_text";
// The accessor to retrieve a dictionary of attributes of an element
public static string AttributesAccessor { get; set; } = "_attrs";
// The accessor to retrieve an array of the children of an element
public static string ChildrenAccessor { get; set; } = "_children";
deanebarker / FluidFakeFileProvider.cs
Last active Oct 9, 2021
The minimum (I think) you need to do to mock the FileProvider for the Fluid templating engine
View FluidFakeFileProvider.cs
namespace DeaneBarker
public class FakeFileProvider : IFileProvider
// I don't think Fluid ever calls these (fingers crossed)
public IDirectoryContents GetDirectoryContents(string subpath) { throw new NotImplementedException(); }
public IChangeToken Watch(string filter) { throw new NotImplementedException(); }
public IFileInfo GetFileInfo(string path)
deanebarker / FluidParserExtensions.cs
Last active Oct 9, 2021
Allows retrieval of the initial Fluid template using the declared IFileProvider
View FluidParserExtensions.cs
// var parser = new FluidParser();
// parser.ParseFromFile("deane");
namespace DeaneBarker.Fluid
public static class FluidParserExtensions
public static IFluidTemplate ParseFromFile(this FluidParser parser, string path)
if(TemplateOptions.Default.FileProvider == null)
deanebarker / Managing Non-Web Content in Episerver
Last active Aug 7, 2020
A demo of using Episerver to manage "pure" (non-web) content.
View Managing Non-Web Content in Episerver
This file exists just to name the gist...
deanebarker / RenderScriban.cs
Last active Jun 30, 2019
A Scriban module for Wyam
View RenderScriban.cs
using Scriban;
using Scriban.Parsing;
using Scriban.Runtime;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wyam.Common.Configuration;
deanebarker / XmlNode.cs
Last active Feb 12, 2018
XmlNode Drop to output an XML document in DotLiquid
View XmlNode.cs
public class XmlNode : Drop
private const string attributeMethodName = "attr";
private const string xpathQueryMethodName = "xpath";
private const string listQueryMethodName = "list";
private const char shorthandDelimiter = '-';
private XmlElement doc;
public XmlNode(XmlDocument xml)