Exemple #1
0
        private Task <string> ResolveEmbedInclude(IMetadata data, IPage page)
        {
            var embedData = data.ToObject <EmbedIncludeData>();

            var asset = AssetsHelper.FindAsset(m_Site, page, embedData.FileName);

            return(Task.FromResult(asset.AsTextContent()));
        }
Exemple #2
0
        private Task OnPreCompile(ISite site)
        {
            foreach (var page in site.MainPage.GetAllPages())
            {
                string image;

                if (MetadataExtension.TryGetParameter <string>(page.Data, IMAGE_TAG_NAME, out image))
                {
                    if (!string.IsNullOrEmpty(image))
                    {
                        if (string.Equals(Path.GetExtension(image),
                                          SVG_EXT, StringComparison.CurrentCultureIgnoreCase))
                        {
                            IAsset imgAsset;

                            try
                            {
                                imgAsset = AssetsHelper.FindAsset(site, page, image);
                            }
                            catch (Exception ex)
                            {
                                throw new NullReferenceException($"Failed to find image asset: '{image}'", ex);
                            }

                            var imgName = Path.GetFileNameWithoutExtension(image) + PNG_EXT;

                            byte[] pngBuffer = null;

                            using (var svgStream = new MemoryStream(imgAsset.Content))
                            {
                                var svgDocument = SvgDocument.Open <SvgDocument>(svgStream);
                                var bitmap      = svgDocument.Draw(m_Settings.SvgPngWidth, m_Settings.SvgPngHeight);

                                using (var pngStream = new MemoryStream())
                                {
                                    bitmap.Save(pngStream, ImageFormat.Png);
                                    pngBuffer = pngStream.ToArray();
                                }
                            }

                            page.Data.Add(REPLACE_IMAGE_TAG_NAME, imgName);
                            var imgPngAsset = new PluginAsset(pngBuffer, imgName);
                            page.Assets.Add(imgPngAsset);
                        }
                    }
                }
            }

            if (m_Settings.GenerateFavIcon)
            {
                GenerateFavIcon(site);
            }

            return(Task.CompletedTask);
        }