Merge pull request #5997 from sbwalker/dev

fix #5988 - add inline script support to static rendering
This commit is contained in:
Shaun Walker
2026-01-30 09:01:14 -05:00
committed by GitHub
7 changed files with 27 additions and 51 deletions

View File

@@ -625,11 +625,11 @@
{ {
if (resource.ResourceType == ResourceType.Stylesheet || resource.Level != ResourceLevel.Site) if (resource.ResourceType == ResourceType.Stylesheet || resource.Level != ResourceLevel.Site)
{ {
if (resource.Url.StartsWith("~")) if (!string.IsNullOrEmpty(resource.Url) && resource.Url.StartsWith("~"))
{ {
resource.Url = resource.Url.Replace("~", "/" + type + "/" + name + "/").Replace("//", "/"); resource.Url = resource.Url.Replace("~", "/" + type + "/" + name + "/").Replace("//", "/");
} }
if (!resource.Url.Contains("://") && alias.BaseUrl != "" && !resource.Url.StartsWith(alias.BaseUrl)) if (!string.IsNullOrEmpty(resource.Url) && !resource.Url.Contains("://") && alias.BaseUrl != "" && !resource.Url.StartsWith(alias.BaseUrl))
{ {
resource.Url = alias.BaseUrl + resource.Url; resource.Url = alias.BaseUrl + resource.Url;
} }

View File

@@ -227,38 +227,4 @@
} }
return stylesheets; return stylesheets;
} }
private string ManageScripts(List<Resource> resources, Alias alias)
{
var scripts = "";
if (resources != null)
{
foreach (var resource in resources.Where(item => item.ResourceType == ResourceType.Script && item.Location == ResourceLocation.Head))
{
var script = CreateScript(resource, alias);
if (!scripts.Contains(script, StringComparison.OrdinalIgnoreCase))
{
scripts += script + Environment.NewLine;
}
}
}
return scripts;
}
private string CreateScript(Resource resource, Alias alias)
{
if (!string.IsNullOrEmpty(resource.Url))
{
var url = (resource.Url.Contains("://")) ? resource.Url : alias.BaseUrl + resource.Url;
return "<script src=\"" + url + "\"" +
((!string.IsNullOrEmpty(resource.Integrity)) ? " integrity=\"" + resource.Integrity + "\"" : "") +
((!string.IsNullOrEmpty(resource.CrossOrigin)) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") +
"></script>";
}
else
{
// inline script
return "<script>" + resource.Content + "</script>";
}
}
} }

View File

@@ -543,8 +543,6 @@
} }
else else
{ {
var url = (resource.Url.Contains("://")) ? resource.Url : alias.BaseUrl + resource.Url;
var dataAttributes = ""; var dataAttributes = "";
if (!resource.DataAttributes.ContainsKey("data-reload")) if (!resource.DataAttributes.ContainsKey("data-reload"))
{ {
@@ -566,12 +564,24 @@
} }
} }
return "<script src=\"" + url + "\"" + if (!string.IsNullOrEmpty(resource.Url))
((!string.IsNullOrEmpty(resource.Type)) ? " type=\"" + resource.Type + "\"" : "") + {
((!string.IsNullOrEmpty(resource.Integrity)) ? " integrity=\"" + resource.Integrity + "\"" : "") + var url = (string.IsNullOrEmpty(resource.Url) || resource.Url.Contains("://")) ? resource.Url : alias.BaseUrl + resource.Url;
((!string.IsNullOrEmpty(resource.CrossOrigin)) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") +
((!string.IsNullOrEmpty(dataAttributes)) ? dataAttributes : "") + return "<script src=\"" + url + "\"" +
"></script>"; ((!string.IsNullOrEmpty(resource.Type)) ? " type=\"" + resource.Type + "\"" : "") +
((!string.IsNullOrEmpty(resource.Integrity)) ? " integrity=\"" + resource.Integrity + "\"" : "") +
((!string.IsNullOrEmpty(resource.CrossOrigin)) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") +
((!string.IsNullOrEmpty(dataAttributes)) ? dataAttributes : "") +
"></script>";
}
else
{
return "<script" +
((!string.IsNullOrEmpty(resource.Type)) ? " type=\"" + resource.Type + "\"" : "") +
((!string.IsNullOrEmpty(dataAttributes)) ? dataAttributes : "") +
">" + resource.Content + "</script>";
}
} }
} }
@@ -744,11 +754,11 @@
{ {
if (rendermode == RenderModes.Static || resource.ResourceType == ResourceType.Stylesheet || resource.Level == ResourceLevel.Site) if (rendermode == RenderModes.Static || resource.ResourceType == ResourceType.Stylesheet || resource.Level == ResourceLevel.Site)
{ {
if (resource.Url.StartsWith("~")) if (!string.IsNullOrEmpty(resource.Url) && resource.Url.StartsWith("~"))
{ {
resource.Url = resource.Url.Replace("~", "/" + type + "/" + name + "/").Replace("//", "/"); resource.Url = resource.Url.Replace("~", "/" + type + "/" + name + "/").Replace("//", "/");
} }
if (!resource.Url.Contains("://") && alias.BaseUrl != "" && !resource.Url.StartsWith(alias.BaseUrl)) if (!string.IsNullOrEmpty(resource.Url) && !resource.Url.Contains("://") && alias.BaseUrl != "" && !resource.Url.StartsWith(alias.BaseUrl))
{ {
resource.Url = alias.BaseUrl + resource.Url; resource.Url = alias.BaseUrl + resource.Url;
} }

View File

@@ -364,7 +364,7 @@ namespace Oqtane.Repository
{ {
foreach (var resource in moduledefinition.Resources) foreach (var resource in moduledefinition.Resources)
{ {
if (resource.Url.StartsWith("~")) if (!string.IsNullOrEmpty(resource.Url) && resource.Url.StartsWith("~"))
{ {
resource.Url = resource.Url.Replace("~", "/Modules/" + Utilities.GetTypeName(moduledefinition.ModuleDefinitionName) + "/").Replace("//", "/"); resource.Url = resource.Url.Replace("~", "/Modules/" + Utilities.GetTypeName(moduledefinition.ModuleDefinitionName) + "/").Replace("//", "/");
} }

View File

@@ -329,7 +329,7 @@ namespace Oqtane.Repository
{ {
foreach (var resource in theme.Resources) foreach (var resource in theme.Resources)
{ {
if (resource.Url.StartsWith("~")) if (!string.IsNullOrEmpty(resource.Url) && resource.Url.StartsWith("~"))
{ {
resource.Url = resource.Url.Replace("~", "/Themes/" + Utilities.GetTypeName(theme.ThemeName) + "/").Replace("//", "/"); resource.Url = resource.Url.Replace("~", "/Themes/" + Utilities.GetTypeName(theme.ThemeName) + "/").Replace("//", "/");
} }

View File

@@ -24,7 +24,7 @@ namespace Oqtane.Models
get => _url; get => _url;
set set
{ {
_url = (value.Contains("://")) ? value : (!value.StartsWith("/") && !value.StartsWith("~") ? "/" : "") + value; _url = (string.IsNullOrEmpty(value) || value.Contains("://")) ? value : (!value.StartsWith("/") && !value.StartsWith("~") ? "/" : "") + value;
} }
} }

View File

@@ -501,11 +501,11 @@ namespace Oqtane.Shared
public static string GetUrlPath(string url) public static string GetUrlPath(string url)
{ {
if (url.Contains("?")) if (!string.IsNullOrEmpty(url) && url.Contains("?"))
{ {
url = url.Substring(0, url.IndexOf("?")); url = url.Substring(0, url.IndexOf("?"));
} }
return url; return url ?? "";
} }
public static string LogMessage(object @class, string message) public static string LogMessage(object @class, string message)