-
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.
Seo Keywords added with Umbraco Tags Editor
- Loading branch information
Uğurhan Gül
committed
May 31, 2023
1 parent
13b2ad9
commit 776560b
Showing
6 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditEditors/SeoKeywordsEditor.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; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors | ||
{ | ||
public class SeoKeywordsEditor : ISeoFieldEditEditor | ||
{ | ||
public string View => "tags"; | ||
public Dictionary<string, object> Config { get; } | ||
public IEditorValueConverter ValueConverter { get; } | ||
|
||
public SeoKeywordsEditor() | ||
{ | ||
Config = new Dictionary<string, object> | ||
{ | ||
{ "group", "keywords" }, | ||
{ "storageType", "Json" } | ||
}; | ||
ValueConverter = new TextValueConverter(); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditors/KeywordsFieldPropertyEditor.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,25 @@ | ||
using Newtonsoft.Json.Linq; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Common.Converters.EditorConverters; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField; | ||
using SeoToolkit.Umbraco.MetaFields.Core.Models.Converters; | ||
using System.Linq; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditors | ||
{ | ||
public class KeywordsFieldPropertyEditor : SeoFieldPropertyEditor, ISeoFieldEditorProcessor | ||
{ | ||
|
||
public KeywordsFieldPropertyEditor() : base("tags", new TextValueConverter()) | ||
{ | ||
IsPreValue = false; | ||
Config.Add("group", "keywords"); | ||
Config.Add("storageType", "Json"); | ||
|
||
} | ||
|
||
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
30 changes: 30 additions & 0 deletions
30
src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/KeywordsField.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,30 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Html; | ||
using Newtonsoft.Json; | ||
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.SeoFieldEditors; | ||
using Umbraco.Cms.Core.Composing; | ||
|
||
namespace SeoToolkit.Umbraco.MetaFields.Core.Models.SeoField; | ||
|
||
[Weight(200)] | ||
public class KeywordsField : ISeoField | ||
{ | ||
public string Title => "Keywords"; | ||
public string Alias => SeoFieldAliasConstants.Keywords; | ||
public string Description => "Keywords for the page"; | ||
public string GroupAlias => SeoFieldGroupConstants.MetaFieldsGroup; | ||
public Type FieldType => typeof(string); | ||
|
||
public ISeoFieldEditor Editor => new KeywordsFieldPropertyEditor(); | ||
public ISeoFieldEditEditor EditEditor => new SeoKeywordsEditor(); | ||
|
||
public HtmlString Render(object value) | ||
{ | ||
if (value is not string s) return null; | ||
return string.IsNullOrEmpty(s) ? null : new HtmlString($"<meta name=\"keywords\" content=\"{string.Join(",", JsonConvert.DeserializeObject<string[]>(s))}\"/>"); | ||
} | ||
} |
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