add support for data-reload=false attribute in Interactive rendering

This commit is contained in:
sbwalker 2024-12-19 13:04:43 -05:00
parent af821dcd9a
commit b5a1b529ab
2 changed files with 16 additions and 25 deletions

View File

@ -92,6 +92,14 @@
{
if (!firstRender)
{
if (!string.IsNullOrEmpty(PageState.Site.HeadContent) && PageState.Site.HeadContent.Contains("<script"))
{
await InjectScripts(PageState.Site.HeadContent, ResourceLocation.Head);
}
if (!string.IsNullOrEmpty(PageState.Site.BodyContent) && PageState.Site.BodyContent.Contains("<script"))
{
await InjectScripts(PageState.Site.BodyContent, ResourceLocation.Body);
}
if (!string.IsNullOrEmpty(PageState.Page.HeadContent) && PageState.Page.HeadContent.Contains("<script"))
{
await InjectScripts(PageState.Page.HeadContent, ResourceLocation.Head);
@ -180,7 +188,8 @@
}
else
{
// inline script must have an id attribute
if (dataAttributes == null || !dataAttributes.ContainsKey("data-reload") || dataAttributes["data-reload"] != "false")
{
if (id == "")
{
count += 1;
@ -189,6 +198,7 @@
var pos = script.IndexOf(">") + 1;
await interop.IncludeScript(id, "", "", "", type, script.Substring(pos, script.IndexOf("</script>") - pos), location.ToString().ToLower(), dataAttributes);
}
}
index = content.IndexOf("<script", index + 1);
}
if (scripts.Any())

View File

@ -192,9 +192,6 @@
_scripts += CreateScrollPositionScript();
}
_headResources += ParseScripts(site.HeadContent);
_bodyResources += ParseScripts(site.BodyContent);
// set culture if not specified
string cultureCookie = Context.Request.Cookies[Shared.CookieRequestCultureProvider.DefaultCookieName];
if (cultureCookie == null)
@ -514,22 +511,6 @@
"</script>" + Environment.NewLine;
}
private string ParseScripts(string content)
{
var scripts = "";
// in interactive render mode, parse scripts from content and inject into page
if (_renderMode == RenderModes.Interactive && !string.IsNullOrEmpty(content))
{
var index = content.IndexOf("<script");
while (index >= 0)
{
scripts += content.Substring(index, content.IndexOf("</script>", index) + 9 - index);
index = content.IndexOf("<script", index + 1);
}
}
return scripts;
}
private void AddScript(Resource resource, Alias alias)
{
var script = CreateScript(resource, alias);