From bdbe605cc8966ca45724684763c2353e446c720b Mon Sep 17 00:00:00 2001 From: iJungleboy Date: Wed, 27 Feb 2019 08:05:30 +0100 Subject: [PATCH] last details and docs for 1.1 --- Blade/Blade/JsonLdData.cs | 8 ------- Blade/Razor - Blade.csproj | 2 +- Blade/Types/SchemaOrg/List.cs | 13 +++++++++++ Connect.Razor.Dnn/Blade/HtmlPage.cs | 11 ++++++++- docs/htmlpage.md | 35 +++++++++++++++++++++++++++++ readme.md | 20 ++++++++++++----- 6 files changed, 74 insertions(+), 15 deletions(-) delete mode 100644 Blade/Blade/JsonLdData.cs create mode 100644 Blade/Types/SchemaOrg/List.cs create mode 100644 docs/htmlpage.md diff --git a/Blade/Blade/JsonLdData.cs b/Blade/Blade/JsonLdData.cs deleted file mode 100644 index e2f23fe..0000000 --- a/Blade/Blade/JsonLdData.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections.Generic; - -namespace Connect.Razor.Blade -{ - public class JsonLdNode: Dictionary - { - } -} diff --git a/Blade/Razor - Blade.csproj b/Blade/Razor - Blade.csproj index 6e91a80..90cad5e 100644 --- a/Blade/Razor - Blade.csproj +++ b/Blade/Razor - Blade.csproj @@ -33,7 +33,7 @@ 4 - + diff --git a/Blade/Types/SchemaOrg/List.cs b/Blade/Types/SchemaOrg/List.cs new file mode 100644 index 0000000..3cf9cbb --- /dev/null +++ b/Blade/Types/SchemaOrg/List.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Connect.Razor.Types.SchemaOrg +{ + /// + /// Helper Type to keep code shorter when creating JSON LD data + /// + // ReSharper disable once InheritdocConsiderUsage + // WIP!!! Work in progress + internal class List: Dictionary + { + } +} diff --git a/Connect.Razor.Dnn/Blade/HtmlPage.cs b/Connect.Razor.Dnn/Blade/HtmlPage.cs index 67f1052..cb2cefa 100644 --- a/Connect.Razor.Dnn/Blade/HtmlPage.cs +++ b/Connect.Razor.Dnn/Blade/HtmlPage.cs @@ -3,6 +3,16 @@ namespace Connect.Razor.Blade { + /// + /// Access the surrounding page and read/modify some properties, + /// + add various kinds of headers + /// + /// + /// 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 + /// public static class HtmlPage { public static IHtmlPage GetPage() => new DnnHtmlPage(); @@ -59,7 +69,6 @@ public static string Keywords /// value of this property public static void AddOpenGraph(string property, string content) => GetPage().AddOpenGraph(property, content); - /// /// Add a JSON-LD header according https://developers.google.com/search/docs/guides/intro-structured-data /// diff --git a/docs/htmlpage.md b/docs/htmlpage.md new file mode 100644 index 0000000..b525df7 --- /dev/null +++ b/docs/htmlpage.md @@ -0,0 +1,35 @@ + + +# 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` 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 `` 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 = "...; +``` \ No newline at end of file diff --git a/readme.md b/readme.md index c56dd55..5d123ec 100644 --- a/readme.md +++ b/readme.md @@ -1,9 +1,19 @@ -# 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 `ü` will mess up your count or might even be cut off. This is automatically handled by:_ ```razor @@ -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 `` 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 `` 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