Skip to content

Commit

Permalink
make preview less magical
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Feb 7, 2017
1 parent dbe8562 commit 4f0bc67
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
5 changes: 2 additions & 3 deletions lighthouse-core/audits/dobetterweb/uses-optimized-images.js
Expand Up @@ -112,8 +112,7 @@ class UsesOptimizedImages extends Audit {
totalWastedBytes += webpSavings.bytes;
results.push({
url: URL.getDisplayName(image.url),
previewUrl: image.url,
mimeType: image.mimeType,
preview: {url: image.url, mimeType: image.mimeType},
total: `${originalKb} KB`,
webpSavings: `${webpSavings.percent}%`,
jpegSavings: jpegSavingsLabel
Expand Down Expand Up @@ -144,7 +143,7 @@ class UsesOptimizedImages extends Audit {
value: {
results,
tableHeadings: {
previewUrl: '',
preview: '',
url: 'URL',
total: 'Original (KB)',
webpSavings: 'WebP Savings (%)',
Expand Down
8 changes: 5 additions & 3 deletions lighthouse-core/audits/dobetterweb/uses-responsive-images.js
Expand Up @@ -123,8 +123,10 @@ class UsesResponsiveImages extends Audit {
totalWastedBytes += processed.wastedBytes;

results.push(Object.assign({
previewUrl: image.networkRecord.url,
mimeType: image.networkRecord.mimeType
preview: {
url: image.networkRecord.url,
mimeType: image.networkRecord.mimeType
}
}, processed.result));

return results;
Expand All @@ -147,7 +149,7 @@ class UsesResponsiveImages extends Audit {
value: {
results,
tableHeadings: {
previewUrl: '',
preview: '',
url: 'URL',
totalKb: 'Original (KB)',
potentialSavings: 'Potential Savings (%)'
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/formatters/partials/table.html
Expand Up @@ -57,7 +57,7 @@
<thead>
<tr>
{{#each ../tableHeadings}}
<th {{#if_eq @key "previewUrl"}}class="preview-image"{{/if_eq}}>{{this}}</th>
<th {{#if_eq @key "preview"}}class="preview-image"{{/if_eq}}>{{this}}</th>
{{/each}}
</tr>
</thead>
Expand Down
9 changes: 5 additions & 4 deletions lighthouse-core/formatters/table.js
Expand Up @@ -70,7 +70,8 @@ class Table extends Formatter {
* @param {!Object<string>} headings for the table. The order of this
* object's key/value pairs determines the order of the HTML table headings.
* There is special handling for certain keys:
* previewUrl: returns a markdown image wrapped in an anchor.
* preview {url: string, mimeType: string}: For image mimetypes, wraps
* the value in a markdown image.
* code: wraps the value in single ` for a markdown code snippet.
* pre: wraps the value in triple ``` for a markdown code block.
* lineCol: combines the values for the line and col keys into a single
Expand All @@ -94,9 +95,9 @@ class Table extends Formatter {
}

switch (key) {
case 'previewUrl':
if (/^image/.test(result.mimeType)) {
return `[![Image preview](${value} "Image preview")](${value})`;
case 'preview':
if (/^image/.test(value.mimeType)) {
return `[![Image preview](${value.url} "Image preview")](${value.url})`;
}
return '';
case 'code':
Expand Down
5 changes: 2 additions & 3 deletions lighthouse-core/test/formatter/table-formatter-test.js
Expand Up @@ -26,16 +26,15 @@ describe('TableFormatter', () => {
const extendedInfo = {
tableHeadings: {
url: 'URL', lineCol: 'Line/col', code: 'Snippet', isEval: 'Eval\'d?',
pre: 'Code', previewUrl: 'Preview'},
pre: 'Code', preview: 'Preview'},
results: [{
url: 'http://example.com',
line: 123,
col: 456,
code: 'code snippet',
isEval: true,
pre: 'pre snippet',
previewUrl: 'http://example.com/i.jpg',
mimeType: 'image/jpeg',
preview: {url: 'http://example.com/i.jpg', mimeType: 'image/jpeg'}
}]
};

Expand Down

0 comments on commit 4f0bc67

Please sign in to comment.