-
Notifications
You must be signed in to change notification settings - Fork 28
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
Possible to set meta robots noindex/nofollow? #123
Comments
Hi @ianleeder Yeah, robot tags aren't yet possible. I will see what I can do in the coming days, it shouldn't be hard to add this to the metafields package. And good find with the documentation. I'll also see if I can improve on that, because it is possible to add fields already |
Part of this has been picked up with this PR: #126. That will give you the ability to set the robot tag value on document type level. I'll also get it working for content level, but that will take a bit longer so I already merged this part. Expect this to be in the new version somewhere next week |
Any update on doing this at the content level @patrickdemooij9? And similar to #140, is it possible to read these values through code? My customer wants to hide For now I'll probably just add two checkboxes ( |
Has now been added in the latest release 2.3.0 & 3.1.0. |
Thanks @patrickdemooij9. I had a poke around in the source, and it looks like I need to use Am I on the wrong track? |
@ianleeder you are on the right track. Here is some example code of me reading & setting the title on a published event:
Though, hearing that the VariationContext is null is a bit weird to me. I assume you are trying to do this outside Umbraco context?
I also think that the service should have a method where you can pass the culture, so I made an issue for that: #162. Though I think you should be able to get it working with the VariationContext. Let me know if you still have any issues with this! |
Yeah, that's pretty much what I'm doing. The customer wants to hide pages from the sitemap if the robots meta value is set to public class HideFromSiteMapNotificationHandler : INotificationHandler<GenerateSitemapNodeNotification>
{
private IMetaFieldsValueService _metaFieldsValueService;
public HideFromSiteMapNotificationHandler(IMetaFieldsValueService metaFieldsValueService)
{
_metaFieldsValueService = metaFieldsValueService;
}
public void Handle(GenerateSitemapNodeNotification notification)
{
notification.Node.HideFromSitemap |= notification.Node.Content.Value<bool>("hideFromSitemap");
if(!notification.Node.HideFromSitemap)
{
Dictionary<string, object> values = _metaFieldsValueService.GetUserValues(notification.Node.Content.Id);
// Check Robots NOINDEX value
}
}
} It's a valid ID, I've also tried hard-coding one. I had to create a debug build and step into the code to find out why it's throwing I don't need my own |
@ianleeder, I think I see what is going on then. Am I right in assuming that you have a website with just one language? |
Not at work at the moment, so I can’t check, but I think there may be two. I added “en-au” as default. At some point I think I tried to delete “en-us”, but from memory I had some issue (possibly unrelated) and added it back.
On 9 Feb 2023, at 19:02, patrickdemooij9 ***@***.***> wrote:
@ianleeder<https://github.com/ianleeder>, I think I see what is going on then. Am I right in assuming that you have a website with just one language?
—
Reply to this email directly, view it on GitHub<#123 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AB64BFGI32TT26W2XVA26MLWWSQCBANCNFSM6AAAAAAQ6P5NHE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
So I was having a play with this today @patrickdemooij9 . The top variable ( The It looks like #162 is required to bypass this limitation. |
@ianleeder have you find a solution for hiding contents with NOINDEX selected? |
@dederuhi Patrick's solution above works after the fix in #166. For reference here is my complete class: using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.Services;
using SeoToolkit.Umbraco.Sitemap.Core.Notifications;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Events;
using Umbraco.Extensions;
namespace MyProject.Notifications;
// https://seotoolkit.gitbook.io/useotoolkit/extensions/notifications#generatesitemapnodenotification
public class HideFromSiteMapComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddNotificationHandler<GenerateSitemapNodeNotification, HideFromSiteMapNotificationHandler>();
}
}
public class HideFromSiteMapNotificationHandler : INotificationHandler<GenerateSitemapNodeNotification>
{
private readonly IMetaFieldsValueService _metaFieldsValueService;
public HideFromSiteMapNotificationHandler(IMetaFieldsValueService metaFieldsValueService)
{
_metaFieldsValueService = metaFieldsValueService;
}
public void Handle(GenerateSitemapNodeNotification notification)
{
// Get settings for this content node
Dictionary<string, object> values = _metaFieldsValueService.GetUserValues(notification.Node.Content.Id);
// If settings include robots noindex, hide from sitemap
if (values.TryGetValue("robots", out object? robotsObject) && robotsObject is string robotsString)
{
notification.Node.HideFromSitemap |= robotsString.Split(',').Contains("noindex");
}
}
} |
Very excited to find this package, it covers 99% of my needs! I was mildly surprised that it doesn't seem to allow setting a meta tag for
robots
, eg:https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag
Have I missed something, or do you have another recommended method to accomplish this?
If I was implementing this myself, I was going to add 2 checkboxes to each document type settings. However given all the other SEO settings are now in a new page, I'd like to keep them grouped if possible.
I just found this promising teaser in the wiki:
Is it already possible, but just undocumented?
Regardless of your answer, love your work, and I'm excited to use this package.
The text was updated successfully, but these errors were encountered: