Skip to content

Commit

Permalink
added featuers for jsonld
Browse files Browse the repository at this point in the history
  • Loading branch information
iJungleboy committed Feb 26, 2019
1 parent 3eb1ce8 commit 3e7e2f9
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 23 deletions.
8 changes: 8 additions & 0 deletions Blade/Blade/JsonLdData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

namespace Connect.Razor.Blade
{
public class JsonLdNode: Dictionary<string, object>
{
}
}
15 changes: 13 additions & 2 deletions Blade/Interfaces/IPage.cs → Blade/Interfaces/IHtmlPage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Connect.Razor.Interfaces
{
public interface IPage
public interface IHtmlPage
{

/// <summary>
Expand All @@ -27,7 +27,7 @@ public interface IPage
/// Will simply not do anything if an error occurs, like if the page object doesn't exist
/// </summary>
/// <param name="tag"></param>
void AddHeader(string tag);
void AddToHead(string tag);

/// <summary>
/// Add a standard meta header tag.
Expand All @@ -45,6 +45,17 @@ public interface IPage
void AddOpenGraph(string property, string content);


/// <summary>
/// Add a JSON-LD header according https://developers.google.com/search/docs/guides/intro-structured-data
/// </summary>
/// <param name="jsonString">A prepared JSON string</param>
void AddJsonLd(string jsonString);

/// <summary>
/// Add a JSON-LD header according https://developers.google.com/search/docs/guides/intro-structured-data
/// </summary>
/// <param name="jsonObject">A object which will be converted to JSON. We recommend using dictionaries to build the object.</param>
void AddJsonLd(object jsonObject);

}
}
8 changes: 2 additions & 6 deletions Blade/Razor - Blade.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Blade\JsonLdData.cs" />
<Compile Include="Blade\Tags\LineBreaks.cs" />
<Compile Include="Blade\Tags\TagReplacer.cs" />
<Compile Include="Blade\Tags\Wrap.cs" />
<Compile Include="Blade\Text\Zip.cs" />
<Compile Include="Blade\Text\Crop.cs" />
<Compile Include="Interfaces\IPage.cs" />
<Compile Include="Interfaces\IHtmlPage.cs" />
<Compile Include="Internals\Defaults.cs" />
<Compile Include="Blade\Dic\SafeGet.cs" />
<Compile Include="Blade\Dic\Dynamic.cs" />
Expand All @@ -49,10 +50,5 @@
<Compile Include="Internals\Truncator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="DotNetNuke">
<HintPath>..\..\2sxc-dnn742\Website\bin\DotNetNuke.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Connect.Razor.Blade
{
public static class Head
public static class HtmlPage
{
public static IPage GetPage() => new DnnPage();
public static IHtmlPage GetPage() => new DnnHtmlPage();

/// <summary>
/// The current page title
Expand Down Expand Up @@ -42,7 +42,7 @@ public static string Keywords
/// Will simply not do anything if an error occurs, like if the page object doesn't exist
/// </summary>
/// <param name="tag"></param>
public static void AddHeader(string tag) => GetPage().AddHeader(tag);
public static void AddToHead(string tag) => GetPage().AddToHead(tag);

/// <summary>
/// Add a standard meta header tag.
Expand All @@ -60,6 +60,17 @@ public static string Keywords
public static void AddOpenGraph(string property, string content) => GetPage().AddOpenGraph(property, content);


/// <summary>
/// Add a JSON-LD header according https://developers.google.com/search/docs/guides/intro-structured-data
/// </summary>
/// <param name="jsonString">A prepared JSON string</param>
public static void AddJsonLd(string jsonString) => GetPage().AddJsonLd(jsonString);

/// <summary>
/// Add a JSON-LD header according https://developers.google.com/search/docs/guides/intro-structured-data
/// </summary>
/// <param name="jsonObject">A object which will be converted to JSON. We recommend using dictionaries to build the object.</param>
public static void AddJsonLd(object jsonObject) => GetPage().AddJsonLd(jsonObject);

}
}
5 changes: 3 additions & 2 deletions Connect.Razor.Dnn/Connect.Razor.Dnn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
</ItemGroup>
<ItemGroup>
<Compile Include="Blade\Head.cs" />
<Compile Include="Blade\HtmlPage.cs" />
<Compile Include="Dnn\DnnPage_BasicProps.cs" />
<Compile Include="Dnn\DnnPage.cs" />
<Compile Include="Dnn\DnnHtmlPage.cs" />
<Compile Include="Dnn\DnnPage_Headers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Connect.Razor.Dnn
{
public partial class DnnPage : IPage
public partial class DnnHtmlPage : IHtmlPage
{
public DnnPage()
public DnnHtmlPage()
{
// load the page from the context
// will be null if not available
Expand Down
2 changes: 1 addition & 1 deletion Connect.Razor.Dnn/Dnn/DnnPage_BasicProps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Connect.Razor.Dnn
{
public partial class DnnPage
public partial class DnnHtmlPage
{
public string Description
{
Expand Down
16 changes: 11 additions & 5 deletions Connect.Razor.Dnn/Dnn/DnnPage_Headers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Connect.Razor.Dnn
{
public partial class DnnPage
public partial class DnnHtmlPage
{
public void AddHeader(string tag)
public void AddToHead(string tag)
{
try
{
Expand All @@ -17,13 +17,19 @@ public void AddHeader(string tag)
}

public void AddMeta(string name, string content)
=> AddHeader($"<meta name=\'{name}\' content=\'{Attribute(content)}\' /> ");
=> AddToHead($"<meta name=\'{name}\' content=\'{Attribute(content)}\' /> ");

public void AddOpenGraph(string property, string content)
=> AddHeader($"<meta property=\'{property}\' content=\'{Attribute(content)}\' /> ");
=> AddToHead($"<meta property=\'{property}\' content=\'{Attribute(content)}\' /> ");

public void AddJsonLd(string jsonString)
=> AddHeader($"<script type=\"application/ld+json\">{jsonString}</script>");
=> AddToHead($"<script type=\"application/ld+json\">{jsonString}</script>");

public void AddJsonLd(object jsonObject)
{
var str = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(jsonObject);
AddJsonLd(str);
}

private void EnsureFieldVisibleAndSetValueAgain(string id, string value)
{
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ This is a short summary of the most used variations of the helpers. Further deta
1. `Text.Has(value)`
1. `Text.First(value, value[, moreValues, ...])`
1. `Text.Zip(value)`
1. **Head** - for v1.1 see [detailed docs todo](docs/Head.md)
1. **HtmlPage** - for v1.1 see [detailed docs todo](docs/htmlpage.md)
1. `Title` get-set property
1. `Description` get-set property
1. `Keywords` get-set property
1. `Add(tagString)` add any tag string into the page header
1. `AddToHead(tagString)` add any tag string into the page `<head>` section
1. `AddMeta(name, content)` add a meta-tag to the header
1. `AddOpenGraph(property, content)` add an [open-graph tag](http://ogp.me/) to the header for facebook, twitter and co.
1. `AddJsonLd(string)` create a [Json-LD header](https://en.wikipedia.org/wiki/JSON-LD) see also [google guideline](https://developers.google.com/search/docs/guides/intro-structured-data)
Expand Down

0 comments on commit 3e7e2f9

Please sign in to comment.