Exemple #1
0
        private string scriptEval(SeoPartSettings settings, SeoPart part)
        {
            var tokensDictionary = new Dictionary <string, object> {
                { "Content", part.ContentItem }
            };

            return(_tokenizer.Replace(settings.JsonLd, tokensDictionary));;
        }
Exemple #2
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (Orchard.UI.Admin.AdminFilter.IsApplied(filterContext.RequestContext) ||
                !(filterContext.Result is ViewResult))
            {
                return;
            }

            ContentItem currentContent = _currentContentAccessor.GetCurrentContentItem();

            if (currentContent != null)
            {
                SeoPart seoPart = currentContent.As <SeoPart>();
                if (seoPart != null)
                {
                    // Canonical URL
                    string canonicalUrl = _seoService.GetCanonicalUrl(seoPart);
                    if (!String.IsNullOrWhiteSpace(canonicalUrl))
                    {
                        _resourceManager.RegisterLink(new LinkEntry()
                        {
                            Rel = "canonical", Href = canonicalUrl
                        });
                    }
                    // Description meta
                    string description = _seoService.GetDescription(seoPart);
                    if (!String.IsNullOrWhiteSpace(description))
                    {
                        _resourceManager.SetMeta(new MetaEntry()
                        {
                            Name = "description", Content = description
                        });
                    }
                    // Keywords meta
                    string keywords = _seoService.GetKeywords(seoPart);
                    if (!String.IsNullOrWhiteSpace(keywords))
                    {
                        _resourceManager.SetMeta(new MetaEntry()
                        {
                            Name = "keywords", Content = keywords
                        });
                    }
                    // Description meta
                    string robots = _seoService.GetRobots(seoPart);
                    if (!String.IsNullOrWhiteSpace(robots))
                    {
                        _resourceManager.SetMeta(new MetaEntry()
                        {
                            Name = "robots", Content = robots
                        });
                    }
                }
            }
        }
Exemple #3
0
 public string GetDescription(SeoPart part)
 {
     if (String.IsNullOrWhiteSpace(part.Description))
     {
         return(GenerateDefaultDescription(part));
     }
     else
     {
         return(part.Description);
     }
 }
Exemple #4
0
 public SeoPartEditViewModel(SeoPart part)
 {
     if (!String.IsNullOrWhiteSpace(part.Description))
     {
         this.Description         = part.Description;
         this.OverrideDescription = true;
     }
     this.OverrideKeywords = part.OverrideKeywords;
     this.Keywords         = part.Keywords;
     this.OverrideRobots   = part.OverrideRobots;
     this.Robots           = part.Robots;
     this.CanonicalUrl     = part.CanonicalUrl;
 }
Exemple #5
0
        public string GetRobots(SeoPart part)
        {
            SeoRobotsMeta robots;

            if (part.OverrideRobots)
            {
                robots = part.Robots;
            }
            else
            {
                SeoPartSettings settings = part.Settings.GetModel <SeoPartSettings>();
                robots = settings.DefaultRobotsMeta;
            }
            return(robots != SeoRobotsMeta.All ? robots.ToString().ToLower() : String.Empty);
        }
Exemple #6
0
        public string GenerateDefaultKeywords(SeoPart part)
        {
            SeoPartSettings settings = part.Settings.GetModel <SeoPartSettings>();

            if (!String.IsNullOrWhiteSpace(settings.DefaultKeywordsPattern))
            {
                return(_tokenizer.Replace(
                           settings.DefaultKeywordsPattern,
                           BuildTokenContext(part.ContentItem),
                           new ReplaceOptions {
                    Encoding = ReplaceOptions.NoEncode
                }));
            }
            else
            {
                return(String.Empty);
            }
        }
 /// <summary>
 /// Update a part based on the values of properties in the view model.
 /// </summary>
 /// <param name="part">The SeoPart we are going to update.</param>
 /// <param name="seoServices">Dependency injection for services.</param>
 public void UpdatePart(SeoPart part)
 {
     part.TitleOverride              = this.TitleOverride;
     part.CanonicalUrl               = this.CanonicalUrl;
     part.Keywords                   = this.Keywords;
     part.Description                = this.Description;
     part.RobotsNoIndex              = this.RobotsNoIndex;
     part.RobotsNoFollow             = this.RobotsNoFollow;
     part.RobotsNoSnippet            = this.RobotsNoSnippet;
     part.RobotsNoOdp                = this.RobotsNoOdp;
     part.RobotsNoArchive            = this.RobotsNoArchive;
     part.RobotsUnavailableAfter     = this.RobotsUnavailableAfter;
     part.RobotsUnavailableAfterDate = _seoServices.DateToUTC(this._robotsUnavailableAfterDate);
     //part.RobotsUnavailableAfterDate = seoServices.DateToUTC(this.RobotsUnavailableAfterDate);
     part.RobotsNoImageIndex        = this.RobotsNoImageIndex;
     part.GoogleNoSiteLinkSearchBox = this.GoogleNoSiteLinkSearchBox;
     part.GoogleNoTranslate         = this.GoogleNoTranslate;
     part.HideDetailMicrodata       = this.HideDetailMicrodata;
     part.HideAggregatedMicrodata   = this.HideAggregatedMicrodata;
 }
 /// <summary>
 /// Create the ViewModel from the Part.
 /// </summary>
 /// <param name="part">The SeoPart we start from.</param>
 /// <param name="seoServices">Dependency injection for services.</param>
 public SeoPartViewModel(SeoPart part, ISEOServices seoServices) : this(seoServices) {
     this.TitleOverride               = part.TitleOverride;
     this.CanonicalUrl                = part.CanonicalUrl;
     this.Keywords                    = part.Keywords;
     this.Description                 = part.Description;
     this.RobotsNoIndex               = part.RobotsNoIndex;
     this.RobotsNoFollow              = part.RobotsNoFollow;
     this.RobotsNoSnippet             = part.RobotsNoSnippet;
     this.RobotsNoOdp                 = part.RobotsNoOdp;
     this.RobotsNoArchive             = part.RobotsNoArchive;
     this.RobotsUnavailableAfter      = part.RobotsUnavailableAfter;
     this._robotsUnavailableAfterDate = _seoServices.DateToLocal(part.RobotsUnavailableAfterDate);
     //this.RobotsUnavailableAfterDate = seoServices.DateToLocal(part.RobotsUnavailableAfterDate).ToShortDateString();
     this.RobotsNoImageIndex        = part.RobotsNoImageIndex;
     this.GoogleNoSiteLinkSearchBox = part.GoogleNoSiteLinkSearchBox;
     this.GoogleNoTranslate         = part.GoogleNoTranslate;
     this.HideDetailMicrodata       = part.HideDetailMicrodata;
     this.HideAggregatedMicrodata   = part.HideAggregatedMicrodata;
     this.HasDetailMicrodata        = !string.IsNullOrWhiteSpace(part.Settings.GetModel <SeoPartSettings>().JsonLd);
     this.HasAggregatedMicrodata    = part.Settings.GetModel <SeoPartSettings>().ShowAggregatedMicrodata;
 }
Exemple #9
0
 public string GetKeywords(SeoPart part)
 {
     if (part.OverrideKeywords)
     {
         return(CleanKeywords(part.Keywords));
     }
     else
     {
         string defaultKeywords    = CleanKeywords(GenerateDefaultKeywords(part));
         string additionalKeywords = CleanKeywords(part.Keywords);
         if (String.IsNullOrWhiteSpace(defaultKeywords))
         {
             return(additionalKeywords);
         }
         else if (String.IsNullOrWhiteSpace(additionalKeywords))
         {
             return(defaultKeywords);
         }
         else
         {
             return(defaultKeywords + "," + additionalKeywords);
         }
     }
 }
Exemple #10
0
 public string GenerateCanonicalUrl(SeoPart part)
 {
     return(_urlHelper.MakeAbsolute(_urlHelper.RouteUrl(_contentManager.GetItemMetadata(part.ContentItem).DisplayRouteValues)));
 }
Exemple #11
0
        public string GetCanonicalUrl(SeoPart part)
        {
            SeoPartSettings settings = part.Settings.GetModel <SeoPartSettings>();

            return(part.CanonicalUrl ?? (settings.AddCanonicalLink ? GenerateCanonicalUrl(part) : String.Empty));
        }