Skip to content

Instantly share code, notes, and snippets.

@deanebarker
deanebarker / PersonalizedContentAreaSerializer.cs
Last active April 2, 2024 15:29
A POC of providing personalization data with content area items in an API response
[ServiceConfiguration(typeof(IPropertyConverterProvider), Lifecycle = ServiceInstanceScope.Singleton)]
public class CustomPropertyConverterProvider : IPropertyConverterProvider
{
public int SortOrder => 200;
public IPropertyConverter Resolve(PropertyData propertyData)
{
if (propertyData is PropertyContentArea)
{
return new PersonalizedContentAreaPropertyConverter();
@deanebarker
deanebarker / Startup.cs
Created March 29, 2024 02:21
An example showing how to shut off Opti UI telemetry
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
public class Startup
{
public void Configure(TelemetryConfiguration telemetryConfiguration)
{
telemetryConfiguration.DisableTelemetry = true;
TelemetryDebugWriter.IsTracingDisabled = true;
}
@deanebarker
deanebarker / ComponentController.cs
Created March 13, 2024 22:03
A POC showing how to create endpoints on an Optimize CMS instance that return fully-contained client-side components
using EPiServer.ServiceLocation;
using Microsoft.AspNetCore.Mvc;
using Optimizely.ContentGraph.Cms.Core.Internal;
namespace DeaneBarker.Optimizely.Cms
{
[Route("component")]
public class ComponentController : Controller
{
private const string KEY_TOKEN = "@key";
@deanebarker
deanebarker / TableOfContents.js
Last active November 21, 2023 16:39
Web Component to embed a dynamic table of contents based on heading tags
/*
<table-of-contents title="Contents" source=".article" selector="h2,h3"></table-of-contents>
* "title" will be placed in a HEADER tag as the first child
* "source" default to the BODY tag
* "selector" defaults to "h2"
OR
/*
<relative-date datetime="1971-09-03" prefix="Posted" suffix="ago"/>
Outputs:
<relative-date>Posted 52 years ago</relative-date>
*?
@deanebarker
deanebarker / Nemmet.cs
Last active April 10, 2023 01:38
An implementation of Emmet in C# using Parlot
Moved to a permanent repo here: https://github.com/deanebarker/Nemmet
@deanebarker
deanebarker / .Using the MultiSourceTemplateProvider
Last active January 10, 2023 15:27
An example of how to retrieve template files for Liquid/Fluid templating in Optimizely CMS
This file is just for naming
@deanebarker
deanebarker / HideVisualViewUIDescriptor.cs
Created November 14, 2022 20:28
Code to hide preview and on-page edit views for content that has no visual component
[UIDescriptorRegistration]
public class HideVisualViewUIDescriptor : UIDescriptor<[Page Type or interface>
{
public HideVisualViewUIDescriptor() : base()
{
DefaultView = CmsViewNames.AllPropertiesView;
EnableStickyView = false;
DisabledViews = new[] { CmsViewNames.PreviewView, CmsViewNames.OnPageEditView };
}
}
@deanebarker
deanebarker / BookRankings.cs
Last active October 13, 2022 22:34
Code to process the NY Times Bestseller List
void Main()
{
// This code depends on the FlatFiles Nuget package: https://github.com/jehugaleahsa/FlatFiles
// Download the dataset from here: https://view.data.post45.org/nytfull
var pathToFile = @"[path to file]";
var mapper = DelimitedTypeMapper.Define<BookRanking>();
mapper.Property(c => c.Year).ColumnName("year");
mapper.Property(c => c.Week).ColumnName("week").InputFormat("yyyy-MM-dd");
@deanebarker
deanebarker / ExtractTextFromWord.cs
Last active August 19, 2022 13:30
A quick and dirty way to extract text from Word document via C#
// This is some rough/stub code for extracting raw text from a Word document
// A modern Word document (.docx) is just a zip file. Extract it.
// Find a file called word/document.xml. That contains the text of the document.
// Paragraphs are in "w:p" tags, and text is in "w:t".
// Iterate the "p" tags, then concatenate all the "t" tags inside them
void Main()
{
var doc = XDocument.Parse(File.ReadAllText(" [path to word/document.xml] "));
XNamespace nsW = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";