Skip to content

Commit

Permalink
last details and docs for 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
iJungleboy committed Feb 27, 2019
1 parent 3e7e2f9 commit bdbe605
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 15 deletions.
8 changes: 0 additions & 8 deletions Blade/Blade/JsonLdData.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Blade/Razor - Blade.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Blade\JsonLdData.cs" />
<Compile Include="Types\SchemaOrg\List.cs" />
<Compile Include="Blade\Tags\LineBreaks.cs" />
<Compile Include="Blade\Tags\TagReplacer.cs" />
<Compile Include="Blade\Tags\Wrap.cs" />
Expand Down
13 changes: 13 additions & 0 deletions Blade/Types/SchemaOrg/List.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace Connect.Razor.Types.SchemaOrg
{
/// <summary>
/// Helper Type to keep code shorter when creating JSON LD data
/// </summary>
// ReSharper disable once InheritdocConsiderUsage
// WIP!!! Work in progress
internal class List: Dictionary<string, object>
{
}
}
11 changes: 10 additions & 1 deletion Connect.Razor.Dnn/Blade/HtmlPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

namespace Connect.Razor.Blade
{
/// <summary>
/// Access the surrounding page and read/modify some properties,
/// + add various kinds of headers
/// </summary>
/// <remarks>
/// It's important that the commands on this class are the same as in the IHtmlPage,
/// to allow the API to be consistent both when using this shortcut-class as well as
/// when using the GetPage() and then doing the same commands on that.
/// This cannot be enforced with interfaces, as the static class cannot be typed
/// </remarks>
public static class HtmlPage
{
public static IHtmlPage GetPage() => new DnnHtmlPage();
Expand Down Expand Up @@ -59,7 +69,6 @@ public static string Keywords
/// <param name="content">value of this property</param>
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>
Expand Down
35 changes: 35 additions & 0 deletions docs/htmlpage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<img src="assets/razor-blade-logo.png" width="100%">

# Razor Blade HtmlPage API

_return to [overview](https://github.com/DNN-Connect/razor-blade)_

## Properties To Change Title, Description, Keywords

1. `HtmlPage.Description` (get/set) - Read/Write the page description. _v1.1_

1. `HtmlPage.Keywords` (get/set) - Read/Write the page keywords. _v1.1_

1. `HtmlPage.Title` (get/set) - Read/Write the page title. _v1.1_

## Commands to Add Headers

1. `HtmlPage.AddMeta(name, content)` - Adds a meta-tag with this name and content to the header. _v1.1_

1. `AddJsonLd(...)` create a [JSON-LD (linked data) header](https://en.wikipedia.org/wiki/JSON-LD) see also [google guideline](https://developers.google.com/search/docs/guides/intro-structured-data) and [Schema.org](https://schema.org/). _v1.1_
1. `AddToJsonLd(string)` - uses a string, which should already be a valid json
1. `AddToJsonLd(object)` - will JSON-serialize whatever you pass into it. For now, we recommend using `Dictionary<string, object>` to prepare the data you want to add.

1. `AddOpenGraph(property, content)` add an [open-graph tag](http://ogp.me/) to the header for facebook, twitter and co. _v1.1_

1. `HtmlPage.AddToHead(string)` - Add anything to the `<head>` section of the page. The string should usually contain a meta, link or script tag. _v1.1_

## Performance Optimizations

The commands above are available for comfortable use. Internally, each command finds the page object and manipulates it. If you would like to optimize the code a bit, the `GetPage()` command gives you an object with the same features, but will run a few percent faster. So you can also do this:

```razor
var p = HtmlPage.GetPage();
p.Title = "...";
p.Keywords = "...;
```
20 changes: 15 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<img src="docs/assets/razor-blade-logo.png" width="100%">

# Razor Blade v1.0 stable
# Razor Blade v1.1 stable

A library of common functions for Razor, to lighten Razor templates and make work easier. Some examples:

_You need to change the page title and some headers from a razor template:_

```razor
@using Connect.Razor.Blade;
HtmlPage.Title = "Title changed using Razor Blade! original";
HtmlPage.Description = "Learn to use Razor Blade " + HtmlPage.Description;
HtmlPage.Keywords = "Tutorial, Razor, Blade" + HtmlPage.Keywords;
HtmlPage.AddMeta("somename", "somevalue");
```

_You need the first 100 characters followed by an ellipsis (if truncated), but umlauts like `&uuml;` will mess up your count or might even be cut off. This is automatically handled by:_

```razor
Expand Down Expand Up @@ -76,21 +86,21 @@ 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. **HtmlPage** - for v1.1 see [detailed docs todo](docs/htmlpage.md)
1. **HtmlPage** - for v1.1 see [detailed docs](docs/htmlpage.md)
1. `Title` get-set property
1. `Description` get-set property
1. `Keywords` get-set property
1. `AddToHead(tagString)` add any tag string into the page `<head>` section
1. `AddMeta(name, content)` add a meta-tag to the header
1. `AddJsonLd(string|object)` 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)
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)
1. `AddToHead(tagString)` add any tag string into the page `<head>` section
1. `GetPage()` (WIP)


## Work in Progress v1.1 (WIP / in discussion)

1. **Url**
1. SeoFragment(string) - in discussion, would take a string and save-convert it so it can be added to a url for SEO.
1. SeoFragment(string) - in discussion, would take a string and save-convert it so it can be added to a url for SEO.
1. AddParameters(...) - would add more url-parameters, and ensure that it only has one ? etc.

## Ideas to discuss
Expand Down

0 comments on commit bdbe605

Please sign in to comment.