Skip to content

QuatroCode/Simplr.OpenGraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simplr.OpenGraph

OpenGraph tags generator for .NET. Built according to OpenGraph spec found here

NuGet package

You can find NuGet package here or install it via package manager console:

Install-Package Simplr.OpenGraph

Usage

Helper class that generates tags for OpenGraph has two main methods:

OGHelper.GetMetadata<T>(IOGType<T> metadata)
OGHelper.GetMetadata<T>(OGMetadata metadata, IOGType<T> contentMetadata)

Both return string with generated meta tags.

Basic Example

  1. Create page defining metadata object:

    var metadata = new OGMetadata() {
        Title = "My cool page title",
        Url = new Uri("https://mypage.buzz"),
        Description = "My page that has a cool title and even cooler site name!",
        SiteName = "Cool page"
    };

    Objects can be filled fully or partially.

  2. Call helper method to generate meta tags

    string tags = OGHelper.GetMetadata(metadata);
  3. Add meta tags to your HTML -> HEAD website

  4. You can test if it works in Facebook's debug tool here

Specific page type example

Some of our pages have more specific data, e.g. they represent Music Song, Music Album, Profile, Book, etc.

If you want to add that specific metadata in addition to basic one, create a global type object from provided models or create your own (section bellow)

var metadata = new OGMetadata() {
    Title = "My cool page title",
    Url = new Uri("https://mypage.buzz"),
    Description = "My page that has a cool title and even cooler site name!",
    SiteName = "Cool page"
};

var customMetadata = new OGProfile(){
    FirstName = "John",
    LastName = "Smith",
    Username = "johnysmith"
}

string tags = OGHelper.GetMetadata(metadata, customMetadata);

Custom type example

If your page data does not fall into any of global types, you can create custom ones.

To do that, simply create your type and inherit a global type or implement IOGType interface and define your own properties.

Custom type example

class MyPageObj : IOGType {
    public string Type {
        get { return "MyType"; }
    }

    public string MyProperty {
        get { return "MyPropertyValue"; }
    }
}

And use it like in "Specific page type example".

About

OpenGraph tags generator for .NET

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages