allow HeadContent to support script tags
This commit is contained in:
parent
8d2f644177
commit
5da4dadc31
|
@ -134,7 +134,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta and link tags are valid, script tags are not)." ResourceKey="HeadContent">Head Content: </Label>
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute." ResourceKey="HeadContent">Head Content: </Label>
|
||||
<div class="col-sm-9">
|
||||
<textarea id="headcontent" class="form-control" @bind="@_headcontent" rows="3"></textarea>
|
||||
</div>
|
||||
|
|
|
@ -141,7 +141,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta and link tags are valid, script tags are not)." ResourceKey="HeadContent">Head Content: </Label>
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute." ResourceKey="HeadContent">Head Content: </Label>
|
||||
<div class="col-sm-9">
|
||||
<textarea id="headcontent" class="form-control" @bind="@_headcontent" rows="3"></textarea>
|
||||
</div>
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta and link tags are valid, script tags are not)." ResourceKey="HeadContent">Head Content: </Label>
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute." ResourceKey="HeadContent">Head Content: </Label>
|
||||
<div class="col-sm-9">
|
||||
<textarea id="headcontent" class="form-control" @bind="@_headcontent" rows="3"></textarea>
|
||||
</div>
|
||||
|
|
|
@ -229,7 +229,7 @@
|
|||
<value>Appearance</value>
|
||||
</data>
|
||||
<data name="HeadContent.HelpText" xml:space="preserve">
|
||||
<value>Optionally enter content to be included in the page head (ie. meta and link tags are valid, script tags are not).</value>
|
||||
<value>Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute.</value>
|
||||
</data>
|
||||
<data name="HeadContent.Text" xml:space="preserve">
|
||||
<value>Head Content:</value>
|
||||
|
|
|
@ -265,7 +265,7 @@
|
|||
<value>Clickable?</value>
|
||||
</data>
|
||||
<data name="HeadContent.HelpText" xml:space="preserve">
|
||||
<value>Optionally enter content to be included in the page head (ie. meta and link tags are valid, script tags are not).</value>
|
||||
<value>Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute.</value>
|
||||
</data>
|
||||
<data name="HeadContent.Text" xml:space="preserve">
|
||||
<value>Head Content:</value>
|
||||
|
|
|
@ -355,7 +355,7 @@
|
|||
<value>Appearance</value>
|
||||
</data>
|
||||
<data name="HeadContent.HelpText" xml:space="preserve">
|
||||
<value>Optionally enter content to be included in the page head (ie. meta and link tags are valid, script tags are not).</value>
|
||||
<value>Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute.</value>
|
||||
</data>
|
||||
<data name="HeadContent.Text" xml:space="preserve">
|
||||
<value>Head Content:</value>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
@namespace Oqtane.UI
|
||||
@inject IJSRuntime JsRuntime
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject SiteState SiteState
|
||||
|
||||
|
@ -41,11 +41,11 @@
|
|||
// head content
|
||||
if (!string.IsNullOrEmpty(PageState.Site.HeadContent))
|
||||
{
|
||||
headcontent += PageState.Site.HeadContent + "\n";
|
||||
headcontent += RemoveScripts(PageState.Site.HeadContent) + "\n";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(PageState.Page.HeadContent))
|
||||
{
|
||||
headcontent += PageState.Page.HeadContent + "\n";
|
||||
headcontent += RemoveScripts(PageState.Page.HeadContent) + "\n";
|
||||
}
|
||||
// stylesheets
|
||||
foreach (Resource resource in PageState.Page.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet))
|
||||
|
@ -79,6 +79,78 @@
|
|||
};
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!firstRender)
|
||||
{
|
||||
if (PageState.Page.HeadContent != null && PageState.Page.HeadContent.Contains("<script"))
|
||||
{
|
||||
var interop = new Interop(JSRuntime);
|
||||
var index = PageState.Page.HeadContent.IndexOf("<script");
|
||||
while (index >= 0)
|
||||
{
|
||||
var script = PageState.Page.HeadContent.Substring(index, PageState.Page.HeadContent.IndexOf("</script>", index) + 9 - index);
|
||||
var attributes = script.Substring(0, script.IndexOf(">")).Replace("\"", "").Split(" ");
|
||||
string id = "";
|
||||
string url = "";
|
||||
string integrity = "";
|
||||
string crossorigin = "";
|
||||
bool es6module = false;
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
if (attribute.Contains("="))
|
||||
{
|
||||
var value = attribute.Split("=");
|
||||
switch (value[0])
|
||||
{
|
||||
case "id":
|
||||
id = value[1];
|
||||
break;
|
||||
case "src":
|
||||
url = value[1];
|
||||
break;
|
||||
case "integrity":
|
||||
integrity = value[1];
|
||||
break;
|
||||
case "crossorigin":
|
||||
crossorigin = value[1];
|
||||
break;
|
||||
case "type":
|
||||
es6module = (value[1] == "module");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
url = (url.Contains("://")) ? url : PageState.Alias.BaseUrl + url;
|
||||
await interop.IncludeScript(id, url, integrity, crossorigin, "", "head");
|
||||
}
|
||||
else
|
||||
{
|
||||
index = script.IndexOf(">") + 1;
|
||||
await interop.IncludeScript(id, "", "", "", script.Substring(index, script.IndexOf("</script>") - index), "head");
|
||||
}
|
||||
index = PageState.Page.HeadContent.IndexOf("<script", index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string RemoveScripts(string headcontent)
|
||||
{
|
||||
if (headcontent != null)
|
||||
{
|
||||
var index = headcontent.IndexOf("<script");
|
||||
while (index >= 0)
|
||||
{
|
||||
headcontent = headcontent.Remove(index, headcontent.IndexOf("</script>") + 9 - index);
|
||||
index = headcontent.IndexOf("<script");
|
||||
}
|
||||
}
|
||||
return headcontent;
|
||||
}
|
||||
|
||||
private string CreateLink(string url, string integrity, string crossorigin)
|
||||
{
|
||||
return "<link rel=\"stylesheet\" href=\"" + url + "\"" + (!string.IsNullOrEmpty(integrity) ? " integrity=\"" + integrity + "\"" : "") + (!string.IsNullOrEmpty(crossorigin) ? " crossorigin=\"" + crossorigin + "\"" : "") + " type=\"text/css\"/>";
|
||||
|
|
|
@ -125,6 +125,10 @@ namespace Oqtane.Pages
|
|||
{
|
||||
ReconnectScript = CreateReconnectScript();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(site.HeadContent))
|
||||
{
|
||||
ProcessHeadContent(site.HeadContent);
|
||||
}
|
||||
var ThemeType = site.DefaultThemeType;
|
||||
|
||||
// get jwt token for downstream APIs
|
||||
|
@ -166,6 +170,8 @@ namespace Oqtane.Pages
|
|||
}
|
||||
}
|
||||
|
||||
ProcessHeadContent(page.HeadContent);
|
||||
|
||||
// include global resources
|
||||
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||
foreach (Assembly assembly in assemblies)
|
||||
|
@ -376,6 +382,20 @@ namespace Oqtane.Pages
|
|||
}
|
||||
}
|
||||
|
||||
private void ProcessHeadContent(string headcontent)
|
||||
{
|
||||
// iterate scripts
|
||||
if (headcontent != null)
|
||||
{
|
||||
var index = headcontent.IndexOf("<script");
|
||||
while (index >= 0)
|
||||
{
|
||||
HeadResources += headcontent.Substring(index, headcontent.IndexOf("</script>", index) + 9 - index) + Environment.NewLine;
|
||||
index = headcontent.IndexOf("<script", index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessResource(Resource resource, int count, Alias alias)
|
||||
{
|
||||
var url = (resource.Url.Contains("://")) ? resource.Url : alias.BaseUrl + resource.Url;
|
||||
|
|
Loading…
Reference in New Issue
Block a user