Пример #1
0
        public Func <JToken, SanityOptions, Task <string> > SerializeImageGallery()
        {
            return(async(JToken input, SanityOptions options) =>
            {
                var html = new StringBuilder();
                var layout = input["layout"]?.ToObject <string>() ?? "";
                var customLayout = input["customLayout"]?.ToObject <string>() ?? "";
                var images = input["images"]?.ToObject <List <SanityImageGalleryImage> >();

                if (images.Count > 0)
                {
                    html.Append("<ul class=\"gp-image-gallery " + layout + " " + customLayout + "\">");
                    foreach (var img in images)
                    {
                        var originalurl = SanityImageUtilities.GetImageURL(img, _opts);

                        var _img = _imgService.GetCachedImageUrl(originalurl);
                        html.Append("<li>");
                        html.Append("<figure>");
                        html.Append("<img src=\"" + _img + "\" />");
                        html.Append("<figcaption class=\"caption\">" + (img.Caption.Length != 0 ? await _sanity.HtmlBuilder.BuildAsync(img?.Caption) : "&nbsp;") + "</figcaption>");
                        html.Append("</figure>");
                        html.Append("</li>");
                    }
                    html.Append("</ul>");
                    return (html.ToString());
                }
                else
                {
                    return "";
                }
            });
        }
Пример #2
0
 internal void Initialize(SanityDataContext sanity)
 {
     _sanity = sanity;
     _sanity.AddHtmlSerializer("image", SanityImageUtilities.CreateCachedSerializer(_imgService));
     _sanity.AddHtmlSerializer("column2", SerializeDoubleColumns());
     _sanity.AddHtmlSerializer("column3", SerializeTrippleColumns());
     _sanity.AddHtmlSerializer("video", SerializeVideo());
     _sanity.AddHtmlSerializer("imageGallery", SerializeImageGallery());
     _sanity.AddHtmlSerializer("tableItem", SerializeTable());
     _sanity.AddHtmlSerializer("modal", SerializeModal());
 }