@nitpicker/report-google-sheets 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/data/create-discrepancies.d.ts +10 -12
- package/lib/data/create-discrepancies.js +27 -31
- package/lib/data/create-image-list.d.ts +26 -6
- package/lib/data/create-image-list.js +65 -39
- package/lib/data/create-links.d.ts +18 -1
- package/lib/data/create-links.js +91 -55
- package/lib/data/create-page-list.d.ts +24 -24
- package/lib/data/create-page-list.js +177 -225
- package/lib/data/create-referrers-relational-table.d.ts +13 -7
- package/lib/data/create-referrers-relational-table.js +57 -47
- package/lib/data/create-resources-relational-table.d.ts +7 -0
- package/lib/data/create-resources-relational-table.js +41 -33
- package/lib/data/create-resources.d.ts +24 -124
- package/lib/data/create-resources.js +100 -264
- package/lib/data/create-violations.d.ts +7 -6
- package/lib/data/create-violations.js +34 -19
- package/lib/dedupe-progress-message.d.ts +17 -0
- package/lib/dedupe-progress-message.js +26 -0
- package/lib/format-progress-count.d.ts +19 -0
- package/lib/format-progress-count.js +22 -0
- package/lib/open-report-archive.d.ts +54 -0
- package/lib/open-report-archive.js +76 -0
- package/lib/report.d.ts +16 -12
- package/lib/report.js +101 -94
- package/lib/reports/get-plugin-reports.d.ts +14 -6
- package/lib/reports/get-plugin-reports.js +14 -34
- package/lib/sheets/create-sheets.d.ts +66 -36
- package/lib/sheets/create-sheets.js +228 -362
- package/lib/sheets/estimate-cell-budget.d.ts +55 -0
- package/lib/sheets/estimate-cell-budget.js +56 -0
- package/lib/sheets/types.d.ts +111 -91
- package/lib/test-helpers/assert-no-lazy-cells.d.ts +16 -0
- package/lib/test-helpers/assert-no-lazy-cells.js +23 -0
- package/lib/test-helpers/cell-inspection.d.ts +20 -0
- package/lib/test-helpers/cell-inspection.js +21 -0
- package/lib/test-helpers/create-mock-sheet.d.ts +30 -0
- package/lib/test-helpers/create-mock-sheet.js +71 -0
- package/lib/test-helpers/one-chunk.d.ts +8 -0
- package/lib/test-helpers/one-chunk.js +11 -0
- package/lib/utils/join-urls-for-note.d.ts +27 -0
- package/lib/utils/join-urls-for-note.js +48 -0
- package/lib/utils/truncate-note-text.d.ts +15 -0
- package/lib/utils/truncate-note-text.js +23 -0
- package/package.json +8 -10
- package/lib/archive.d.ts +0 -29
- package/lib/archive.js +0 -49
- package/lib/sheets/run-finalize-resources.d.ts +0 -40
- package/lib/sheets/run-finalize-resources.js +0 -44
- package/lib/types.d.ts +0 -11
- package/lib/types.js +0 -1
- package/lib/utils/canonicalize-url.d.ts +0 -53
- package/lib/utils/canonicalize-url.js +0 -105
- package/lib/utils/has-prop-filter.d.ts +0 -18
- package/lib/utils/has-prop-filter.js +0 -19
- package/lib/utils/sort-resources-by-url.d.ts +0 -69
- package/lib/utils/sort-resources-by-url.js +0 -223
|
@@ -2,18 +2,16 @@ import type { CreateSheet } from '../sheets/types.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates the "Discrepancies" sheet configuration.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* Lists cross-page discrepancies produced by analyze plugins (e.g. meta tag
|
|
6
|
+
* consistency checks).
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* Both data sources are written to the same sheet, distinguished by
|
|
16
|
-
* the "Type" column.
|
|
17
|
-
* @param reports
|
|
8
|
+
* The pre-rewrite version also compared every anchor's `textContent`
|
|
9
|
+
* against its `title` attribute (a "Link Text vs Page Title" check, despite
|
|
10
|
+
* the label — it never actually compared to the destination page's
|
|
11
|
+
* `<title>`). That check is dropped: an anchor's `title` attribute is not
|
|
12
|
+
* stored anywhere in the 0.13 write model or the viewer read model (only
|
|
13
|
+
* `anchor_edges.first_text_id`/`viewer_anchor_facts.first_text_id`, the
|
|
14
|
+
* `textContent`, survive), so there is no data left to compare against.
|
|
15
|
+
* @param reports - Analyze plugin reports to extract discrepancy data from.
|
|
18
16
|
*/
|
|
19
17
|
export declare const createDiscrepancies: CreateSheet;
|
|
@@ -5,19 +5,17 @@ const log = pLog.extend('Discrepancies');
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates the "Discrepancies" sheet configuration.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Lists cross-page discrepancies produced by analyze plugins (e.g. meta tag
|
|
9
|
+
* consistency checks).
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* Both data sources are written to the same sheet, distinguished by
|
|
19
|
-
* the "Type" column.
|
|
20
|
-
* @param reports
|
|
11
|
+
* The pre-rewrite version also compared every anchor's `textContent`
|
|
12
|
+
* against its `title` attribute (a "Link Text vs Page Title" check, despite
|
|
13
|
+
* the label — it never actually compared to the destination page's
|
|
14
|
+
* `<title>`). That check is dropped: an anchor's `title` attribute is not
|
|
15
|
+
* stored anywhere in the 0.13 write model or the viewer read model (only
|
|
16
|
+
* `anchor_edges.first_text_id`/`viewer_anchor_facts.first_text_id`, the
|
|
17
|
+
* `textContent`, survive), so there is no data left to compare against.
|
|
18
|
+
* @param reports - Analyze plugin reports to extract discrepancy data from.
|
|
21
19
|
*/
|
|
22
20
|
export const createDiscrepancies = (reports) => {
|
|
23
21
|
return {
|
|
@@ -25,31 +23,27 @@ export const createDiscrepancies = (reports) => {
|
|
|
25
23
|
createHeaders() {
|
|
26
24
|
return ['Type', 'Left URL', 'Left', 'Right', 'Right URL', 'Note'];
|
|
27
25
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
log('Found %d anchors', anchors.length);
|
|
33
|
-
for (const anchor of anchors) {
|
|
34
|
-
data.push([
|
|
35
|
-
createCellData({ value: 'Link Text vs Page Title' }, defaultCellFormat),
|
|
36
|
-
createCellData({ value: page.url.href }, defaultCellFormat),
|
|
37
|
-
createCellData({ value: anchor.textContent }, defaultCellFormat),
|
|
38
|
-
createCellData({ value: anchor.title }, defaultCellFormat),
|
|
39
|
-
createCellData({ value: anchor.url }, defaultCellFormat),
|
|
40
|
-
createCellData({ value: '' }, defaultCellFormat),
|
|
41
|
-
]);
|
|
26
|
+
estimateRowCount() {
|
|
27
|
+
let count = 0;
|
|
28
|
+
for (const report of reports) {
|
|
29
|
+
count += report.discrepancies?.length ?? 0;
|
|
42
30
|
}
|
|
43
|
-
return
|
|
31
|
+
return count;
|
|
44
32
|
},
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
async run({ sheet, maxRows, onProgress }) {
|
|
34
|
+
let sent = 0;
|
|
35
|
+
const total = reports.reduce((sum, r) => sum + (r.discrepancies?.length ?? 0), 0);
|
|
47
36
|
for (const report of reports) {
|
|
48
37
|
if (!report.discrepancies) {
|
|
49
38
|
continue;
|
|
50
39
|
}
|
|
40
|
+
log('From %s', report.name);
|
|
51
41
|
for (const discrepancy of report.discrepancies) {
|
|
52
|
-
|
|
42
|
+
if (sent >= maxRows) {
|
|
43
|
+
await sheet.flush();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
await sheet.appendRow([
|
|
53
47
|
createCellData({ value: report.name }, defaultCellFormat),
|
|
54
48
|
createCellData({ value: discrepancy.leftSourceUrl, note: discrepancy.leftSourceUrlNote }, defaultCellFormat),
|
|
55
49
|
createCellData({ value: discrepancy.left, note: discrepancy.leftNote }, defaultCellFormat),
|
|
@@ -57,9 +51,11 @@ export const createDiscrepancies = (reports) => {
|
|
|
57
51
|
createCellData({ value: discrepancy.rightSourceUrl, note: discrepancy.rightSourceUrlNote }, defaultCellFormat),
|
|
58
52
|
createCellData({ value: discrepancy.note }, defaultCellFormat),
|
|
59
53
|
]);
|
|
54
|
+
sent++;
|
|
55
|
+
onProgress(sent, total);
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
|
-
|
|
58
|
+
await sheet.flush();
|
|
63
59
|
},
|
|
64
60
|
};
|
|
65
61
|
};
|
|
@@ -2,12 +2,32 @@ import type { CreateSheet } from '../sheets/types.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates the "Images" sheet configuration.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Reports every `<img>` element's attributes (src, currentSrc, alt,
|
|
6
|
+
* dimensions, lazy loading, DOM position) via `streamAllImages` — a plain
|
|
7
|
+
* `image_items` keyset sweep (write-model, populated at crawl time; see
|
|
8
|
+
* that function's docs for why it bypasses the viewer UI's
|
|
9
|
+
* `listViewerImages`/`viewer_images`).
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* The pre-rewrite version instead re-fetched each internal page's full
|
|
12
|
+
* HTML snapshot and re-parsed it with `jsdom` per page (`page.getHtml()` +
|
|
13
|
+
* `new JSDOM(html)`), to resolve `src`/`currentSrc` after base-URL
|
|
14
|
+
* resolution — the only sheet that did so. `image_items` already stores
|
|
15
|
+
* those resolved values from crawl time, so this sheet no longer needs
|
|
16
|
+
* `jsdom` or HTML-blob decompression at all.
|
|
17
|
+
*
|
|
18
|
+
* `requiresReadModel: true` holds regardless of `streamAllImages`' own
|
|
19
|
+
* write-model-only dependency: this flag governs the `viewer-build`
|
|
20
|
+
* gate `report.ts` enforces before running any selected sheet (see
|
|
21
|
+
* `sheets/types.ts`), not each sheet's individual data source, so it is
|
|
22
|
+
* set independently of which tables a given sheet's `run()` happens to
|
|
23
|
+
* read.
|
|
24
|
+
*
|
|
25
|
+
* `Source Code` (the `<img>`'s `outerHTML`) is dropped: the 0.13 schema
|
|
26
|
+
* deliberately does not store it (see `image_items.dom_path_text_id`'s DDL
|
|
27
|
+
* comment) — replaced by `DOM Path`, a stable structural locator
|
|
28
|
+
* (e.g. `html/body[1]/main[1]/img[1]`) derived from the same crawl-time
|
|
29
|
+
* capture.
|
|
30
|
+
* @param _reports
|
|
31
|
+
* @param accessor
|
|
12
32
|
*/
|
|
13
33
|
export declare const createImageList: CreateSheet;
|
|
@@ -1,20 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { streamAllImages } from '@nitpicker/query';
|
|
2
2
|
import { createCellData } from '../sheets/create-cell-data.js';
|
|
3
3
|
import { defaultCellFormat } from '../sheets/default-cell-format.js';
|
|
4
|
+
/**
|
|
5
|
+
* Counts every `image_items` row, for `estimateRowCount()`.
|
|
6
|
+
* @param accessor - The archive accessor to query.
|
|
7
|
+
*/
|
|
8
|
+
async function countImages(accessor) {
|
|
9
|
+
const knex = accessor.getKnex();
|
|
10
|
+
const [row] = await knex('image_items').count({
|
|
11
|
+
count: '*',
|
|
12
|
+
});
|
|
13
|
+
return Number(row?.count ?? 0);
|
|
14
|
+
}
|
|
4
15
|
/**
|
|
5
16
|
* Creates the "Images" sheet configuration.
|
|
6
17
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
18
|
+
* Reports every `<img>` element's attributes (src, currentSrc, alt,
|
|
19
|
+
* dimensions, lazy loading, DOM position) via `streamAllImages` — a plain
|
|
20
|
+
* `image_items` keyset sweep (write-model, populated at crawl time; see
|
|
21
|
+
* that function's docs for why it bypasses the viewer UI's
|
|
22
|
+
* `listViewerImages`/`viewer_images`).
|
|
23
|
+
*
|
|
24
|
+
* The pre-rewrite version instead re-fetched each internal page's full
|
|
25
|
+
* HTML snapshot and re-parsed it with `jsdom` per page (`page.getHtml()` +
|
|
26
|
+
* `new JSDOM(html)`), to resolve `src`/`currentSrc` after base-URL
|
|
27
|
+
* resolution — the only sheet that did so. `image_items` already stores
|
|
28
|
+
* those resolved values from crawl time, so this sheet no longer needs
|
|
29
|
+
* `jsdom` or HTML-blob decompression at all.
|
|
11
30
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
31
|
+
* `requiresReadModel: true` holds regardless of `streamAllImages`' own
|
|
32
|
+
* write-model-only dependency: this flag governs the `viewer-build`
|
|
33
|
+
* gate `report.ts` enforces before running any selected sheet (see
|
|
34
|
+
* `sheets/types.ts`), not each sheet's individual data source, so it is
|
|
35
|
+
* set independently of which tables a given sheet's `run()` happens to
|
|
36
|
+
* read.
|
|
37
|
+
*
|
|
38
|
+
* `Source Code` (the `<img>`'s `outerHTML`) is dropped: the 0.13 schema
|
|
39
|
+
* deliberately does not store it (see `image_items.dom_path_text_id`'s DDL
|
|
40
|
+
* comment) — replaced by `DOM Path`, a stable structural locator
|
|
41
|
+
* (e.g. `html/body[1]/main[1]/img[1]`) derived from the same crawl-time
|
|
42
|
+
* capture.
|
|
43
|
+
* @param _reports
|
|
44
|
+
* @param accessor
|
|
14
45
|
*/
|
|
15
|
-
export const createImageList = () => {
|
|
46
|
+
export const createImageList = (_reports, accessor) => {
|
|
16
47
|
return {
|
|
17
48
|
name: 'Images',
|
|
49
|
+
requiresReadModel: true,
|
|
18
50
|
createHeaders() {
|
|
19
51
|
return [
|
|
20
52
|
'Page URL',
|
|
@@ -23,41 +55,35 @@ export const createImageList = () => {
|
|
|
23
55
|
'Alternative Text',
|
|
24
56
|
'Displayed Width',
|
|
25
57
|
'Displayed Height',
|
|
26
|
-
// 'Original Width',
|
|
27
|
-
// 'Original Height',
|
|
28
|
-
// 'Fit Width Rate',
|
|
29
|
-
// 'Fit Height Rate',
|
|
30
58
|
'Lazy Loading',
|
|
31
|
-
'
|
|
59
|
+
'DOM Path',
|
|
32
60
|
];
|
|
33
61
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
];
|
|
58
|
-
imgData.push(data);
|
|
62
|
+
estimateRowCount: () => countImages(accessor),
|
|
63
|
+
async run({ sheet, maxRows, estimatedTotal, onProgress }) {
|
|
64
|
+
let sent = 0;
|
|
65
|
+
const total = estimatedTotal;
|
|
66
|
+
for await (const chunk of streamAllImages(accessor)) {
|
|
67
|
+
for (const item of chunk) {
|
|
68
|
+
if (sent >= maxRows) {
|
|
69
|
+
await sheet.flush();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
await sheet.appendRow([
|
|
73
|
+
createCellData({ value: item.pageUrl }, defaultCellFormat),
|
|
74
|
+
createCellData({ value: item.src }, defaultCellFormat),
|
|
75
|
+
createCellData({ value: item.currentSrc }, defaultCellFormat),
|
|
76
|
+
createCellData({ value: item.alt }, defaultCellFormat),
|
|
77
|
+
createCellData({ value: item.width }, defaultCellFormat),
|
|
78
|
+
createCellData({ value: item.height }, defaultCellFormat),
|
|
79
|
+
createCellData({ value: item.isLazy }, defaultCellFormat),
|
|
80
|
+
createCellData({ value: item.domPath }, defaultCellFormat),
|
|
81
|
+
]);
|
|
82
|
+
sent++;
|
|
83
|
+
onProgress(sent, total);
|
|
84
|
+
}
|
|
59
85
|
}
|
|
60
|
-
|
|
86
|
+
await sheet.flush();
|
|
61
87
|
},
|
|
62
88
|
};
|
|
63
89
|
};
|
|
@@ -2,14 +2,31 @@ import type { CreateSheet } from '../sheets/types.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates the "Links" sheet configuration.
|
|
4
4
|
*
|
|
5
|
-
* Produces one row per
|
|
5
|
+
* Produces one row per `content_items` row — internal, external, skipped,
|
|
6
|
+
* and never-fetched alike (see `streamAllContentItems`'s docs for why this
|
|
7
|
+
* bypasses the viewer read model's `viewer_pages`, which structurally
|
|
8
|
+
* cannot list skipped/never-fetched pages) — with URL, title, HTTP status,
|
|
6
9
|
* content type, redirect chain, referrers, response headers, and remarks.
|
|
7
10
|
* The remarks column shows the skip reason for pages that were skipped
|
|
8
11
|
* during crawling (e.g., blocked by robots.txt, excluded by rules).
|
|
12
|
+
*
|
|
13
|
+
* Referrers are fetched from `viewer_anchor_facts`
|
|
14
|
+
* (`getInboundReferrerUrlsByPageIds`, batched per `streamAllContentItems`
|
|
15
|
+
* chunk): the "N Elements" count sums every returned detail's
|
|
16
|
+
* `InboundReferrerDetail.count` (the raw per-anchor occurrence tally
|
|
17
|
+
* `viewer_anchor_facts` still carries, even though it stores one row per
|
|
18
|
+
* `(source, resolved dest)` pair rather than one per raw anchor
|
|
19
|
+
* observation), and each note line reconstructs the pre-rewrite report's
|
|
20
|
+
* `text (url => [REDIRECTED FROM] rawUrl)` format from
|
|
21
|
+
* `InboundReferrerDetail.redirectedFromUrl`. This sheet therefore requires
|
|
22
|
+
* the viewer read model (`requiresReadModel: true`).
|
|
23
|
+
*
|
|
9
24
|
* Applies conditional formatting to highlight:
|
|
10
25
|
* - Status codes >= 400 (client/server errors)
|
|
11
26
|
* - Status codes outside the 200-399 range (non-success)
|
|
12
27
|
*
|
|
13
28
|
* The header row and first column are frozen for easier scrolling.
|
|
29
|
+
* @param _reports
|
|
30
|
+
* @param accessor
|
|
14
31
|
*/
|
|
15
32
|
export declare const createLinks: CreateSheet;
|
package/lib/data/create-links.js
CHANGED
|
@@ -1,24 +1,57 @@
|
|
|
1
|
+
import { getInboundReferrerUrlsByPageIds, streamAllContentItems } from '@nitpicker/query';
|
|
1
2
|
import { pLog } from '../debug.js';
|
|
2
3
|
import { createCellData } from '../sheets/create-cell-data.js';
|
|
3
4
|
import { defaultCellFormat } from '../sheets/default-cell-format.js';
|
|
4
5
|
import { booleanFormatError } from '../sheets/format.js';
|
|
6
|
+
import { joinUrlsForNote } from '../utils/join-urls-for-note.js';
|
|
7
|
+
import { truncateNoteText } from '../utils/truncate-note-text.js';
|
|
5
8
|
const log = pLog.extend('Links');
|
|
9
|
+
/**
|
|
10
|
+
* Formats one referrer's cell-note line, restoring the pre-rewrite report's
|
|
11
|
+
* `text (url => [REDIRECTED FROM] rawUrl)` shape.
|
|
12
|
+
* @param detail - One referrer's detail from `getInboundReferrerUrlsByPageIds`.
|
|
13
|
+
*/
|
|
14
|
+
function formatReferrerNoteLine(detail) {
|
|
15
|
+
const text = detail.textContent || '(no text)';
|
|
16
|
+
const redirectSuffix = detail.redirectedFromUrl
|
|
17
|
+
? ` => [REDIRECTED FROM] ${detail.redirectedFromUrl}`
|
|
18
|
+
: '';
|
|
19
|
+
return `${text} (${detail.url}${redirectSuffix})`;
|
|
20
|
+
}
|
|
6
21
|
/**
|
|
7
22
|
* Creates the "Links" sheet configuration.
|
|
8
23
|
*
|
|
9
|
-
* Produces one row per
|
|
24
|
+
* Produces one row per `content_items` row — internal, external, skipped,
|
|
25
|
+
* and never-fetched alike (see `streamAllContentItems`'s docs for why this
|
|
26
|
+
* bypasses the viewer read model's `viewer_pages`, which structurally
|
|
27
|
+
* cannot list skipped/never-fetched pages) — with URL, title, HTTP status,
|
|
10
28
|
* content type, redirect chain, referrers, response headers, and remarks.
|
|
11
29
|
* The remarks column shows the skip reason for pages that were skipped
|
|
12
30
|
* during crawling (e.g., blocked by robots.txt, excluded by rules).
|
|
31
|
+
*
|
|
32
|
+
* Referrers are fetched from `viewer_anchor_facts`
|
|
33
|
+
* (`getInboundReferrerUrlsByPageIds`, batched per `streamAllContentItems`
|
|
34
|
+
* chunk): the "N Elements" count sums every returned detail's
|
|
35
|
+
* `InboundReferrerDetail.count` (the raw per-anchor occurrence tally
|
|
36
|
+
* `viewer_anchor_facts` still carries, even though it stores one row per
|
|
37
|
+
* `(source, resolved dest)` pair rather than one per raw anchor
|
|
38
|
+
* observation), and each note line reconstructs the pre-rewrite report's
|
|
39
|
+
* `text (url => [REDIRECTED FROM] rawUrl)` format from
|
|
40
|
+
* `InboundReferrerDetail.redirectedFromUrl`. This sheet therefore requires
|
|
41
|
+
* the viewer read model (`requiresReadModel: true`).
|
|
42
|
+
*
|
|
13
43
|
* Applies conditional formatting to highlight:
|
|
14
44
|
* - Status codes >= 400 (client/server errors)
|
|
15
45
|
* - Status codes outside the 200-399 range (non-success)
|
|
16
46
|
*
|
|
17
47
|
* The header row and first column are frozen for easier scrolling.
|
|
48
|
+
* @param _reports
|
|
49
|
+
* @param accessor
|
|
18
50
|
*/
|
|
19
|
-
export const createLinks = () => {
|
|
51
|
+
export const createLinks = (_reports, accessor) => {
|
|
20
52
|
return {
|
|
21
53
|
name: 'Links',
|
|
54
|
+
requiresReadModel: true,
|
|
22
55
|
createHeaders() {
|
|
23
56
|
return [
|
|
24
57
|
'URL',
|
|
@@ -32,46 +65,59 @@ export const createLinks = () => {
|
|
|
32
65
|
'Remarks',
|
|
33
66
|
];
|
|
34
67
|
},
|
|
35
|
-
async
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
async estimateRowCount() {
|
|
69
|
+
const knex = accessor.getKnex();
|
|
70
|
+
const [row] = await knex('content_items').count({
|
|
71
|
+
count: '*',
|
|
72
|
+
});
|
|
73
|
+
return Number(row?.count ?? 0);
|
|
74
|
+
},
|
|
75
|
+
async run({ sheet, maxRows, estimatedTotal, onProgress }) {
|
|
76
|
+
let sent = 0;
|
|
77
|
+
// No cheap running total from `streamAllContentItems` itself (unlike
|
|
78
|
+
// `getViolations`'s `page.total` or `listViewerPages`'s `page.total`)
|
|
79
|
+
// — `estimatedTotal` (from `estimateRowCount()`, captured once in
|
|
80
|
+
// Phase 1.5) is the progress denominator instead.
|
|
81
|
+
const total = estimatedTotal;
|
|
82
|
+
for await (const chunk of streamAllContentItems(accessor)) {
|
|
83
|
+
const referrerDetailsByPageId = await getInboundReferrerUrlsByPageIds(accessor, chunk.map((row) => row.pageId));
|
|
84
|
+
for (const row of chunk) {
|
|
85
|
+
if (sent >= maxRows) {
|
|
86
|
+
await sheet.flush();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const referrerDetails = referrerDetailsByPageId.get(row.pageId) ?? [];
|
|
90
|
+
// Sum occurrence counts, not `.length`: `referrerDetails` is
|
|
91
|
+
// already deduped to one entry per referring page (see
|
|
92
|
+
// `InboundReferrerDetail.count`'s docs), so counting entries
|
|
93
|
+
// would undercount a page with more than one anchor to the
|
|
94
|
+
// same destination.
|
|
95
|
+
const elementCount = referrerDetails.reduce((sum, d) => sum + d.count, 0);
|
|
96
|
+
await sheet.appendRow([
|
|
97
|
+
createCellData({ value: row.url, textFormat: { link: { uri: row.url } } }, defaultCellFormat),
|
|
98
|
+
createCellData({ value: row.title || '-' }, defaultCellFormat),
|
|
99
|
+
createCellData({ value: row.status ?? -1 }, defaultCellFormat),
|
|
100
|
+
createCellData({ value: row.statusText || '' }, defaultCellFormat),
|
|
101
|
+
createCellData({ value: row.contentType || '' }, defaultCellFormat),
|
|
102
|
+
createCellData({
|
|
103
|
+
value: row.redirectFromUrls.length,
|
|
104
|
+
note: joinUrlsForNote(row.redirectFromUrls),
|
|
105
|
+
}, defaultCellFormat),
|
|
106
|
+
createCellData({
|
|
107
|
+
value: `${elementCount} Elements`,
|
|
108
|
+
note: joinUrlsForNote(referrerDetails.map(formatReferrerNoteLine)),
|
|
109
|
+
}, defaultCellFormat),
|
|
110
|
+
createCellData({
|
|
111
|
+
value: '{}',
|
|
112
|
+
note: truncateNoteText(JSON.stringify(row.responseHeaders, null, 2)),
|
|
113
|
+
}, defaultCellFormat),
|
|
114
|
+
createCellData({ value: row.isSkipped ? row.skipReason || 'skipped' : '' }, defaultCellFormat),
|
|
115
|
+
]);
|
|
116
|
+
sent++;
|
|
117
|
+
onProgress(sent, total);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
await sheet.flush();
|
|
75
121
|
},
|
|
76
122
|
async updateSheet(sheet) {
|
|
77
123
|
await sheet.frozen(2, 1);
|
|
@@ -79,11 +125,7 @@ export const createLinks = () => {
|
|
|
79
125
|
booleanRule: {
|
|
80
126
|
condition: {
|
|
81
127
|
type: 'NUMBER_GREATER_THAN_EQ',
|
|
82
|
-
values: [
|
|
83
|
-
{
|
|
84
|
-
userEnteredValue: '400',
|
|
85
|
-
},
|
|
86
|
-
],
|
|
128
|
+
values: [{ userEnteredValue: '400' }],
|
|
87
129
|
},
|
|
88
130
|
format: booleanFormatError,
|
|
89
131
|
},
|
|
@@ -92,18 +134,12 @@ export const createLinks = () => {
|
|
|
92
134
|
booleanRule: {
|
|
93
135
|
condition: {
|
|
94
136
|
type: 'NUMBER_NOT_BETWEEN',
|
|
95
|
-
values: [
|
|
96
|
-
{
|
|
97
|
-
userEnteredValue: '200',
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
userEnteredValue: '399',
|
|
101
|
-
},
|
|
102
|
-
],
|
|
137
|
+
values: [{ userEnteredValue: '200' }, { userEnteredValue: '399' }],
|
|
103
138
|
},
|
|
104
139
|
format: booleanFormatError,
|
|
105
140
|
},
|
|
106
141
|
});
|
|
142
|
+
log('Formatting applied');
|
|
107
143
|
},
|
|
108
144
|
};
|
|
109
145
|
};
|
|
@@ -5,13 +5,16 @@ import type { CreateSheet } from '../sheets/types.js';
|
|
|
5
5
|
* This is the most complex sheet, combining crawler metadata with analyze
|
|
6
6
|
* plugin data into a comprehensive per-page inventory:
|
|
7
7
|
*
|
|
8
|
-
* - **URL decomposition**: Protocol, domain, and up to 10 path segments
|
|
9
|
-
*
|
|
8
|
+
* - **URL decomposition**: Protocol, domain, and up to 10 path segments for
|
|
9
|
+
* hierarchical filtering in the spreadsheet — computed once at read-model
|
|
10
|
+
* build time, not per-batch (see `PageListItem.path1`'s docs).
|
|
10
11
|
* - **Title shortening**: Directory index titles are subtracted from child
|
|
11
12
|
* page titles to produce concise display titles (e.g. removing the site
|
|
12
|
-
* name suffix)
|
|
13
|
+
* name suffix) — computed once at read-model build time, not per-batch
|
|
14
|
+
* (see `PageListItem.displayTitle`'s docs).
|
|
13
15
|
* - **Link quality**: Internal/external link counts with bad-link breakdowns
|
|
14
|
-
* (status >= 400, excluding 401 which is often auth-protected)
|
|
16
|
+
* (status >= 400, excluding 401 which is often auth-protected) — fetched
|
|
17
|
+
* per cursor batch via `getOutboundLinkFactsByPageIds`.
|
|
15
18
|
* - **SEO metadata**: description, keywords, canonical, alternate, OGP, etc.
|
|
16
19
|
* - **Plugin columns**: Dynamic columns from analyze plugin `pageData`.
|
|
17
20
|
*
|
|
@@ -25,26 +28,23 @@ import type { CreateSheet } from '../sheets/types.js';
|
|
|
25
28
|
*
|
|
26
29
|
* Unused path columns (beyond the deepest URL) are hidden automatically.
|
|
27
30
|
*
|
|
28
|
-
* ##
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* —
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* `
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* is needed since the library auto-detects. The corresponding spec
|
|
45
|
-
* (`create-page-list.spec.ts`) asserts the presence of at least one lazy
|
|
46
|
-
* cell so the maintainer who removes the thunk will see the test fail and
|
|
47
|
-
* be prompted to reconsider whether the change is intentional.
|
|
31
|
+
* ## Streaming design (report OOM fix)
|
|
32
|
+
*
|
|
33
|
+
* Reads `streamPageListRows` (a `viewer_pages` keyset sweep,
|
|
34
|
+
* `requiresReadModel: true` — see that function's docs for why it exists
|
|
35
|
+
* instead of reusing the viewer UI's `listViewerPages`) one chunk at a time
|
|
36
|
+
* and sends each row via `sheet.appendRow(...)` immediately — no lazy
|
|
37
|
+
* (`createCellData(() => ...)`) cells anywhere in this file. The pre-rewrite
|
|
38
|
+
* version used a lazy thunk for "Internal Referrers" (its value depended on
|
|
39
|
+
* sibling index pages processed later in the same batch), which disabled
|
|
40
|
+
* `@d-zero/google-sheets`' automatic 2500-row flush for the entire batch —
|
|
41
|
+
* the direct cause of the OOM this rewrite fixes. That cross-page dependency
|
|
42
|
+
* no longer exists: `displayTitle`/`inboundLinkCount`/
|
|
43
|
+
* `dirIndexInboundLinkCount`/`protocol`/`hostname`/`path1`..`path10` are all
|
|
44
|
+
* precomputed once, for every page, before the read model is queryable at
|
|
45
|
+
* all (see `build-viewer-read-model.ts`), so every column is known
|
|
46
|
+
* synchronously from the current row alone.
|
|
48
47
|
* @param reports - Analyze plugin reports to extract per-page data columns from
|
|
48
|
+
* @param accessor - The archive accessor to query.
|
|
49
49
|
*/
|
|
50
50
|
export declare const createPageList: CreateSheet;
|