Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support specifying RenderMode for Resources #3933

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Oqtane.Client/Modules/ModuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,18 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
var inline = 0;
foreach (Resource resource in resources)
{
if (!string.IsNullOrEmpty(resource.Url))
if (string.IsNullOrEmpty(resource.RenderMode) || resource.RenderMode == RenderModes.Interactive)
{
var url = (resource.Url.Contains("://")) ? resource.Url : PageState.Alias.BaseUrl + resource.Url;
scripts.Add(new { href = url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", es6module = resource.ES6Module, location = resource.Location.ToString().ToLower() });
}
else
{
inline += 1;
await interop.IncludeScript(GetType().Namespace.ToLower() + inline.ToString(), "", "", "", resource.Content, resource.Location.ToString().ToLower());
if (!string.IsNullOrEmpty(resource.Url))
{
var url = (resource.Url.Contains("://")) ? resource.Url : PageState.Alias.BaseUrl + resource.Url;
scripts.Add(new { href = url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", es6module = resource.ES6Module, location = resource.Location.ToString().ToLower() });
}
else
{
inline += 1;
await interop.IncludeScript(GetType().Namespace.ToLower() + inline.ToString(), "", "", "", resource.Content, resource.Location.ToString().ToLower());
}
}
}
if (scripts.Any())
Expand Down
19 changes: 11 additions & 8 deletions Oqtane.Client/Themes/ThemeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
var inline = 0;
foreach (Resource resource in resources)
{
if (!string.IsNullOrEmpty(resource.Url))
if (string.IsNullOrEmpty(resource.RenderMode) || resource.RenderMode == RenderModes.Interactive)
{
var url = (resource.Url.Contains("://")) ? resource.Url : PageState.Alias.BaseUrl + resource.Url;
scripts.Add(new { href = url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", es6module = resource.ES6Module, location = resource.Location.ToString().ToLower() });
}
else
{
inline += 1;
await interop.IncludeScript(GetType().Namespace.ToLower() + inline.ToString(), "", "", "", resource.Content, resource.Location.ToString().ToLower());
if (!string.IsNullOrEmpty(resource.Url))
{
var url = (resource.Url.Contains("://")) ? resource.Url : PageState.Alias.BaseUrl + resource.Url;
scripts.Add(new { href = url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", es6module = resource.ES6Module, location = resource.Location.ToString().ToLower() });
}
else
{
inline += 1;
await interop.IncludeScript(GetType().Namespace.ToLower() + inline.ToString(), "", "", "", resource.Content, resource.Location.ToString().ToLower());
}
}
}
if (scripts.Any())
Expand Down
1 change: 1 addition & 0 deletions Oqtane.Client/UI/SiteRouter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@
Location = resource.Location,
ES6Module = resource.ES6Module,
Content = resource.Content,
RenderMode = resource.RenderMode,
Level = level,
Namespace = name
});
Expand Down
16 changes: 12 additions & 4 deletions Oqtane.Server/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,11 @@
if (!string.IsNullOrEmpty(resource.Url))
{
var url = (resource.Url.Contains("://")) ? resource.Url : alias.BaseUrl + resource.Url;
return "<script src=\"" + url + "\"" +
return "<script" +
((!string.IsNullOrEmpty(resource.Integrity)) ? " integrity=\"" + resource.Integrity + "\"" : "") +
((!string.IsNullOrEmpty(resource.CrossOrigin)) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") +
"></script>";
((resource.ES6Module) ? " type=\"module\"" : "") +
" src =\"" + url + "\"></script>"; // src at end of element due to enhanced navigation patch algorithm
}
else
{
Expand Down Expand Up @@ -647,6 +648,7 @@
Location = resource.Location,
ES6Module = resource.ES6Module,
Content = resource.Content,
RenderMode = resource.RenderMode,
Level = level,
Namespace = name
});
Expand All @@ -666,7 +668,10 @@
{
count++;
string id = "id=\"app-stylesheet-" + ResourceLevel.Page.ToString().ToLower() + "-" + batch + "-" + count.ToString("00") + "\" ";
_styleSheets += "<link " + id + "rel=\"stylesheet\"" + (!string.IsNullOrEmpty(resource.Integrity) ? " integrity=\"" + resource.Integrity + "\"" : "") + (!string.IsNullOrEmpty(resource.CrossOrigin) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") + " href=\"" + resource.Url + "\" type=\"text/css\"/>" + Environment.NewLine;
_styleSheets += "<link " + id + "rel=\"stylesheet\"" +
(!string.IsNullOrEmpty(resource.Integrity) ? " integrity=\"" + resource.Integrity + "\"" : "") +
(!string.IsNullOrEmpty(resource.CrossOrigin) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") +
" href=\"" + resource.Url + "\" type=\"text/css\"/>" + Environment.NewLine; // href at end of element due to enhanced navigation patch algorithm
}
}
}
Expand All @@ -677,7 +682,10 @@
{
foreach (var resource in resources.Where(item => item.ResourceType == ResourceType.Script))
{
AddScript(resource, alias);
if (string.IsNullOrEmpty(resource.RenderMode) || resource.RenderMode == RenderModes.Static)
{
AddScript(resource, alias);
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Oqtane.Shared/Models/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public string Url
/// </summary>
public string Content { get; set; }

/// <summary>
/// For Scripts this defines the render mode (default is all render modes) - not applicable to Stylesheets
/// </summary>
public string RenderMode { get; set; }

/// <summary>
/// The namespace of the component that declared the resource - only used in SiteRouter
/// </summary>
Expand Down