Merge pull request #5997 from sbwalker/dev
fix #5988 - add inline script support to static rendering
This commit is contained in:
@@ -625,11 +625,11 @@
|
||||
{
|
||||
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("//", "/");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -227,38 +227,4 @@
|
||||
}
|
||||
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>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,8 +543,6 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
var url = (resource.Url.Contains("://")) ? resource.Url : alias.BaseUrl + resource.Url;
|
||||
|
||||
var dataAttributes = "";
|
||||
if (!resource.DataAttributes.ContainsKey("data-reload"))
|
||||
{
|
||||
@@ -566,12 +564,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
return "<script src=\"" + url + "\"" +
|
||||
((!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>";
|
||||
if (!string.IsNullOrEmpty(resource.Url))
|
||||
{
|
||||
var url = (string.IsNullOrEmpty(resource.Url) || resource.Url.Contains("://")) ? resource.Url : alias.BaseUrl + resource.Url;
|
||||
|
||||
return "<script src=\"" + url + "\"" +
|
||||
((!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 (resource.Url.StartsWith("~"))
|
||||
if (!string.IsNullOrEmpty(resource.Url) && resource.Url.StartsWith("~"))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -364,7 +364,7 @@ namespace Oqtane.Repository
|
||||
{
|
||||
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("//", "/");
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ namespace Oqtane.Repository
|
||||
{
|
||||
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("//", "/");
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Oqtane.Models
|
||||
get => _url;
|
||||
set
|
||||
{
|
||||
_url = (value.Contains("://")) ? value : (!value.StartsWith("/") && !value.StartsWith("~") ? "/" : "") + value;
|
||||
_url = (string.IsNullOrEmpty(value) || value.Contains("://")) ? value : (!value.StartsWith("/") && !value.StartsWith("~") ? "/" : "") + value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -501,11 +501,11 @@ namespace Oqtane.Shared
|
||||
|
||||
public static string GetUrlPath(string url)
|
||||
{
|
||||
if (url.Contains("?"))
|
||||
if (!string.IsNullOrEmpty(url) && url.Contains("?"))
|
||||
{
|
||||
url = url.Substring(0, url.IndexOf("?"));
|
||||
}
|
||||
return url;
|
||||
return url ?? "";
|
||||
}
|
||||
|
||||
public static string LogMessage(object @class, string message)
|
||||
|
||||
Reference in New Issue
Block a user