optimize JavaScript handling

This commit is contained in:
sbwalker
2023-05-18 14:36:06 -04:00
parent 076d150f72
commit 0b8086bd36
7 changed files with 84 additions and 123 deletions

View File

@ -19,22 +19,30 @@
switch (e.PropertyName)
{
case "PageTitle":
if (title != SiteState.Properties.PageTitle)
{
title = "\n<title>" + SiteState.Properties.PageTitle + "</title>";
StateHasChanged();
}
title = "\n<title>" + SiteState.Properties.PageTitle + "</title>";
StateHasChanged();
break;
case "HeadContent":
if (content != SiteState.Properties.HeadContent)
{
content = SiteState.Properties.HeadContent + "\n";
StateHasChanged();
}
content = RemoveScripts(SiteState.Properties.HeadContent) + "\n";
StateHasChanged();
break;
}
}
private string RemoveScripts(string headcontent)
{
if (!string.IsNullOrEmpty(headcontent))
{
var index = headcontent.IndexOf("<script");
while (index >= 0)
{
headcontent = headcontent.Remove(index, headcontent.IndexOf("</script>") + 9 - index);
index = headcontent.IndexOf("<script");
}
}
return headcontent;
}
public void Dispose()
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged -= PropertyChanged;