/// <summary> /// override the OnPreRender to handle the meta tags /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { string inlineCSS = MetadataExtension.GetMetadata(this, ".InlineCSS"); if (!string.IsNullOrWhiteSpace(inlineCSS)) { this.Context.AppendInlineCSS(inlineCSS); } ViewPageEx viewPage = this.Page as ViewPageEx; if (viewPage != null) { if (!string.IsNullOrWhiteSpace(this.Title) && string.IsNullOrWhiteSpace(viewPage.Title)) { viewPage.Title = this.Title; } if (!string.IsNullOrWhiteSpace(this.MetaKeywords)) { viewPage.MetaKeywords = this.MetaKeywords; } if (!string.IsNullOrWhiteSpace(this.MetaDescription)) { viewPage.MetaDescription = this.MetaDescription; } } base.OnPreRender(e); }
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); }
protected override void OnPreRender(EventArgs e) { string inlineCSS = MetadataExtension.GetMetadata(this, ".InlineCSS"); if (!string.IsNullOrWhiteSpace(inlineCSS)) { this.Context.AppendInlineCSS(inlineCSS); } base.OnPreRender(e); }
public void Validate(HtmlDocument doc, Dictionary <string, object> settings) { TSetts specSetts = null; if (settings != null) { specSetts = MetadataExtension.ToObject <TSetts>(settings); } if (specSetts == null) { specSetts = new TSetts(); } Validate(doc, specSetts); }
private void InitPlugins(Dictionary <Assembly, string> pluginAssemblies) { foreach (var plugin in m_Plugins) { var pluginSpecType = plugin.GetType(); if (plugin is IPlugin) { (plugin as IPlugin).Init(m_Engine); } else if (IsAssignableToGenericType(pluginSpecType, typeof(IPlugin <>), out Type pluginDeclrType)) { var settsType = pluginDeclrType.GetGenericArguments().ElementAt(0); var pluginName = pluginAssemblies[pluginSpecType.Assembly]; IDictionary <string, object> settsData; object setts = null; if (MetadataExtension.TryGetParameter(m_Conf, PLUGIN_SETTINGS_TOKEN + pluginName, out settsData)) { setts = MetadataExtension.ToObject(settsData, settsType); } else { setts = Activator.CreateInstance(settsType); } var initMethod = pluginSpecType.GetMethod(nameof(IPlugin <object> .Init)); initMethod.Invoke(plugin, new object[] { m_Engine, setts }); } else { throw new NotSupportedException($"'{plugin.GetType().FullName}' is not supported"); } } }
public bool TryGet <T>(string prpName, out T val) => MetadataExtension.TryGetParameter <T>(this, prpName, out val);
public T ToObject <T>() => MetadataExtension.ToObject <T>(this);