Skip to content

Commit

Permalink
Merge pull request #33 from umbraco-community/minor-updates
Browse files Browse the repository at this point in the history
minor improvements.
  • Loading branch information
rickbutterfield authored Nov 12, 2024
2 parents ccf5877 + dd17079 commit 50e6e53
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public static string GetInitiatorType(ResourceGroupType groupType)
{
ResourceGroupType.Images => "img",
ResourceGroupType.Scripts => "script",
ResourceGroupType.Styles => "link",
ResourceGroupType.Other => "css",
ResourceGroupType.Links => "link",
ResourceGroupType.Css => "css",
ResourceGroupType.Other => "other",
_ => string.Empty,
};
}
Expand All @@ -44,8 +45,10 @@ public enum ResourceGroupType
Images,
[Display(Name = "Scripts")]
Scripts,
[Display(Name = "Styles")]
Styles,
[Display(Name = "Links")]
Links,
[Display(Name = "Css")]
Css,
[Display(Name = "Other")]
Other
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public async Task<SustainabilityResponse> GetSustainabilityData(string url)
// Create a new incognito browser context and go to web page
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();
await page.GotoAsync(url);
await page.GotoAsync(url, new PageGotoOptions()
{
WaitUntil = WaitUntilState.DOMContentLoaded
});

// Add our script to report data
await page.AddScriptTagAsync(new PageAddScriptTagOptions()
Expand All @@ -33,18 +36,11 @@ await page.AddScriptTagAsync(new PageAddScriptTagOptions()
var sustainabilityData = JsonSerializer.Deserialize<SustainabilityData>(data);

var resourceGroups = new List<ExternalResourceGroup>();

var scripts = GetExternalResourceGroup(ResourceGroupType.Scripts, sustainabilityData.resources);
resourceGroups.Add(scripts);

var images = GetExternalResourceGroup(ResourceGroupType.Images, sustainabilityData.resources);
resourceGroups.Add(images);

var styles = GetExternalResourceGroup(ResourceGroupType.Styles, sustainabilityData.resources);
resourceGroups.Add(styles);

var other = GetExternalResourceGroup(ResourceGroupType.Other, sustainabilityData.resources);
resourceGroups.Add(other);
foreach (ResourceGroupType resourceGroupType in Enum.GetValues(typeof(ResourceGroupType)))
{
var resources = GetExternalResourceGroup(resourceGroupType, sustainabilityData.resources);
resourceGroups.Add(resources);
}

await browser.CloseAsync();

Expand All @@ -60,7 +56,7 @@ await page.AddScriptTagAsync(new PageAddScriptTagOptions()
private ExternalResourceGroup GetExternalResourceGroup(ResourceGroupType groupType, IList<Resource> resources)
{
var initiator = ExternalResourceGroup.GetInitiatorType(groupType);
var resourcesByType = resources.Where(x => x.initiatorType.Equals(initiator));
var resourcesByType = resources.Where(x => x.initiatorType.Equals(initiator) && x.transferSize > 0);

var transferSize = 0;
var resourceList = new List<ExternalResource>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Fix Umbraco Colors */

.umb-sub-views-nav-item .badge.-type-warning {
background-color: #f0ac00
}

.umb-sub-views-nav-item .badge.-type-alert {
background-color: #d42054;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { co2, hosting } from 'https://cdn.skypack.dev/@tgwf/[email protected]';

scrollPage();
window.addEventListener("load", (event) => {
scrollPage();
});

export function scrollPage() {
window.scrollTo({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ angular.module('umbraco').controller('Umbraco.Sustainability.ContentApp.Controll
}

function updateBadge() {
let badgeType = "";
let badgeType = "default";
let score = $scope.sustainabilityData.totalEmissions;

if (score > 0.186 && score < 0.656) {
if (score >= 0.186 && score < 0.656) {
badgeType = "warning";
} else if (score >= 0.656) {
badgeType = "alert";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,24 @@
</uui-button>
</uui-box>

<div class="umb-box-row">
<div class="umb-box-row" style="margin-bottom: 16px;">
<uui-box headline="Page size" style="margin-left: 10px; margin-right: 10px; flex: 1;">
{{(sustainabilityData.totalSize / 1024).toFixed(2)}}KB
</uui-box>

<uui-box headline="CO₂ per page view" style="margin-left: 10px; margin-right: 10px; flex: 1;">
{{sustainabilityData.totalEmissions.toFixed(4)}}g
</uui-box>

</div>

<uui-box headline="Estimations">
<p>
This data is based on resources loaded and uses <a href="https://developers.thegreenwebfoundation.org/co2js/overview/">CO2.js</a> to
convert page weight to carbon emissions.
</p>
<p>Please use as a guideline to diagnose and highlight potential areas of improvement.</p>
</uui-box>
</div>
</div>
</div>

0 comments on commit 50e6e53

Please sign in to comment.