Skip to content

Commit

Permalink
Seo Keywords added with Umbraco Tags Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Uğurhan Gül committed May 31, 2023
1 parent 13b2ad9 commit 776560b
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
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();
}
}
}
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public void Compose(IUmbracoBuilder builder)
.Add<OpenGraphDescriptionField>()
.Add<OpenGraphImageField>()
.Add<CanonicalUrlField>()
.Add<RobotsField>();
.Add<RobotsField>()
.Add<KeywordsField>();

builder.WithCollectionBuilder<SeoConverterCollectionBuilder>()
.Add<TextSeoValueConverter>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
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))}\"/>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@ public string CanonicalUrl
get => GetValue<string>(SeoFieldAliasConstants.CanonicalUrl);
set => SetValue(SeoFieldAliasConstants.CanonicalUrl, value);
}

public string Keywords
{
get => GetValue<string>(SeoFieldAliasConstants.Keywords);
set => SetValue(SeoFieldAliasConstants.Keywords, value);
}
}
}

0 comments on commit 776560b

Please sign in to comment.