Skip to content

Instantly share code, notes, and snippets.

@kgiszewski
Created December 31, 2015 18:42
Show Gist options
  • Select an option

  • Save kgiszewski/41f7fdeeadd5a9e68054 to your computer and use it in GitHub Desktop.

Select an option

Save kgiszewski/41f7fdeeadd5a9e68054 to your computer and use it in GitHub Desktop.
using System;
using Umbraco.Core.Models;
using Umbraco.Web;
namespace KGLLC.Umbraco.Helpers
{
public static class PublishedContentExtensions
{
public static string ToPublishedDateLong(this IPublishedContent content)
{
return content.ToPublishedDate().ToString("D");
}
public static string ToPublishedDateShort(this IPublishedContent content)
{
return content.ToPublishedDate().ToString("dd MMM");
}
public static DateTime ToPublishedDate(this IPublishedContent content)
{
var publishedDate = content.GetPropertyValue<DateTime>("publishedDate");
if (publishedDate == DateTime.MinValue)
{
return content.CreateDate;
}
return content.GetPropertyValue<DateTime>("publishedDate");
}
public static string ToMetaDescription(this IPublishedContent content)
{
if (content.DocumentTypeAlias == "BlogPostPage")
{
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
return umbHelper.StripHtml(content.GetPropertyValue<string>("teaseDescription")).ToString().Replace("\n", " ");
}
return string.Format("Kevin.Giszewski.com - {0}", content.Name);
}
public static string ToTitleTag(this IPublishedContent content)
{
return string.Format("Kevin.Giszewski.com - {0}", content.Name);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment