Skip to content

Commit 4764cf3

Browse files
authored
Handle property attribute for custom meta tags (#11)
* Introduce CustomMetaItem container * Updated tests * Dotnet format
1 parent 862ec7d commit 4764cf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+301
-73
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ where `{0}` is the value from `PageTitle` and `{1}` is the value from `SiteName`
3939

4040
### Methods
4141

42-
- `SetCustomMeta(string key, string value)`: Add any custom meta-tag.
42+
- `SetCustomMeta(string key, string value, CustomMetaAttributeKey? attribute = null)`: Add any
43+
custom meta-tag. Keys starting with prefixes such as `og:` or `fb:` default to the `property` attribute. Use
44+
the `attribute` parameter to explicitly choose `name` or `property`.
4345
- `SetMetaRobots(bool index, bool follow)`: Specify the instructions for robots.
4446
Updates the value for `MetaRobots`.
4547

src/AspNetSeo.CoreMvc/ActionContextExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
22

33
namespace AspNetSeo.CoreMvc;
44

src/AspNetSeo.CoreMvc/ControllerBaseExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
22

33
namespace AspNetSeo.CoreMvc;
44

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
namespace AspNetSeo.CoreMvc;
1+
namespace AspNetSeo.CoreMvc;
22

33
/// <summary>
44
/// Adds a custom meta tag.
55
/// </summary>
66
/// <param name="name">Meta name.</param>
77
/// <param name="content">Meta content.</param>
8+
/// <param name="attribute">Explicit rendering attribute for the meta key.</param>
89
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
9-
public class CustomMetaAttribute(string name, string content) : SeoAttributeBase
10+
public class CustomMetaAttribute(string name, string content, CustomMetaAttributeKey? attribute = null)
11+
: SeoAttributeBase
1012
{
1113
private readonly string _name = name
1214
?? throw new ArgumentNullException(nameof(name));
1315

1416
private readonly string _content = content;
1517

18+
private readonly CustomMetaAttributeKey? _attribute = attribute;
19+
1620
/// <summary>Applies the custom meta.</summary>
1721
/// <param name="seoHelper">The SEO helper.</param>
1822
public override void OnHandleSeoValues(ISeoHelper seoHelper)
1923
{
20-
seoHelper.CustomMetas[_name] = _content;
24+
seoHelper.SetCustomMeta(_name, _content, _attribute);
2125
}
2226
}
2327

src/AspNetSeo.CoreMvc/ISeoUrlHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
22

33
namespace AspNetSeo.CoreMvc;
44

src/AspNetSeo.CoreMvc/LinkCanonicalAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AspNetSeo.CoreMvc;
1+
namespace AspNetSeo.CoreMvc;
22

33
/// <summary>
44
/// Sets the canonical link.

src/AspNetSeo.CoreMvc/MetaDescriptionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AspNetSeo.CoreMvc;
1+
namespace AspNetSeo.CoreMvc;
22

33
/// <summary>
44
/// Sets the meta description.

src/AspNetSeo.CoreMvc/MetaKeywordsAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AspNetSeo.CoreMvc;
1+
namespace AspNetSeo.CoreMvc;
22

33
/// <summary>
44
/// Sets the meta keywords.

src/AspNetSeo.CoreMvc/MetaRobotsAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using AspNetSeo.Internal;
1+
using AspNetSeo.Internal;
22

33
namespace AspNetSeo.CoreMvc;
44

src/AspNetSeo.CoreMvc/OgDescriptionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AspNetSeo.CoreMvc;
1+
namespace AspNetSeo.CoreMvc;
22

33
/// <summary>
44
/// Sets the Open Graph description.

0 commit comments

Comments
 (0)