Skip to content

Commit 5540e25

Browse files
Fix SustainabilityService to point to live URL for resource-checker.js
1 parent 4d678a9 commit 5540e25

File tree

10 files changed

+323
-44
lines changed

10 files changed

+323
-44
lines changed

.gitignore

Lines changed: 296 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,299 @@ MigrationBackup/
353353
.ionide/
354354

355355
# Rider
356-
src/.idea
356+
src/.idea
357+
358+
## Ignore Visual Studio temporary files, build results, and
359+
## files generated by popular Visual Studio add-ons.
360+
##
361+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
362+
363+
# User-specific files
364+
*.suo
365+
*.user
366+
*.userosscache
367+
*.sln.docstates
368+
*.vcxproj.filters
369+
370+
# User-specific files (MonoDevelop/Xamarin Studio)
371+
*.userprefs
372+
373+
# Build results
374+
[Dd]ebug/
375+
[Dd]ebugPublic/
376+
[Rr]elease/
377+
[Rr]eleases/
378+
x64/
379+
x86/
380+
bld/
381+
[Bb]in/
382+
[Oo]bj/
383+
[Ll]og/
384+
385+
# Visual Studio 2015 cache/options directory
386+
.vs/
387+
# Uncomment if you have tasks that create the project's static files in wwwroot
388+
#wwwroot/
389+
390+
# MSTest test Results
391+
[Tt]est[Rr]esult*/
392+
[Bb]uild[Ll]og.*
393+
394+
# NUNIT
395+
*.VisualState.xml
396+
TestResult.xml
397+
398+
# Build Results of an ATL Project
399+
[Dd]ebugPS/
400+
[Rr]eleasePS/
401+
dlldata.c
402+
403+
# DNX
404+
project.lock.json
405+
project.fragment.lock.json
406+
artifacts/
407+
**/Properties/launchSettings.json
408+
409+
*_i.c
410+
*_p.c
411+
*_i.h
412+
*.ilk
413+
*.meta
414+
*.obj
415+
*.pch
416+
*.pdb
417+
*.pgc
418+
*.pgd
419+
*.rsp
420+
*.sbr
421+
*.tlb
422+
*.tli
423+
*.tlh
424+
*.tmp
425+
*.tmp_proj
426+
*.log
427+
*.vspscc
428+
*.vssscc
429+
.builds
430+
*.pidb
431+
*.svclog
432+
*.scc
433+
434+
# Chutzpah Test files
435+
_Chutzpah*
436+
437+
# Visual C++ cache files
438+
ipch/
439+
*.aps
440+
*.ncb
441+
*.opendb
442+
*.opensdf
443+
*.sdf
444+
*.cachefile
445+
*.VC.db
446+
*.VC.VC.opendb
447+
448+
# Visual Studio profiler
449+
*.psess
450+
*.vsp
451+
*.vspx
452+
*.sap
453+
454+
# TFS 2012 Local Workspace
455+
$tf/
456+
457+
# Guidance Automation Toolkit
458+
*.gpState
459+
460+
# ReSharper is a .NET coding add-in
461+
_ReSharper*/
462+
*.[Rr]e[Ss]harper
463+
*.DotSettings.user
464+
465+
# JustCode is a .NET coding add-in
466+
.JustCode
467+
468+
# TeamCity is a build add-in
469+
_TeamCity*
470+
471+
# DotCover is a Code Coverage Tool
472+
*.dotCover
473+
474+
# Visual Studio code coverage results
475+
*.coverage
476+
*.coveragexml
477+
478+
# NCrunch
479+
_NCrunch_*
480+
.*crunch*.local.xml
481+
nCrunchTemp_*
482+
483+
# MightyMoose
484+
*.mm.*
485+
AutoTest.Net/
486+
487+
# Web workbench (sass)
488+
.sass-cache/
489+
490+
# Installshield output folder
491+
[Ee]xpress/
492+
493+
# DocProject is a documentation generator add-in
494+
DocProject/buildhelp/
495+
DocProject/Help/*.HxT
496+
DocProject/Help/*.HxC
497+
DocProject/Help/*.hhc
498+
DocProject/Help/*.hhk
499+
DocProject/Help/*.hhp
500+
DocProject/Help/Html2
501+
DocProject/Help/html
502+
503+
# Click-Once directory
504+
publish/
505+
506+
# Publish Web Output
507+
*.[Pp]ublish.xml
508+
*.azurePubxml
509+
# TODO: Comment the next line if you want to checkin your web deploy settings
510+
# but database connection strings (with potential passwords) will be unencrypted
511+
*.pubxml
512+
*.publishproj
513+
514+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
515+
# checkin your Azure Web App publish settings, but sensitive information contained
516+
# in these scripts will be unencrypted
517+
PublishScripts/
518+
519+
# NuGet Packages
520+
*.nupkg
521+
# The packages folder can be ignored because of Package Restore
522+
**/packages/*
523+
# except build/, which is used as an MSBuild target.
524+
!**/packages/build/
525+
# Uncomment if necessary however generally it will be regenerated when needed
526+
#!**/packages/repositories.config
527+
# NuGet v3's project.json files produces more ignoreable files
528+
*.nuget.props
529+
*.nuget.targets
530+
531+
# Microsoft Azure Build Output
532+
csx/
533+
*.build.csdef
534+
535+
# Microsoft Azure Emulator
536+
ecf/
537+
rcf/
538+
539+
# Windows Store app package directories and files
540+
AppPackages/
541+
BundleArtifacts/
542+
Package.StoreAssociation.xml
543+
_pkginfo.txt
544+
545+
# Visual Studio cache files
546+
# files ending in .cache can be ignored
547+
*.[Cc]ache
548+
# but keep track of directories ending in .cache
549+
!*.[Cc]ache/
550+
551+
# Others
552+
ClientBin/
553+
~$*
554+
*~
555+
*.dbmdl
556+
*.dbproj.schemaview
557+
*.jfm
558+
*.pfx
559+
*.publishsettings
560+
node_modules/
561+
orleans.codegen.cs
562+
563+
# Since there are multiple workflows, uncomment next line to ignore bower_components
564+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
565+
#bower_components/
566+
567+
# RIA/Silverlight projects
568+
Generated_Code/
569+
570+
# Backup & report files from converting an old project file
571+
# to a newer Visual Studio version. Backup files are not needed,
572+
# because we have git ;-)
573+
_UpgradeReport_Files/
574+
Backup*/
575+
UpgradeLog*.XML
576+
UpgradeLog*.htm
577+
578+
# SQL Server files
579+
*.mdf
580+
*.ldf
581+
582+
# Business Intelligence projects
583+
*.rdl.data
584+
*.bim.layout
585+
*.bim_*.settings
586+
587+
# Microsoft Fakes
588+
FakesAssemblies/
589+
590+
# GhostDoc plugin setting file
591+
*.GhostDoc.xml
592+
593+
# Node.js Tools for Visual Studio
594+
.ntvs_analysis.dat
595+
596+
# Visual Studio 6 build log
597+
*.plg
598+
599+
# Visual Studio 6 workspace options file
600+
*.opt
601+
602+
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
603+
*.vbw
604+
605+
# Visual Studio LightSwitch build output
606+
**/*.HTMLClient/GeneratedArtifacts
607+
**/*.DesktopClient/GeneratedArtifacts
608+
**/*.DesktopClient/ModelManifest.xml
609+
**/*.Server/GeneratedArtifacts
610+
**/*.Server/ModelManifest.xml
611+
_Pvt_Extensions
612+
613+
# Paket dependency manager
614+
.paket/paket.exe
615+
paket-files/
616+
617+
# FAKE - F# Make
618+
.fake/
619+
620+
# JetBrains Rider
621+
.idea/
622+
*.sln.iml
623+
624+
# CodeRush
625+
.cr/
626+
627+
# Python Tools for Visual Studio (PTVS)
628+
__pycache__/
629+
*.pyc
630+
631+
# Cake - Uncomment if you are using it
632+
# tools/
633+
634+
# Umbraco
635+
# Ignore environment-specif folders (cache, logs, etc) generated by Umbraco
636+
**/App_Data/Logs/
637+
**/App_Data/[Pp]review/
638+
**/App_Data/TEMP/
639+
**/App_Data/NuGetBackup/
640+
**/umbraco/Data/
641+
642+
# ImageProcessor Disk Cache
643+
**/App_Data/cache/
644+
645+
# Ignore Umbraco content cache
646+
**/App_Data/umbraco.config
647+
648+
# Umbraco packages should not be ignored.
649+
# Ensure VisualStudio.gitignore is included before this
650+
!**/App_Data/[Pp]ackages/
651+
!**/[Uu]mbraco/[Dd]eveloper/[Pp]ackages
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4
1+
6

src/Umbraco.Community.Sustainability/Services/SustainabilityService.cs

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,40 @@ public async Task<SustainabilityResponse> GetSustainabilityData(string url)
2222
var page = await context.NewPageAsync();
2323
await page.GotoAsync(url);
2424

25-
string? buildDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
26-
string? fullPath = Path.Combine(buildDir, "wwwroot\\Umbraco.Community.Sustainability\\js\\resource-checker.js");
27-
28-
bool fileExists = File.Exists(fullPath);
29-
30-
if (fileExists)
25+
// Add our script to report data
26+
await page.AddScriptTagAsync(new PageAddScriptTagOptions()
3127
{
32-
// Add our script to report data
33-
await page.AddScriptTagAsync(new PageAddScriptTagOptions()
34-
{
35-
Path = fullPath,
36-
Type = "module"
37-
});
38-
39-
// Retrieve data from page
40-
var data = await page.GetByTestId("sustainabilityData").TextContentAsync();
41-
var sustainabilityData = JsonSerializer.Deserialize<SustainabilityData>(data);
28+
Url = "/App_Plugins/Umbraco.Community.Sustainability/js/resource-checker.js",
29+
Type = "module"
30+
});
4231

43-
var resourceGroups = new List<ExternalResourceGroup>();
32+
// Retrieve data from page
33+
var data = await page.GetByTestId("sustainabilityData").TextContentAsync();
34+
var sustainabilityData = JsonSerializer.Deserialize<SustainabilityData>(data);
4435

45-
var scripts = GetExternalResourceGroup(ResourceGroupType.Scripts, sustainabilityData.resources);
46-
resourceGroups.Add(scripts);
36+
var resourceGroups = new List<ExternalResourceGroup>();
4737

48-
var images = GetExternalResourceGroup(ResourceGroupType.Images, sustainabilityData.resources);
49-
resourceGroups.Add(images);
38+
var scripts = GetExternalResourceGroup(ResourceGroupType.Scripts, sustainabilityData.resources);
39+
resourceGroups.Add(scripts);
5040

51-
var styles = GetExternalResourceGroup(ResourceGroupType.Styles, sustainabilityData.resources);
52-
resourceGroups.Add(styles);
41+
var images = GetExternalResourceGroup(ResourceGroupType.Images, sustainabilityData.resources);
42+
resourceGroups.Add(images);
5343

54-
var other = GetExternalResourceGroup(ResourceGroupType.Other, sustainabilityData.resources);
55-
resourceGroups.Add(other);
44+
var styles = GetExternalResourceGroup(ResourceGroupType.Styles, sustainabilityData.resources);
45+
resourceGroups.Add(styles);
5646

57-
await browser.CloseAsync();
47+
var other = GetExternalResourceGroup(ResourceGroupType.Other, sustainabilityData.resources);
48+
resourceGroups.Add(other);
5849

59-
return new SustainabilityResponse()
60-
{
61-
TotalSize = sustainabilityData.pageWeight,
62-
TotalEmissions = sustainabilityData.emissions.co2,
63-
CarbonRating = sustainabilityData.carbonRating,
64-
ResourceGroups = resourceGroups
65-
};
66-
}
50+
await browser.CloseAsync();
6751

68-
return default;
52+
return new SustainabilityResponse()
53+
{
54+
TotalSize = sustainabilityData.pageWeight,
55+
TotalEmissions = sustainabilityData.emissions.co2,
56+
CarbonRating = sustainabilityData.carbonRating,
57+
ResourceGroups = resourceGroups
58+
};
6959
}
7060

7161
private ExternalResourceGroup GetExternalResourceGroup(ResourceGroupType groupType, IList<Resource> resources)

0 commit comments

Comments
 (0)