Пример #1
0
        public virtual async Task <PageMetaModel> GetMetaAsync()
        {
            if (_meta == null)
            {
                _meta = new PageMetaModel {
                    Title = Site.Title, CurrentUrl = new Uri(Site.Url)
                };
                SeoContentPropertiesSet seoPropertiesSet = null;
                if (Section != null)
                {
                    seoPropertiesSet = await PropertiesProvider.GetAsync <SeoContentPropertiesSet>(Section);
                }

                if (seoPropertiesSet != null)
                {
                    _meta.Description = seoPropertiesSet.Description;
                    _meta.Keywords    = seoPropertiesSet.Keywords;
                }
                else
                {
                    var sitePropertiesSet = await PropertiesProvider.GetAsync <SeoSitePropertiesSet>(Site);

                    if (sitePropertiesSet != null)
                    {
                        _meta.Description = sitePropertiesSet.Description;
                        _meta.Keywords    = sitePropertiesSet.Keywords;
                    }
                }
            }

            return(_meta);
        }
Пример #2
0
        public override async Task <PageMetaModel> GetMetaAsync()
        {
            var path = LinkGenerator.GeneratePublicUrl(Entity);
            var meta = new PageMetaModel
            {
                Title = $"{Entity.Title} / {Site.Title}", CurrentUrl = new Uri($"{Site.Url}{path}")
            };

            var seoPropertiesSet = await PropertiesProvider.GetAsync <SeoContentPropertiesSet>(Entity);

            if (seoPropertiesSet != null && !string.IsNullOrEmpty(seoPropertiesSet.Description))
            {
                meta.Description = seoPropertiesSet.Description;
            }
            else
            {
                if (Entity is IContentEntity contentEntity)
                {
                    if (contentEntity.Blocks.OrderBy(b => b.Position).FirstOrDefault(b => b is TextBlock) is TextBlock
                        textBlock)
                    {
                        meta.Description = HtmlHelper.GetDescriptionFromHtml(textBlock.Data.Text);
                    }
                }
            }

            if (seoPropertiesSet != null && !string.IsNullOrEmpty(seoPropertiesSet.Keywords))
            {
                meta.Keywords = seoPropertiesSet.Keywords;
            }
            else
            {
                if (Entity is ITaggedContentEntity taggedContentEntity)
                {
                    meta.Keywords = string.Join(", ", taggedContentEntity.Tags.Select(t => t.Title));
                }
            }

            if (Entity is IContentEntity contEntity)
            {
                foreach (var block in contEntity.Blocks.OrderBy(b => b.Position))
                {
                    if (block is PictureBlock pictureBlock)
                    {
                        meta.ImageUrl = pictureBlock.Data.Picture.PublicUri;
                        break;
                    }

                    if (block is GalleryBlock galleryBlock && galleryBlock.Data.Pictures.Length > 0)
                    {
                        meta.ImageUrl = galleryBlock.Data.Pictures[0].PublicUri;
                        break;
                    }
                }
            }

            return(meta);
        }