public void BuildBundleData(ContentFragmentPageControl contentFragmentPage, CQ parsedContent) { if (Configuration.OptomizeGlobalCss) { //Get the themes CSS files CQ elements = parsedContent.Select(BuildSelector); foreach (IDomObject element in elements) { string mediaType = element.GetAttribute("media") ?? "screen"; if (mediaType.IndexOf("screen", StringComparison.OrdinalIgnoreCase) > -1) { string src = element.GetAttribute("href"); if (!string.IsNullOrEmpty(src) && mediaType.IndexOf("dynamic-style.aspx", StringComparison.OrdinalIgnoreCase) < 0 && src.EndsWith(".css")) { IBundledFile file = _bundledFileFactory.GetBundleFile("css", src, contentFragmentPage, ""); if (file != null) { HandleLayoutCssPath(file); Include(file); } } } } } }
protected void Include(IBundledFile bundledFile) { if (!PartOfBundle(bundledFile.OrignalUri)) { Bundle.Include(bundledFile.RelativeUri); _includedFiles[bundledFile.OrignalUri] = true; } }
private void HandleLayoutCssPath(IBundledFile file) { using (FileStream fs = new FileStream(file.LocalPath, FileMode.Open, FileAccess.ReadWrite)) { using (StreamReader sr = new StreamReader(fs)) { string fileData = sr.ReadToEnd(); fileData = fileData.Replace("../images/", "../../../../Themes/generic/images/"); fs.Seek(0, SeekOrigin.Begin); byte[] bytes = ASCIIEncoding.UTF8.GetBytes(fileData); fs.Write(bytes, 0, bytes.Length); } } }
private void HandleInlineScripts(CQ parsedContent, ContentFragmentPageControl contentFragmentPage) { if (Configuration.OptomizeGlobalJs) { //Get the themes CSS files CQ elements = parsedContent.Select(BuildSelector); foreach (IDomObject element in elements) { string src = element.GetAttribute("src"); if (!string.IsNullOrEmpty(src)) { IBundledFile file = _bundledFileFactory.GetBundleFile("js", src, contentFragmentPage, ""); if (file != null) { Include(file); } } } //Get the themes axd files elements = parsedContent.Select(BuildAxdSelector); int i = 0; foreach (IDomObject element in elements) { string src = element.GetAttribute("src"); if (!string.IsNullOrEmpty(src)) { IBundledFile file = _bundledFileFactory.GetBundleFile("js", src, contentFragmentPage, i.ToString()); if (file != null) { Include(file); } i++; } } } }