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

Allow running sustainability check on headless sites #32

Open
wants to merge 1 commit into
base: v1/dev
Choose a base branch
from
Open
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
Allow running the sustainability check on headless sites, where `Umbr…
…acoApplicationUrl` may be different to the frontend URL
rickbutterfield committed Feb 8, 2024
commit 9c970e4e36909d3f66a405eedf77db4158938688
Original file line number Diff line number Diff line change
@@ -12,12 +12,6 @@ public class SustainabilityContentApp : IContentAppFactory
if (!(source is IContent))
return null;

var content = (IContent)source;

// Only show app on content items with template
if (content.TemplateId is null)
return null;

return new ContentApp
{
Alias = "sustainabilityCheck",
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Reflection;
using System.Text.Json;
using Microsoft.Extensions.Options;
using Microsoft.Playwright;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Community.Sustainability.Models;

namespace Umbraco.Community.Sustainability.Services
@@ -12,6 +14,13 @@ public interface ISustainabilityService

public class SustainabilityService : ISustainabilityService
{
private readonly WebRoutingSettings _webRoutingSettings;

public SustainabilityService(IOptionsMonitor<WebRoutingSettings> webRoutingSettings)
{
_webRoutingSettings = webRoutingSettings.CurrentValue;
}

public async Task<SustainabilityResponse> GetSustainabilityData(string url)
{
using var playwright = await Playwright.CreateAsync();
@@ -25,7 +34,7 @@ public async Task<SustainabilityResponse> GetSustainabilityData(string url)
// Add our script to report data
await page.AddScriptTagAsync(new PageAddScriptTagOptions()
{
Url = "/App_Plugins/Umbraco.Community.Sustainability/js/resource-checker.js",
Url = $"{_webRoutingSettings.UmbracoApplicationUrl}/App_Plugins/Umbraco.Community.Sustainability/js/resource-checker.js",
Type = "module"
});