Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seo Keywords added with Umbraco Tags Editor #198

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -41,7 +41,8 @@ public void Compose(IUmbracoBuilder builder)
builder.Services.Configure<MetaFieldsAppSettingsModel>(section);
builder.Services.AddSingleton(typeof(ISettingsService<MetaFieldsConfigModel>), typeof(MetaFieldsConfigurationService));

var disabledModules = section?.Get<MetaFieldsAppSettingsModel>()?.DisabledModules ?? Array.Empty<string>();
var settings = section?.Get<MetaFieldsAppSettingsModel>();
var disabledModules = settings?.DisabledModules ?? Array.Empty<string>();

if (disabledModules.Contains(DisabledModuleConstant.All))
{
Expand All @@ -50,7 +51,7 @@ public void Compose(IUmbracoBuilder builder)
}

builder.Components().Append<EnableModuleComponent>();

builder.Services.AddTransient(typeof(IRepository<DocumentTypeSettingsDto>), typeof(MetaFieldsSettingsDatabaseRepository));
builder.Services.AddTransient(typeof(IMetaFieldsSettingsService), typeof(MetaFieldsSettingsService));
builder.Services.AddTransient(typeof(IMetaFieldsService), typeof(MetaFieldsService));
Expand All @@ -66,7 +67,13 @@ public void Compose(IUmbracoBuilder builder)
.Add<OpenGraphDescriptionField>()
.Add<OpenGraphImageField>()
.Add<CanonicalUrlField>()
.Add<RobotsField>();
.Add<RobotsField>()
.Add<SeoSchemaField>();

if (settings?.ShowKeywordsField is true)
{
builder.WithCollectionBuilder<SeoFieldCollectionBuilder>().Add<KeywordsField>();
}

builder.WithCollectionBuilder<SeoConverterCollectionBuilder>()
.Add<TextSeoValueConverter>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ public class MetaFieldsAppSettingsModel
public string[] SupportedMediaTypes { get; set; } = new[] { ".png", ".jpg", ".jpeg", ".webp", ".gif" };
public string OpenGraphCropAlias { get; set; } = "openGraphImage";
public string[] DisabledModules { get; set; } = Array.Empty<string>();

/// <summary>
/// Determines if the meta field keywords should be shown. Most search engines don't use it anymore.
/// </summary>
public bool ShowKeywordsField { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public static class SeoFieldAliasConstants
{
public const string Title = "title";
public const string Keywords = "keywords";
public const string Schema = "schema";
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
@@ -0,0 +1,28 @@
using System;
using Microsoft.AspNetCore.Html;
using Umbraco.Cms.Core.Composing;
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors;
using SeoToolkit.Umbraco.MetaFields.Core.Constants;
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField;
using SeoToolkit.Umbraco.MetaFields.Core.Models.SeoFieldEditors;

namespace SeoToolkit.Umbraco.MetaFields.Core.Models.SeoField
{
[Weight(200)]
public class SeoSchemaField : ISeoField
{
public string Title => "Schema";
public string Alias => SeoFieldAliasConstants.Schema;
public string Description => "The schemas are a set of 'types', each associated with a set of properties. The types are arranged in a hierarchy.";
public string GroupAlias => SeoFieldGroupConstants.Others;
public Type FieldType => typeof(string);

public ISeoFieldEditor Editor => new SeoFieldFieldsEditor(new[] { "Umbraco.TextBox", "Umbraco.TextArea", "Umbraco.TinyMCE" });
public ISeoFieldEditEditor EditEditor => new SeoTextAreaEditEditor();

public HtmlString Render(object value)
{
return new HtmlString($"{value}");
}
}
}
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);
}
}
}