-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Twitter Metadata field support (#234)
* 🚧 additional opengraph/twitter fields * addresses #191 by adding support for Twitter-specific metadata and OpenGraph Url * added Facebook app_Id and separated twitter fields into their own group * reconsolidated all social media fields under "Social Media"
- Loading branch information
Showing
20 changed files
with
299 additions
and
12 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditEditors/SeoDropdownEditEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.Converters.EditorConverters; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.Converters; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Models.Converters; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors | ||
{ | ||
public class SeoDropdownEditEditor : ISeoFieldEditEditor | ||
{ | ||
public string View => "/App_Plugins/SeoToolkit/MetaFields/Interface/SeoFieldEditors/PropertyEditor/dropdownList.html"; | ||
public Dictionary<string, object> Config { get; } | ||
public IEditorValueConverter ValueConverter { get; } | ||
|
||
public SeoDropdownEditEditor(string[] items) | ||
{ | ||
ValueConverter = new TextValueConverter(); | ||
Config = new Dictionary<string, object> | ||
{ | ||
{"items", items} | ||
}; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditors/DropdownFieldPropertyEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.Converters.EditorConverters; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditors | ||
{ | ||
public class DropdownFieldPropertyEditor : SeoFieldPropertyEditor, ISeoFieldEditorProcessor | ||
{ | ||
|
||
public DropdownFieldPropertyEditor(string[] items) : base("/App_Plugins/SeoToolkit/MetaFields/Interface/SeoFieldEditors/PropertyEditor/dropdownList.html", new TextValueConverter()) | ||
{ | ||
IsPreValue = true; | ||
Config.Add("items", items); | ||
} | ||
|
||
public object HandleValue(object value) | ||
{ | ||
return value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/FacebookIdField.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Microsoft.AspNetCore.Html; | ||
using Umbraco.Cms.Core.Composing; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Constants; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField; | ||
using Umbraco.Extensions; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Models.SeoField; | ||
|
||
[Weight(701)] | ||
public class FacebookIdField : SeoField<string> | ||
{ | ||
public override string Title => "App Id"; | ||
public override string Alias => SeoFieldAliasConstants.FacebookId; | ||
public override string Description => "Facebook app_id for the content"; | ||
public override string GroupAlias => SeoFieldGroupConstants.SocialMediaGroup; | ||
public override ISeoFieldEditor Editor { get; } | ||
public override ISeoFieldEditEditor EditEditor => new SeoTextBoxEditEditor(); | ||
|
||
public FacebookIdField() | ||
{ | ||
var propertyEditor = new SeoFieldPropertyEditor("textbox"); | ||
propertyEditor.SetExtraInformation("Provide the Facebook app_id associated with this content"); | ||
|
||
Editor = propertyEditor; | ||
} | ||
|
||
protected override HtmlString Render(string value) | ||
{ | ||
return new HtmlString(value.IsNullOrWhiteSpace() ? string.Empty : $"<meta name=\"fb:app_id\" content=\"{value}\"/>"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/OpenGraphUrlField.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.AspNetCore.Html; | ||
using Umbraco.Cms.Core.Composing; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Constants; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField; | ||
using Umbraco.Extensions; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Models.SeoField; | ||
|
||
[Weight(600)] | ||
public class OpenGraphUrlField : SeoField<string> | ||
{ | ||
public override string Title => "Open Graph Url"; | ||
public override string Alias => SeoFieldAliasConstants.OpenGraphUrl; | ||
public override string Description => "Open Graph Url for the content"; | ||
public override string GroupAlias => SeoFieldGroupConstants.SocialMediaGroup; | ||
public override ISeoFieldEditor Editor { get; } | ||
public override ISeoFieldEditEditor EditEditor => new SeoTextBoxEditEditor(); | ||
|
||
public OpenGraphUrlField() | ||
{ | ||
var propertyEditor = new SeoFieldPropertyEditor("textbox"); | ||
propertyEditor.SetExtraInformation("You can use %CurrentUrl% to display the URL of the current item"); | ||
propertyEditor.SetDefaultValue("%CurrentUrl%"); | ||
|
||
Editor = propertyEditor; | ||
} | ||
|
||
protected override HtmlString Render(string value) | ||
{ | ||
return new HtmlString(value.IsNullOrWhiteSpace() ? null : $"<meta name=\"og:url\" content=\"{value}\"/>"); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/TwitterCardTypeField.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.AspNetCore.Html; | ||
using Umbraco.Cms.Core.Composing; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Constants; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Models.Converters; | ||
using Umbraco.Extensions; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Models.SeoField; | ||
|
||
[Weight(601)] | ||
public class TwitterCardTypeField : SeoField<string> | ||
{ | ||
public override string Title => "Twitter Card Type"; | ||
public override string Alias => SeoFieldAliasConstants.TwitterCardType; | ||
public override string Description => "Twitter Card Type for your page"; | ||
public override string GroupAlias => SeoFieldGroupConstants.SocialMediaGroup; | ||
public override ISeoFieldEditor Editor { get; } | ||
public override ISeoFieldEditEditor EditEditor { get; } | ||
|
||
public TwitterCardTypeField() | ||
{ | ||
// App is relevant to direct download links to mobile apps; Player is relevant to video/audio media. | ||
var items = new string[] { | ||
"summary", | ||
"summary_large_image", | ||
"app", | ||
"player" | ||
}; | ||
|
||
var propertyEditor = new SeoDropdownEditEditor(items); | ||
// propertyEditor.SetExtraInformation("Use one of 'summary', 'summary_large_image', 'app', 'player' or 'product'"); | ||
// propertyEditor.SetDefaultValue("summary"); | ||
|
||
Editor = new DropdownFieldPropertyEditor(items); | ||
|
||
EditEditor = propertyEditor; | ||
} | ||
|
||
protected override HtmlString Render(string value) | ||
{ | ||
if (value is null) { | ||
return HtmlString.Empty; | ||
} | ||
return new HtmlString(value.IsNullOrWhiteSpace() ? null : $"<meta name=\"twitter:card\" content=\"{value}\"/>"); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/TwitterCreatorField.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.AspNetCore.Html; | ||
using Umbraco.Cms.Core.Composing; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Constants; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField; | ||
using Umbraco.Extensions; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Models.SeoField; | ||
|
||
[Weight(603)] | ||
public class TwitterCreatorField : SeoField<string> | ||
{ | ||
public override string Title => "Twitter Creator"; | ||
public override string Alias => SeoFieldAliasConstants.TwitterCreator; | ||
public override string Description => "Twitter Creator for the content"; | ||
public override string GroupAlias => SeoFieldGroupConstants.SocialMediaGroup; | ||
public override ISeoFieldEditor Editor { get; } | ||
public override ISeoFieldEditEditor EditEditor => new SeoTextBoxEditEditor(); | ||
|
||
public TwitterCreatorField() | ||
{ | ||
var propertyEditor = new SeoFieldPropertyEditor("textbox"); | ||
propertyEditor.SetExtraInformation("Provide the Twitter username of the content creator"); | ||
|
||
Editor = propertyEditor; | ||
} | ||
|
||
protected override HtmlString Render(string value) | ||
{ | ||
// Check for the "@" at the start of the value and remove if present - we'll add it in. | ||
if (value.StartsWith("@")) { | ||
value = value[1..]; | ||
} | ||
return new HtmlString(value.IsNullOrWhiteSpace() ? null : $"<meta name=\"twitter:creator\" content=\"@{value}\"/>"); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/TwitterSiteField.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.AspNetCore.Html; | ||
using Umbraco.Cms.Core.Composing; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditors; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Constants; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField; | ||
using Umbraco.Extensions; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Models.SeoField; | ||
|
||
[Weight(602)] | ||
public class TwitterSiteField : SeoField<string> | ||
{ | ||
public override string Title => "Twitter Site"; | ||
public override string Alias => SeoFieldAliasConstants.TwitterSite; | ||
public override string Description => "Twitter Site for the content"; | ||
public override string GroupAlias => SeoFieldGroupConstants.SocialMediaGroup; | ||
public override ISeoFieldEditor Editor { get; } | ||
public override ISeoFieldEditEditor EditEditor => new SeoTextBoxEditEditor(); | ||
|
||
public TwitterSiteField() | ||
{ | ||
var propertyEditor = new SeoFieldPropertyEditor("textbox"); | ||
propertyEditor.SetExtraInformation("Provide the Twitter username of the website"); | ||
|
||
Editor = propertyEditor; | ||
} | ||
|
||
protected override HtmlString Render(string value) | ||
{ | ||
// Check for the "@" at the start of the value and remove if present - we'll add it in. | ||
if (value.StartsWith("@")) { | ||
value = value[1..]; | ||
} | ||
return new HtmlString(value.IsNullOrWhiteSpace() ? string.Empty : $"<meta name=\"twitter:site\" content=\"@{value}\"/>"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ds/wwwroot/MetaFields/Interface/SeoFieldEditors/PropertyEditor/dropdownList.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
angular.module("umbraco").controller("SeoToolkit.SeoFieldEditors.DropdownListController", | ||
function ($scope) { | ||
|
||
//ensure when form is saved that we don't store [] or [null] as string values in the database when no items are selected | ||
$scope.$on("formSubmitting", function () { | ||
if ($scope.model.value !== null && ($scope.model.value.length === 0 || $scope.model.value[0] === null)) { | ||
$scope.model.value = null; | ||
} | ||
}); | ||
|
||
$scope.updateSingleDropdownValue = function() { | ||
$scope.model.value = $scope.model.singleDropdownValue; | ||
} | ||
|
||
//now we need to check if the value is null/undefined, if it is we need to set it to "" so that any value that is set | ||
// to "" gets selected by default | ||
if ($scope.model.value === null || $scope.model.value === undefined) { | ||
$scope.model.value = ""; | ||
} | ||
|
||
// if we run in single mode we'll store the value in a local variable | ||
// so we can pass an array as the model as our PropertyValueEditor expects that | ||
$scope.model.singleDropdownValue = ""; | ||
if ($scope.model.value) { | ||
$scope.model.singleDropdownValue = $scope.model.value; | ||
} | ||
}); |
Oops, something went wrong.