format head content, remove scripts, and filter duplicate elements
This commit is contained in:
		| @ -42,16 +42,17 @@ | ||||
|         foreach (Resource resource in PageState.Page.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet)) | ||||
|         { | ||||
|             var url = (resource.Url.Contains("://")) ? resource.Url : PageState.Alias.BaseUrl + resource.Url; | ||||
|             headcontent += CreateLink(url, resource.Integrity, resource.CrossOrigin) + "\n"; | ||||
|             headcontent += "<link rel=\"stylesheet\" href=\"" + url + "\"" + (!string.IsNullOrEmpty(resource.Integrity) ? " integrity=\"" + resource.Integrity + "\"" : "") + (!string.IsNullOrEmpty(resource.CrossOrigin) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") + " type=\"text/css\"/>" + "\n"; | ||||
|         } | ||||
|         // head content | ||||
|         AddHeadContent(headcontent, PageState.Site.HeadContent); | ||||
|         if (!string.IsNullOrEmpty(PageState.Site.HeadContent)) | ||||
|         { | ||||
|             headcontent += PageState.Site.HeadContent + "\n"; | ||||
|             headcontent = AddHeadContent(headcontent, PageState.Site.HeadContent); | ||||
|         } | ||||
|         if (!string.IsNullOrEmpty(PageState.Page.HeadContent)) | ||||
|         { | ||||
|             headcontent += PageState.Page.HeadContent + "\n"; | ||||
|             headcontent = AddHeadContent(headcontent, PageState.Page.HeadContent); | ||||
|         } | ||||
|         SiteState.Properties.HeadContent = headcontent; | ||||
|  | ||||
| @ -63,9 +64,21 @@ | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     private string CreateLink(string url, string integrity, string crossorigin) | ||||
|     private string AddHeadContent(string headcontent, string content) | ||||
|     { | ||||
|         return "<link rel=\"stylesheet\" href=\"" + url + "\"" + (!string.IsNullOrEmpty(integrity) ? " integrity=\"" + integrity + "\"" : "") + (!string.IsNullOrEmpty(crossorigin) ? " crossorigin=\"" + crossorigin + "\"" : "") + " type=\"text/css\"/>"; | ||||
|         // format head content, remove scripts, and filter duplicate elements | ||||
|         var elements = (">" + content.Replace("\n", "") + "<").Split("><"); | ||||
|         foreach (var element in elements) | ||||
|         { | ||||
|             if (!string.IsNullOrEmpty(element) && !element.Contains("script")) | ||||
|             { | ||||
|                 if (!headcontent.Contains("<" + element + ">")) | ||||
|                 { | ||||
|                     headcontent += "<" + element + ">" + "\n"; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         return headcontent; | ||||
|     } | ||||
|  | ||||
|     protected override async Task OnAfterRenderAsync(bool firstRender) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 sbwalker
					sbwalker