コード例 #1
0
        public void RegisterTwitter(MetaTagsPart metaTags)
        {
            _resourceManager.RegisterMeta(new MetaEntry {
                Property = "twitter:card", Content = "summary_large_image"
            });
            _resourceManager.RegisterMeta(new MetaEntry {
                Property = "twitter:url", Content = GetPageUrl()
            });

            if (!string.IsNullOrWhiteSpace(metaTags.Title))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Property = "twitter:title", Content = metaTags.Title
                });
            }

            if (!string.IsNullOrWhiteSpace(metaTags.Description))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Property = "twitter:description", Content = metaTags.Description
                });
            }

            if (metaTags.Images != null && metaTags.Images.Any())
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Property = "twitter:image", Content = GetMediaUrl(metaTags.Images[0])
                });
            }
        }
コード例 #2
0
        public void RegisterOpenGraph(MetaTagsPart metaTags)
        {
            _resourceManager.RegisterMeta(new MetaEntry {
                Property = "og:type", Content = "website"
            });
            _resourceManager.RegisterMeta(new MetaEntry {
                Property = "og:url", Content = GetPageUrl()
            });

            if (!string.IsNullOrWhiteSpace(metaTags.Title))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Property = "og:title", Content = metaTags.Title
                });
            }

            if (!string.IsNullOrWhiteSpace(metaTags.Description))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Property = "og:description", Content = metaTags.Description
                });
            }

            if (metaTags.Images != null && metaTags.Images.Any())
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Property = "og:image", Content = GetMediaUrl(metaTags.Images[0])
                });
            }
        }
コード例 #3
0
        public void RegisterOpenGraph(MetaTagsPart metaTags)
        {
            _resourceManager.RegisterMeta(new MetaEntry {
                Name = "og:type", Content = "website"
            });
            _resourceManager.RegisterMeta(new MetaEntry {
                Name = "og:url", Content = GetPageUrl()
            });

            if (!string.IsNullOrWhiteSpace(metaTags.Title))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Name = "og:title", Content = metaTags.Title
                });
            }

            if (!string.IsNullOrWhiteSpace(metaTags.Description))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Name = "og:description", Content = metaTags.Description
                });
            }

            if (metaTags.Images != null && metaTags.Images.Any())
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Name = "og:image", Content = $"{GetHostUrl()}{_mediaFileStore.MapPathToPublicUrl(metaTags.Images[0])}"
                });
            }
        }
コード例 #4
0
        public void RegisterTwitter(MetaTagsPart metaTags)
        {
            _resourceManager.RegisterMeta(new MetaEntry {
                Name = "twitter:card", Content = "summary_large_image"
            });
            _resourceManager.RegisterMeta(new MetaEntry {
                Name = "twitter:url", Content = GetPageUrl()
            });

            if (!string.IsNullOrWhiteSpace(metaTags.Title))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Name = "twitter:title", Content = metaTags.Title
                });
            }

            if (!string.IsNullOrWhiteSpace(metaTags.Description))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Name = "twitter:description", Content = metaTags.Description
                });
            }

            if (metaTags.Images != null && metaTags.Images.Any())
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Name = "twitter:image", Content = $"{GetHostUrl()}{_mediaFileStore.MapPathToPublicUrl(metaTags.Images[0])}"
                });
            }
        }
コード例 #5
0
        public static void UpdateTitle(this MetaTagsPart part, string title)
        {
            var field = part.GetOrCreate <TextField>(Constants.TitleFieldName);

            if (field != null)
            {
                field.Text = title;
                part.Apply(Constants.TitleFieldName, field);
            }
        }
コード例 #6
0
        public static void UpdateImage(this MetaTagsPart part, string[] paths)
        {
            var field = part.GetOrCreate <MediaField>(Constants.ImageFieldName);

            if (field != null)
            {
                field.Paths = paths;
                part.Apply(Constants.ImageFieldName, field);
            }
        }
コード例 #7
0
        public static void UpdateDescription(this MetaTagsPart part, string description)
        {
            var field = part.GetOrCreate <TextField>(Constants.DescriptionFieldName);

            if (field != null)
            {
                field.Text = description;
                part.Apply(Constants.DescriptionFieldName, field);
            }
        }
コード例 #8
0
        public static IList <DictionaryItem> GetCustom(this MetaTagsPart part, IList <DictionaryItem> defaults)
        {
            var values = part.Get <DictionaryField>(Constants.CustomFieldName)?.Data ?? new List <DictionaryItem>();

            if (defaults != null)
            {
                foreach (var customValue in defaults.Where(x => !values.Any(v => v.Name == x.Name)))
                {
                    values.Add(customValue);
                }
            }

            return(values);
        }
コード例 #9
0
        public void RegisterDefaults(MetaTagsPart metaTags)
        {
            if (!string.IsNullOrWhiteSpace(metaTags.Title))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Name = "title", Content = metaTags.Title
                });
            }

            if (!string.IsNullOrWhiteSpace(metaTags.Description))
            {
                _resourceManager.RegisterMeta(new MetaEntry {
                    Name = "description", Content = metaTags.Description
                });
            }
        }
コード例 #10
0
        public void Register(MetaTagsPart part)
        {
            var customMetaTags = part.GetCustom();
            var description    = part.GetDescription();
            var imagePath      = part.GetImage();
            var noIndex        = part.GetNoIndex();
            var title          = part.GetTitle();

            if (string.IsNullOrWhiteSpace(title))
            {
                title = part.ContentItem.DisplayText;
            }

            RegisterCustom(customMetaTags);
            RegisterDefaults(title, description, customMetaTags);
            RegisterNoIndex(noIndex, customMetaTags);
            RegisterOpenGraph(title, description, imagePath, customMetaTags);
            RegisterTwitter(title, description, imagePath, customMetaTags);
        }
コード例 #11
0
        public async Task RegisterAsync(MetaTagsPart part)
        {
            _site = await _siteService.GetSiteSettingsAsync();

            var defaultMetaTags = await GetDefaultMetaTagsAsync(_site, part);

            var customMetaTags = part.GetCustom(defaultMetaTags.Custom);
            var description    = part.GetDescription() ?? defaultMetaTags.Description;
            var imagePath      = part.GetImage() ?? defaultMetaTags.ImagePath;
            var noIndex        = part.GetNoIndex();
            var title          = part.GetTitle() ?? defaultMetaTags.Title;

            if (string.IsNullOrWhiteSpace(title))
            {
                title = part.ContentItem.DisplayText;
            }

            RegisterCustom(customMetaTags);
            RegisterDefaults(title, description, customMetaTags);
            RegisterNoIndex(noIndex, customMetaTags);
            RegisterOpenGraph(title, description, imagePath, customMetaTags);
            RegisterTwitter(title, description, imagePath, customMetaTags);
        }
コード例 #12
0
 public static string GetTitle(this MetaTagsPart part)
 {
     return(part?.Get <TextField>(Constants.TitleFieldName)?.Text ?? null);
 }
コード例 #13
0
 public static string GetImage(this MetaTagsPart part)
 {
     return(part?.Get <MediaField>(Constants.ImageFieldName)?.Paths?.FirstOrDefault() ?? null);
 }
コード例 #14
0
 public static string GetDescription(this MetaTagsPart part)
 {
     return(part?.Get <TextField>(Constants.DescriptionFieldName)?.Text ?? null);
 }
コード例 #15
0
 public static IList <DictionaryItem> GetCustom(this MetaTagsPart part)
 {
     return(part.Get <DictionaryField>(Constants.CustomFieldName)?.Data);
 }
コード例 #16
0
        private async Task <DefaultMetaTags> GetDefaultMetaTagsAsync(ISite siteSettings, MetaTagsPart part)
        {
            var settings = siteSettings.As <ContentItem>("DefaultMetaTags")?.Get <ContentPart>("DefaultMetaTags");

            if (settings == null)
            {
                return(new DefaultMetaTags());
            }

            var imagePath = settings.Get <MediaField>("Image")?.Paths?.FirstOrDefault() ?? string.Empty;
            var values    = new Dictionary <string, FluidValue>()
            {
                ["ContentItem"] = new ObjectValue(part.ContentItem)
            };

            return(new DefaultMetaTags
            {
                Custom = settings.Get <DictionaryField>("Custom")?.Data,
                Description = await _liquidTemplateManager.RenderStringAsync(settings.Get <TextField>("Description")?.Text, NullEncoder.Default, null, values),
                ImagePath = imagePath,
                Title = await _liquidTemplateManager.RenderStringAsync(settings.Get <TextField>("Title")?.Text, NullEncoder.Default, null, values)
            });
        }
コード例 #17
0
 public static bool GetNoIndex(this MetaTagsPart part)
 {
     return(part?.Get <BooleanField>(Constants.NoIndexFieldName)?.Value ?? false);
 }
コード例 #18
0
 public static string GetJSONLD(this MetaTagsPart part)
 {
     return(part?.Get <TextField>(Constants.JSONLDFieldName)?.Text ?? string.Empty);
 }