Skip to content

Commit

Permalink
feat: filters, columns and default - new fields in json
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Aug 21, 2020
1 parent b76b4dc commit 249d4f3
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/presets/columns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
module.exports = {
default: {
name: 'default',
groups: ['main'],
columns: [
'url',
'h1',
'request_time',
'status',
'dom_size',
'html_size',
'is_canonical',
'canonical_count',
'h1_count',
'h2_count',
'h3_count',
'h4_count',
'images',
'images_without_alt',
'images_alt_empty',
'images_outer',
'links',
'links_inner',
'links_outer',
'text_ratio_percent',
/* 'lighthouse_scores_performance',
'lighthouse_scores_pwa',
'lighthouse_scores_accessibility',
'lighthouse_scores_best-practices',
'lighthouse_scores_seo',
'lighthouse_first-contentful-paint',
'lighthouse_speed-index',
'lighthouse_largest-contentful-paint',
'lighthouse_interactive',
'lighthouse_total-blocking-time',
'lighthouse_cumulative-layout-shift', */
]
},
lighthouse: {
name: 'lighthouse',
groups: ['lighthouse'],
columns: [
'url',
'lighthouse_scores_performance',
'lighthouse_scores_pwa',
'lighthouse_scores_accessibility',
'lighthouse_scores_best-practices',
'lighthouse_scores_seo',
'lighthouse_first-contentful-paint',
'lighthouse_speed-index',
'lighthouse_largest-contentful-paint',
'lighthouse_interactive',
'lighthouse_total-blocking-time',
'lighthouse_cumulative-layout-shift',
]
},
opengraph: {
name: 'opengraph',
groups: ['seo'],
columns: [
'url',
'og_image',
'og_title',
'schema_types',
]
},
mixed_content: {
name: 'mixed_content',
groups: ['info', 'seo'],
columns: [
'url',
'mixed_content_url',
]
},
metatags: {
name: 'metatags',
groups: ['info'],
columns: [
'url',
'title',
'description',
'keywords',
'h1',
'canonical',
'og_image',
'og_title',
'schema_types',
]
},
};
17 changes: 17 additions & 0 deletions src/presets/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = [
{
name: 'PageSpeed < 90%',
q: 'lighthouse_scores_performance<90',
groups: ['main', 'perf', 'lighthouse']
},
{
name: 'Request time > 1000',
q: 'request_time>1000',
groups: ['main', 'perf']
},
{
name: 'H1 != 1',
q: 'h1_count!=1',
groups: ['seo']
},
];
13 changes: 13 additions & 0 deletions src/save-as-json.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const fs = require('fs');
const csv = require('csvtojson');
const { fields } = require('./presets/fields');
const filters = require('./presets/filters');
const columns = require('./presets/columns');

const defaultField = 'url';

module.exports = async (csvPath, jsonPath) => {
// read csv to workbook
Expand Down Expand Up @@ -60,6 +64,15 @@ module.exports = async (csvPath, jsonPath) => {
data.fields[i] = field;
}

for (let i in data.fields) {
if (data.fields[i].name === defaultField) {
data.fields[i].default = true; // TODO: default field in viewer
}
}

data.filters = filters;
data.columns = columns;

const raw = JSON.stringify(data);
fs.writeFileSync(jsonPath, raw);
console.log('Saved to ' + jsonPath);
Expand Down

0 comments on commit 249d4f3

Please sign in to comment.