diff --git a/Oqtane.Client/Body.razor b/Oqtane.Client/Body.razor deleted file mode 100644 index 8f28ce95..00000000 --- a/Oqtane.Client/Body.razor +++ /dev/null @@ -1,33 +0,0 @@ -@using System.ComponentModel -@using Oqtane.Shared -@inject SiteState SiteState - -@((MarkupString)content) - -@code { - private string content = ""; - - protected override void OnInitialized() - { - ((INotifyPropertyChanged)SiteState.Properties).PropertyChanged += PropertyChanged; - } - - private void PropertyChanged(object sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case "BodyContent": - if (content != SiteState.Properties.BodyContent) - { - content = SiteState.Properties.BodyContent; - StateHasChanged(); - } - break; - } - } - - public void Dispose() - { - ((INotifyPropertyChanged)SiteState.Properties).PropertyChanged -= PropertyChanged; - } -} \ No newline at end of file diff --git a/Oqtane.Client/Head.razor b/Oqtane.Client/Head.razor index edc2da06..28e2455d 100644 --- a/Oqtane.Client/Head.razor +++ b/Oqtane.Client/Head.razor @@ -19,22 +19,30 @@ switch (e.PropertyName) { case "PageTitle": - if (title != SiteState.Properties.PageTitle) - { - title = "\n" + SiteState.Properties.PageTitle + ""; - StateHasChanged(); - } + title = "\n" + SiteState.Properties.PageTitle + ""; + 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("= 0) + { + headcontent = headcontent.Remove(index, headcontent.IndexOf("") + 9 - index); + index = headcontent.IndexOf(" item.ResourceType == ResourceType.Stylesheet)) @@ -55,13 +55,6 @@ } SiteState.Properties.HeadContent = headcontent; - // set page body content - var bodycontent = ""; - if (bodycontent != "") - { - SiteState.Properties.BodyContent = bodycontent; - } - DynamicComponent = builder => { var themeType = Type.GetType(PageState.Page.ThemeType); @@ -72,77 +65,84 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { - if (!firstRender) + if (!string.IsNullOrEmpty(PageState.Page.HeadContent) && PageState.Page.HeadContent.Contains("= 0) { - var interop = new Interop(JSRuntime); - var count = 0; - var index = PageState.Page.HeadContent.IndexOf("= 0) + var script = PageState.Page.HeadContent.Substring(index, PageState.Page.HeadContent.IndexOf("", index) + 9 - index); + var attributes = script.Substring(0, script.IndexOf(">")).Replace("\"", "").Split(" "); + string id = ""; + string src = ""; + string integrity = ""; + string crossorigin = ""; + string type = ""; + foreach (var attribute in attributes) { - var script = PageState.Page.HeadContent.Substring(index, PageState.Page.HeadContent.IndexOf("", index) + 9 - index); - var attributes = script.Substring(0, script.IndexOf(">")).Replace("\"", "").Split(" "); - string id = ""; - string src = ""; - string integrity = ""; - string crossorigin = ""; - string type = ""; - foreach (var attribute in attributes) + if (attribute.Contains("=")) { - if (attribute.Contains("=")) + var value = attribute.Split("="); + switch (value[0]) { - var value = attribute.Split("="); - switch (value[0]) - { - case "id": - id = value[1]; - break; - case "src": - src = value[1]; - break; - case "integrity": - integrity = value[1]; - break; - case "crossorigin": - crossorigin = value[1]; - break; - case "type": - type = value[1]; - break; - } + case "id": + id = value[1]; + break; + case "src": + src = value[1]; + break; + case "integrity": + integrity = value[1]; + break; + case "crossorigin": + crossorigin = value[1]; + break; + case "type": + type = value[1]; + break; } } - if (!string.IsNullOrEmpty(src)) - { - src = (src.Contains("://")) ? src : PageState.Alias.BaseUrl + src; - await interop.IncludeScript(id, src, integrity, crossorigin, type, "", "head"); - } - else - { - if (id == "") - { - count += 1; - id = $"page{PageState.Page.PageId}-script{count}"; - } - index = script.IndexOf(">") + 1; - await interop.IncludeScript(id, "", "", "", script.Substring(index, script.IndexOf("") - index), "head"); - } - index = PageState.Page.HeadContent.IndexOf("") + 1; + await interop.IncludeScript(id, "", "", "", "", script.Substring(index, script.IndexOf("") - index), "head"); + } + index = PageState.Page.HeadContent.IndexOf("= 0) { - headcontent = headcontent.Remove(index, headcontent.IndexOf("") + 9 - index); - index = headcontent.IndexOf("", index) + 9 - index); + if (!script.Contains("src=") && !script.Contains("id=")) + { + count += 1; + id += $"-script{count}"; + headcontent = headcontent.Replace(script, script.Replace(" } else { diff --git a/Oqtane.Server/Pages/_Host.cshtml.cs b/Oqtane.Server/Pages/_Host.cshtml.cs index 7acc8ca6..50bd0fef 100644 --- a/Oqtane.Server/Pages/_Host.cshtml.cs +++ b/Oqtane.Server/Pages/_Host.cshtml.cs @@ -430,8 +430,8 @@ namespace Oqtane.Pages private void ProcessHeadContent(string headcontent, string id) { - // iterate scripts - if (headcontent != null) + // add scripts to page + if (!string.IsNullOrEmpty(headcontent)) { var count = 0; var index = headcontent.IndexOf("