Skip to content

Commit dd1862a

Browse files
Merge pull request #2 from rickbutterfield/feature/playwright-test
2 parents df51db0 + 3de9f2b commit dd1862a

File tree

50 files changed

+4244
-543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4244
-543
lines changed

src/Umbraco.Community.Sustainability.TestSite/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,4 @@ appsettings-schema.json
479479

480480
# Test Site App_Plugins packages folder (exclude here as in Umbraco.Community.Sustainability project)
481481
/App_Plugins/Umbraco.Community.Sustainability/
482+
/App_Plugins/Bergmania.OpenStreetMap/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { co2, hosting } from 'https://cdn.skypack.dev/@tgwf/co2';
2+
3+
window.addEventListener('load', scrollPage);
4+
5+
export function scrollPage() {
6+
window.scrollTo({
7+
top: document.body.scrollHeight,
8+
behavior: 'smooth'
9+
});
10+
11+
setTimeout(reportEmissions, 2000);
12+
}
13+
14+
export async function reportEmissions() {
15+
const emissionsData = await getEmissionsData();
16+
17+
const emissionsDiv = document.createElement("div");
18+
emissionsDiv.setAttribute("data-testid", "sustainabilityData");
19+
emissionsDiv.innerHTML = JSON.stringify(emissionsData);
20+
21+
document.body.appendChild(emissionsDiv);
22+
}
23+
24+
export async function getEmissionsData() {
25+
26+
const resources = getResources();
27+
const bytesSent = getTransferSize(resources);
28+
const hostCheck = await hosting.check(window.location.hostname);
29+
30+
const co2Emission = new co2({ model: "swd" });
31+
const emissions = co2Emission.perVisitTrace(bytesSent, hostCheck);
32+
33+
return {
34+
pageWeight: bytesSent,
35+
carbonRating: calculateGrade(emissions.co2),
36+
emissions: emissions,
37+
resources: resources
38+
};
39+
}
40+
41+
export function getResources() {
42+
return window.performance.getEntriesByType("resource");
43+
}
44+
45+
export function filterResourceByType(resources, entryType) {
46+
return resources.filter(
47+
(entry) => entry.initiatorType === entryType,
48+
);
49+
}
50+
51+
export function getTransferSize(resources) {
52+
let bytesSent = 0;
53+
resources.forEach((entry) => {
54+
bytesSent += entry.transferSize;
55+
});
56+
57+
return bytesSent;
58+
}
59+
60+
export function calculateGrade(score) {
61+
// grade using swd digital carbon ratings
62+
// https://sustainablewebdesign.org/digital-carbon-ratings/
63+
if (score < 0.095) {
64+
return 'A+';
65+
} else if (score < 0.186) {
66+
return 'A';
67+
} else if (score < 0.341) {
68+
return 'B';
69+
} else if (score < 0.493) {
70+
return 'C';
71+
} else if (score < 0.656) {
72+
return 'D';
73+
} else if (score < 0.846) {
74+
return 'E';
75+
} else {
76+
return 'F';
77+
}
78+
}

src/Umbraco.Community.Sustainability.TestSite/Umbraco.Community.Sustainability.TestSite.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
</PropertyGroup>
7-
<ItemGroup>
8-
<Content Include="App_Plugins\Umbraco.Community.Sustainability\js\page-tracker.js">
9-
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
10-
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
11-
</Content>
12-
</ItemGroup>
137

148
<ItemGroup>
159
<PackageReference Include="Umbraco.Cms" Version="10.0.0" />
10+
<PackageReference Include="Umbraco.TheStarterKit" Version="10.0.0" />
1611
</ItemGroup>
1712

1813
<ItemGroup>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels
2+
3+
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.Blog>
4+
5+
@{
6+
Layout = "master.cshtml";
7+
}
8+
@Html.Partial("~/Views/Partials/SectionHeader.cshtml")
9+
10+
<section class="section">
11+
12+
<div class="container">
13+
@await Umbraco.RenderMacroAsync("latestBlogposts",
14+
new
15+
{
16+
numberOfPosts = Model.HowManyPostsShouldBeShown,
17+
startNodeId = Model.Id
18+
})
19+
</div>
20+
21+
</section>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels
2+
@using Microsoft.AspNetCore.Mvc.Rendering
3+
@using Umbraco.Extensions
4+
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.Blogpost>
5+
@{
6+
Layout = "master.cshtml";
7+
}
8+
@Html.Partial("~/Views/Partials/SectionHeader.cshtml")
9+
10+
<section class="section">
11+
<div class="container">
12+
<article>
13+
<div class="blogpost-meta">
14+
<small class="blogpost-date">@Model.CreateDate.ToShortDateString()</small>
15+
<span class="blogpost-cat">
16+
@Html.Partial("~/Views/Partials/CategoryLinks.cshtml", Model.Categories)
17+
</span>
18+
</div>
19+
<h3>@Model.Excerpt</h3>
20+
@Html.GetGridHtml(Model, "bodyText", "bootstrap3-fluid")
21+
<!-- todo: implement discus comments -->
22+
</article>
23+
</div>
24+
</section>

0 commit comments

Comments
 (0)