From 776560bf96c6cefe34cd626a30999f9066a9a0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Furhan=20G=C3=BCl?= Date: Wed, 31 May 2023 15:38:47 +0300 Subject: [PATCH] Seo Keywords added with Umbraco Tags Editor --- .../SeoFieldEditEditors/SeoKeywordsEditor.cs | 24 +++++++++++++++ .../KeywordsFieldPropertyEditor.cs | 25 ++++++++++++++++ .../Composers/MetaFieldsComposer.cs | 3 +- .../Constants/SeoFieldAliasConstants.cs | 1 + .../Models/SeoField/KeywordsField.cs | 30 +++++++++++++++++++ .../Models/SeoService/MetaTagsModel.cs | 6 ++++ 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditEditors/SeoKeywordsEditor.cs create mode 100644 src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditors/KeywordsFieldPropertyEditor.cs create mode 100644 src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/KeywordsField.cs diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditEditors/SeoKeywordsEditor.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditEditors/SeoKeywordsEditor.cs new file mode 100644 index 00000000..f06a1dbe --- /dev/null +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditEditors/SeoKeywordsEditor.cs @@ -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 Config { get; } + public IEditorValueConverter ValueConverter { get; } + + public SeoKeywordsEditor() + { + Config = new Dictionary + { + { "group", "keywords" }, + { "storageType", "Json" } + }; + ValueConverter = new TextValueConverter(); + } + } +} diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditors/KeywordsFieldPropertyEditor.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditors/KeywordsFieldPropertyEditor.cs new file mode 100644 index 00000000..d195b3c1 --- /dev/null +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Common/SeoFieldEditors/KeywordsFieldPropertyEditor.cs @@ -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; + } + } +} diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Composers/MetaFieldsComposer.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Composers/MetaFieldsComposer.cs index 8fc1de49..61a1e49d 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Composers/MetaFieldsComposer.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Composers/MetaFieldsComposer.cs @@ -66,7 +66,8 @@ public void Compose(IUmbracoBuilder builder) .Add() .Add() .Add() - .Add(); + .Add() + .Add(); builder.WithCollectionBuilder() .Add() diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Constants/SeoFieldAliasConstants.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Constants/SeoFieldAliasConstants.cs index 54bc3ea3..9dcf823b 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Constants/SeoFieldAliasConstants.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Constants/SeoFieldAliasConstants.cs @@ -3,6 +3,7 @@ public static class SeoFieldAliasConstants { public const string Title = "title"; + public const string Keywords = "keywords"; public const string MetaDescription = "metaDescription"; public const string OpenGraphTitle = "openGraphTitle"; public const string OpenGraphDescription = "openGraphDescription"; diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/KeywordsField.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/KeywordsField.cs new file mode 100644 index 00000000..caaaddd3 --- /dev/null +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoField/KeywordsField.cs @@ -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($"(s))}\"/>"); + } +} \ No newline at end of file diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoService/MetaTagsModel.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoService/MetaTagsModel.cs index 8125a8f8..8e4b628f 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoService/MetaTagsModel.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Models/SeoService/MetaTagsModel.cs @@ -72,5 +72,11 @@ public string CanonicalUrl get => GetValue(SeoFieldAliasConstants.CanonicalUrl); set => SetValue(SeoFieldAliasConstants.CanonicalUrl, value); } + + public string Keywords + { + get => GetValue(SeoFieldAliasConstants.Keywords); + set => SetValue(SeoFieldAliasConstants.Keywords, value); + } } }