diff --git a/lib/plugins/sustainable/index.js b/lib/plugins/sustainable/index.js index 26a26bc79..92aa1b2ed 100644 --- a/lib/plugins/sustainable/index.js +++ b/lib/plugins/sustainable/index.js @@ -19,6 +19,7 @@ module.exports = { 'utf8' ); this.aggregator = new Aggregator(options); + this.firstRunsData = {}; context.filterRegistry.registerFilterForType( DEFAULT_METRICS_PAGE_SUMMARY, 'sustainable.pageSummary' @@ -96,6 +97,13 @@ module.exports = { ? this.sustainableOptions.pageViews * co2PerPageView : co2PerPageView; + if (message.iteration === 1) { + this.firstRunsData[message.url] = { + co2PerDomain, + hostingGreenCheck, + dirtiestResources + }; + } // We get data per run, so we want to aggregate that per page (multiple runs per page) // and per group/domain aggregator.addStats( @@ -139,6 +147,8 @@ module.exports = { // and push that info on the queue const summaries = aggregator.summarize(); for (let summary of summaries) { + const extras = this.firstRunsData[summary.url]; + summary.data.firstRun = extras; queue.postMessage( make( 'sustainable.pageSummary', diff --git a/lib/plugins/sustainable/pug/index.pug b/lib/plugins/sustainable/pug/index.pug index ed0fd5f36..c5c109f49 100644 --- a/lib/plugins/sustainable/pug/index.pug +++ b/lib/plugins/sustainable/pug/index.pug @@ -1,6 +1,6 @@ h1 Sustainable Web -- const sustainable = pageInfo.data.sustainable.run ? pageInfo.data.sustainable.run : pageInfo.data.sustainable.pageSummary +- let sustainable = pageInfo.data.sustainable.run ? pageInfo.data.sustainable.run : pageInfo.data.sustainable.pageSummary p Sending data over the wire uses electricity, and because the internet still mostly runs on fossil fuels, the more data we send, the more fossil fuels we burn, which is bad news for our climate. @@ -44,36 +44,40 @@ table td #{options.sustainable.pageViews} page views td #{(sustainable.totalCO2.median/1000) || Number(sustainable.totalCO2/1000).toFixed(3)} kg -if sustainable.co2PerDomain - h2 Per domain - table(data-sortable) - thead - tr - th Domain - th Estimated CO2 emissions - th Transfer Size - each data in sustainable.co2PerDomain - tr - td #{data.domain} - - if (sustainable.hostingGreenCheck.indexOf(data.domain) > -1) - span(class='label normal ok') green - td.number(data-value= data.co2)= data.co2 - td.number(data-value= data.transferSize)= h.size.format(data.transferSize) +- sustainable = pageInfo.data.sustainable.pageSummary ? pageInfo.data.sustainable.pageSummary.firstRun : sustainable -if sustainable.dirtiestResources - h2 Dirtiest assets - table(data-sortable) - thead - tr - th Asset - th Estimated CO2 emissions - th Transfer Size - each resource in sustainable.dirtiestResources - tr - td.url.assetsurl(data-title='URL') - a(href=resource.url)= h.shortAsset(resource.url) - td.number= resource.co2 - td.number= h.size.format(resource.transferSize) +h2 Per domain + if pageInfo.data.sustainable.pageSummary + | (first run) +table(data-sortable) + thead + tr + th Domain + th Estimated CO2 emissions + th Transfer Size + each data in sustainable.co2PerDomain + tr + td #{data.domain} + - if (sustainable.hostingGreenCheck.indexOf(data.domain) > -1) + span(class='label normal ok') green + td.number(data-value= data.co2)= data.co2 + td.number(data-value= data.transferSize)= h.size.format(data.transferSize) + +h2 Dirtiest assets + if pageInfo.data.sustainable.pageSummary + | (first run) +table(data-sortable) + thead + tr + th Asset + th Estimated CO2 emissions + th Transfer Size + each resource in sustainable.dirtiestResources + tr + td.url.assetsurl(data-title='URL') + a(href=resource.url)= h.shortAsset(resource.url) + td.number= resource.co2 + td.number= h.size.format(resource.transferSize) \ No newline at end of file