@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.
Files changed (56) hide show
  1. package/lib/data/create-discrepancies.d.ts +10 -12
  2. package/lib/data/create-discrepancies.js +27 -31
  3. package/lib/data/create-image-list.d.ts +26 -6
  4. package/lib/data/create-image-list.js +65 -39
  5. package/lib/data/create-links.d.ts +18 -1
  6. package/lib/data/create-links.js +91 -55
  7. package/lib/data/create-page-list.d.ts +24 -24
  8. package/lib/data/create-page-list.js +177 -225
  9. package/lib/data/create-referrers-relational-table.d.ts +13 -7
  10. package/lib/data/create-referrers-relational-table.js +57 -47
  11. package/lib/data/create-resources-relational-table.d.ts +7 -0
  12. package/lib/data/create-resources-relational-table.js +41 -33
  13. package/lib/data/create-resources.d.ts +24 -124
  14. package/lib/data/create-resources.js +100 -264
  15. package/lib/data/create-violations.d.ts +7 -6
  16. package/lib/data/create-violations.js +34 -19
  17. package/lib/dedupe-progress-message.d.ts +17 -0
  18. package/lib/dedupe-progress-message.js +26 -0
  19. package/lib/format-progress-count.d.ts +19 -0
  20. package/lib/format-progress-count.js +22 -0
  21. package/lib/open-report-archive.d.ts +54 -0
  22. package/lib/open-report-archive.js +76 -0
  23. package/lib/report.d.ts +16 -12
  24. package/lib/report.js +101 -94
  25. package/lib/reports/get-plugin-reports.d.ts +14 -6
  26. package/lib/reports/get-plugin-reports.js +14 -34
  27. package/lib/sheets/create-sheets.d.ts +66 -36
  28. package/lib/sheets/create-sheets.js +228 -362
  29. package/lib/sheets/estimate-cell-budget.d.ts +55 -0
  30. package/lib/sheets/estimate-cell-budget.js +56 -0
  31. package/lib/sheets/types.d.ts +111 -91
  32. package/lib/test-helpers/assert-no-lazy-cells.d.ts +16 -0
  33. package/lib/test-helpers/assert-no-lazy-cells.js +23 -0
  34. package/lib/test-helpers/cell-inspection.d.ts +20 -0
  35. package/lib/test-helpers/cell-inspection.js +21 -0
  36. package/lib/test-helpers/create-mock-sheet.d.ts +30 -0
  37. package/lib/test-helpers/create-mock-sheet.js +71 -0
  38. package/lib/test-helpers/one-chunk.d.ts +8 -0
  39. package/lib/test-helpers/one-chunk.js +11 -0
  40. package/lib/utils/join-urls-for-note.d.ts +27 -0
  41. package/lib/utils/join-urls-for-note.js +48 -0
  42. package/lib/utils/truncate-note-text.d.ts +15 -0
  43. package/lib/utils/truncate-note-text.js +23 -0
  44. package/package.json +8 -10
  45. package/lib/archive.d.ts +0 -29
  46. package/lib/archive.js +0 -49
  47. package/lib/sheets/run-finalize-resources.d.ts +0 -40
  48. package/lib/sheets/run-finalize-resources.js +0 -44
  49. package/lib/types.d.ts +0 -11
  50. package/lib/types.js +0 -1
  51. package/lib/utils/canonicalize-url.d.ts +0 -53
  52. package/lib/utils/canonicalize-url.js +0 -105
  53. package/lib/utils/has-prop-filter.d.ts +0 -18
  54. package/lib/utils/has-prop-filter.js +0 -19
  55. package/lib/utils/sort-resources-by-url.d.ts +0 -69
  56. package/lib/utils/sort-resources-by-url.js +0 -223
@@ -1,9 +1,12 @@
1
- import { decodeURISafely } from '@d-zero/shared/decode-uri-safely';
1
+ import { tryParseUrl as parseUrl } from '@d-zero/shared/parse-url';
2
+ import { buildRedirectFromUrlsByDestId, countViewerPagesTotal, getOutboundLinkFactsByPageIds, streamPageListRows, } from '@nitpicker/query';
2
3
  import { pLog, reportLog } from '../debug.js';
3
4
  import { createCellData } from '../sheets/create-cell-data.js';
4
5
  import { defaultCellFormat } from '../sheets/default-cell-format.js';
5
6
  import { booleanFormatError } from '../sheets/format.js';
7
+ import { joinUrlsForNote } from '../utils/join-urls-for-note.js';
6
8
  import { nonNullFilter } from '../utils/non-null-filter.js';
9
+ import { truncateNoteText } from '../utils/truncate-note-text.js';
7
10
  const log = pLog.extend('PageList');
8
11
  /**
9
12
  * Creates the "Page List" sheet configuration -- the primary sitemap-style report.
@@ -11,13 +14,16 @@ const log = pLog.extend('PageList');
11
14
  * This is the most complex sheet, combining crawler metadata with analyze
12
15
  * plugin data into a comprehensive per-page inventory:
13
16
  *
14
- * - **URL decomposition**: Protocol, domain, and up to 10 path segments
15
- * for hierarchical filtering in the spreadsheet.
17
+ * - **URL decomposition**: Protocol, domain, and up to 10 path segments for
18
+ * hierarchical filtering in the spreadsheet — computed once at read-model
19
+ * build time, not per-batch (see `PageListItem.path1`'s docs).
16
20
  * - **Title shortening**: Directory index titles are subtracted from child
17
21
  * page titles to produce concise display titles (e.g. removing the site
18
- * name suffix). The `indexTitles` map accumulates these across pages.
22
+ * name suffix) — computed once at read-model build time, not per-batch
23
+ * (see `PageListItem.displayTitle`'s docs).
19
24
  * - **Link quality**: Internal/external link counts with bad-link breakdowns
20
- * (status >= 400, excluding 401 which is often auth-protected).
25
+ * (status >= 400, excluding 401 which is often auth-protected) — fetched
26
+ * per cursor batch via `getOutboundLinkFactsByPageIds`.
21
27
  * - **SEO metadata**: description, keywords, canonical, alternate, OGP, etc.
22
28
  * - **Plugin columns**: Dynamic columns from analyze plugin `pageData`.
23
29
  *
@@ -31,37 +37,33 @@ const log = pLog.extend('PageList');
31
37
  *
32
38
  * Unused path columns (beyond the deepest URL) are hidden automatically.
33
39
  *
34
- * ## Lazy thunk in "Internal Referrers"
40
+ * ## Streaming design (report OOM fix)
35
41
  *
36
- * The "Internal Referrers" column is emitted via `createCellData(() => ...)`
37
- * — a thunk that reads `parentRefs` / `indexRefs` at `provide()` time. The
38
- * thunk is deliberately deferred because sibling index pages mutate the
39
- * shared maps as the batch iterates, so the final referrer count is only
40
- * accurate after every page has been processed.
41
- *
42
- * `@d-zero/google-sheets` detects this lazy cell (via the
43
- * `Cell.prototype.provide` identity check) and switches the sheet's
44
- * `appendRow()` into buffered mode automatically. The buffered rows are
45
- * sent on the explicit `sheet.flush()` call at batch end, by which time
46
- * the maps are fully populated.
47
- *
48
- * If a future refactor removes the thunk pattern from this column, the
49
- * sheet can be sent as a pure stream — no per-sheet configuration change
50
- * is needed since the library auto-detects. The corresponding spec
51
- * (`create-page-list.spec.ts`) asserts the presence of at least one lazy
52
- * cell so the maintainer who removes the thunk will see the test fail and
53
- * be prompted to reconsider whether the change is intentional.
42
+ * Reads `streamPageListRows` (a `viewer_pages` keyset sweep,
43
+ * `requiresReadModel: true` — see that function's docs for why it exists
44
+ * instead of reusing the viewer UI's `listViewerPages`) one chunk at a time
45
+ * and sends each row via `sheet.appendRow(...)` immediately — no lazy
46
+ * (`createCellData(() => ...)`) cells anywhere in this file. The pre-rewrite
47
+ * version used a lazy thunk for "Internal Referrers" (its value depended on
48
+ * sibling index pages processed later in the same batch), which disabled
49
+ * `@d-zero/google-sheets`' automatic 2500-row flush for the entire batch —
50
+ * the direct cause of the OOM this rewrite fixes. That cross-page dependency
51
+ * no longer exists: `displayTitle`/`inboundLinkCount`/
52
+ * `dirIndexInboundLinkCount`/`protocol`/`hostname`/`path1`..`path10` are all
53
+ * precomputed once, for every page, before the read model is queryable at
54
+ * all (see `build-viewer-read-model.ts`), so every column is known
55
+ * synchronously from the current row alone.
54
56
  * @param reports - Analyze plugin reports to extract per-page data columns from
57
+ * @param accessor - The archive accessor to query.
55
58
  */
56
- export const createPageList = (reports) => {
57
- const indexTitles = new Map();
58
- const indexRefs = new Map();
59
+ export const createPageList = (reports, accessor) => {
60
+ let maxDepth = 0;
59
61
  const reportPageData = reports
60
62
  .map((r) => (r.pageData ? { name: r.name, pageData: r.pageData } : null))
61
63
  .filter(nonNullFilter);
62
- let maxDepth = 0;
63
64
  return {
64
65
  name: 'Page List',
66
+ requiresReadModel: true,
65
67
  createHeaders() {
66
68
  const headers = [
67
69
  'Title',
@@ -133,208 +135,158 @@ export const createPageList = (reports) => {
133
135
  }
134
136
  return headers;
135
137
  },
136
- async eachPage(page) {
137
- if (!page.isInternalPage() || !page.isTarget) {
138
- return;
139
- }
140
- const url = page.url;
141
- maxDepth = Math.max(url.depth, maxDepth);
142
- const paths = [...url.paths];
143
- paths[paths.length - 1] = `${paths.at(-1)}${url.query ? `?${url.query}` : ''}`;
144
- const [path1, path2, path3, path4, path5, path6, path7, path8, path9, path10] = paths.map((p) => `/${decodeURISafely(p)}`);
145
- const anchors = await page.getAnchors();
146
- let iLinks = 0;
147
- const iBadLinks = [];
148
- let xLinks = 0;
149
- const xBadLinks = [];
150
- for (const anchor of anchors) {
151
- if (anchor.isExternal) {
152
- xLinks += 1;
153
- if (!anchor.status || (anchor.status >= 400 && anchor.status !== 401)) {
154
- const url = anchor.href === anchor.url ? anchor.url : `${anchor.href} => ${anchor.url}`;
155
- xBadLinks.push(`${anchor.textContent} (${anchor.status} ${anchor.statusText} ${url})`);
138
+ estimateRowCount() {
139
+ return countViewerPagesTotal(accessor.getKnex(), { isExternal: false });
140
+ },
141
+ async run({ sheet, maxRows, estimatedTotal, onProgress }) {
142
+ const redirectFromByDestId = await buildRedirectFromUrlsByDestId(accessor);
143
+ let sent = 0;
144
+ const total = estimatedTotal;
145
+ for await (const chunk of streamPageListRows(accessor)) {
146
+ const linkFactsByPageId = await getOutboundLinkFactsByPageIds(accessor, chunk.map((item) => item.pageId));
147
+ for (const item of chunk) {
148
+ if (sent >= maxRows) {
149
+ await sheet.flush();
150
+ return;
156
151
  }
157
- }
158
- else {
159
- iLinks += 1;
160
- if (!anchor.status || (anchor.status >= 400 && anchor.status !== 401)) {
161
- const url = anchor.href === anchor.url ? anchor.url : `${anchor.href} => ${anchor.url}`;
162
- iBadLinks.push(`${anchor.textContent} (${anchor.status} ${anchor.statusText} ${url})`);
152
+ // Only for the Title column's indentation depth below --
153
+ // protocol/hostname/path1..10 come precomputed from the read
154
+ // model (item.*) and no longer need a per-row parse.
155
+ const parsedForDepth = parseUrl(item.url);
156
+ if (!parsedForDepth) {
157
+ continue;
163
158
  }
164
- }
165
- }
166
- const refers = await page.getReferrers();
167
- let title = page.title;
168
- const dirname = url.dirname || '/';
169
- const parentDir = `/${url.paths.slice(0, -2).join('/')}`;
170
- const dirTitle = url.isIndex
171
- ? indexTitles.get(parentDir) || indexTitles.get(dirname)
172
- : indexTitles.get(dirname) || indexTitles.get(parentDir);
173
- if (dirTitle && title.includes(dirTitle)) {
174
- title = title.replace(dirTitle, '').replaceAll(/\|||/g, '').trim();
175
- if (!title) {
176
- title = page.title;
177
- }
178
- }
179
- const parentRefs = indexRefs.get(dirname);
180
- if (url.isIndex) {
181
- indexTitles.set(dirname, page.title);
182
- if (parentRefs) {
183
- parentRefs.push({
184
- basename: url.basename,
185
- referrers: refers,
186
- });
187
- // return;
188
- }
189
- else {
190
- indexRefs.set(dirname, [
191
- {
192
- basename: url.basename,
193
- referrers: refers,
194
- },
195
- ]);
196
- }
197
- }
198
- const isRoot = url.dirname == null;
199
- const depth = isRoot ? 0 : url.depth - (url.isIndex ? 1 : 0);
200
- const data = [
201
- createCellData({
202
- value: title,
203
- cellFormat: { padding: { left: Math.max(depth, 0) * 20 + 3 } },
204
- note: `Full-title:\n${page.title}`,
205
- }, defaultCellFormat),
206
- createCellData({ value: page.title }, defaultCellFormat),
207
- createCellData({
208
- value: page.url.href,
209
- textFormat: { link: { uri: page.url.href } },
210
- }, defaultCellFormat),
211
- createCellData({ value: url.protocol }, defaultCellFormat),
212
- createCellData({ value: url.hostname }, defaultCellFormat),
213
- createCellData({ value: path1 || null }, defaultCellFormat),
214
- createCellData({ value: path2 || null }, defaultCellFormat),
215
- createCellData({ value: path3 || null }, defaultCellFormat),
216
- createCellData({ value: path4 || null }, defaultCellFormat),
217
- createCellData({ value: path5 || null }, defaultCellFormat),
218
- createCellData({ value: path6 || null }, defaultCellFormat),
219
- createCellData({ value: path7 || null }, defaultCellFormat),
220
- createCellData({ value: path8 || null }, defaultCellFormat),
221
- createCellData({ value: path9 || null }, defaultCellFormat),
222
- createCellData({ value: path10 || null }, defaultCellFormat),
223
- createCellData({ value: page.status || -1 }, defaultCellFormat),
224
- createCellData({
225
- value: page.redirectFrom.length,
226
- note: page.redirectFrom.map((r) => r.url).join('\n'),
227
- }, defaultCellFormat),
228
- createCellData({ value: page.lang || 'N/A' }, defaultCellFormat),
229
- createCellData({ value: page.charset }, defaultCellFormat),
230
- createCellData({ value: iLinks }, defaultCellFormat),
231
- createCellData({ value: iBadLinks.length, note: iBadLinks.join('\n') }, defaultCellFormat),
232
- createCellData({ value: xLinks }, defaultCellFormat),
233
- createCellData({ value: xBadLinks.length, note: xBadLinks.join('\n') }, defaultCellFormat),
234
- createCellData(() => ({
235
- value: url.isIndex && parentRefs
236
- ? parentRefs.reduce((prev, ref) => prev + ref.referrers.length, 0)
237
- : refers.length,
238
- note: url.isIndex && parentRefs
239
- ? parentRefs
240
- .map((ref) => `[[/${ref.basename || ''}]]\n${ref.referrers
241
- .map((ref) => ref.url)
242
- .join('\n')}`)
243
- .join('\n\n')
244
- : refers.map((ref) => ref.url).join('\n'),
245
- }), defaultCellFormat),
246
- createCellData({ value: page.description }, defaultCellFormat),
247
- createCellData({ value: page.keywords }, defaultCellFormat),
248
- createCellData({ value: page.robots_noindex }, defaultCellFormat),
249
- createCellData({ value: page.robots_nofollow }, defaultCellFormat),
250
- createCellData({ value: page.robots_noarchive }, defaultCellFormat),
251
- createCellData({ value: page.robots_raw }, defaultCellFormat),
252
- createCellData({ value: page.canonical }, defaultCellFormat),
253
- createCellData({ value: page.metaFlat.manifest }, defaultCellFormat),
254
- createCellData({ value: page.metaFlat.themeColor }, defaultCellFormat),
255
- createCellData({ value: page.twitter_card }, defaultCellFormat),
256
- createCellData({ value: page.metaFlat.twitter_site }, defaultCellFormat),
257
- createCellData({ value: page.metaFlat.twitter_creator }, defaultCellFormat),
258
- createCellData({ value: page.og_site_name }, defaultCellFormat),
259
- createCellData({
260
- value: page.og_url,
261
- textFormat: { link: { uri: page.og_url } },
262
- }, defaultCellFormat),
263
- createCellData({ value: page.og_title }, defaultCellFormat),
264
- createCellData({ value: page.og_description }, defaultCellFormat),
265
- createCellData({ value: page.og_type }, defaultCellFormat),
266
- createCellData({ value: page.og_image }, defaultCellFormat),
267
- createCellData({ value: page.metaFlat.og_image_alt }, defaultCellFormat),
268
- createCellData({ value: page.metaFlat.og_locale }, defaultCellFormat),
269
- createCellData({ value: page.metaFlat.og_article_published_time }, defaultCellFormat),
270
- // Denormalised aggregates: written at scrape time so no per-page
271
- // GROUP BY is needed here. `tagsProvidersCsv` is comma-separated
272
- // for native Google Sheets list rendering.
273
- createCellData({ value: page.jsonldCount }, defaultCellFormat),
274
- createCellData({ value: page.tagsProvidersCsv }, defaultCellFormat),
275
- // beholder MainContentsData / ScrollHeightData denormalised
276
- // aggregates. `null` (page never fully rendered) or `0` (rendered,
277
- // no main region / no elements of that kind found) render as
278
- // blank / 0 respectively — no special-casing needed here.
279
- createCellData({ value: page.mainContentSelector }, defaultCellFormat),
280
- createCellData({ value: page.mainContentWordCount }, defaultCellFormat),
281
- createCellData({ value: page.mainContentBodyWordCount }, defaultCellFormat),
282
- createCellData({ value: page.mainContentHeadingCount }, defaultCellFormat),
283
- createCellData({ value: page.mainContentImageCount }, defaultCellFormat),
284
- createCellData({ value: page.mainContentTableCount }, defaultCellFormat),
285
- createCellData({ value: page.mainContentButtonCount }, defaultCellFormat),
286
- createCellData({ value: page.mainContentIframeCount }, defaultCellFormat),
287
- createCellData({ value: page.mainContentVideoCount }, defaultCellFormat),
288
- createCellData({ value: page.mainContentAudioCount }, defaultCellFormat),
289
- createCellData({ value: page.mainContentCanvasCount }, defaultCellFormat),
290
- createCellData({ value: page.mainContentCustomElementCount }, defaultCellFormat),
291
- createCellData({ value: page.scrollHeightDesktop }, defaultCellFormat),
292
- createCellData({ value: page.scrollHeightMobile }, defaultCellFormat),
293
- ];
294
- for (const report of reportPageData) {
295
- const tableData = report.pageData.data[page.url.href];
296
- const options = report.pageData.options
297
- ? report.pageData.options[page.url.href]
298
- : null;
299
- if (!tableData) {
300
- reportLog("%s did'nt have table of %s", report.name, page.url);
301
- continue;
302
- }
303
- reportLog('Add %s to table from %s', page.url.href, report.name);
304
- data.push(...Object.keys(report.pageData.headers).map((key) => {
305
- const option = options ? options[key] || null : null;
306
- const data = tableData[key];
307
- const format = {};
308
- let note;
309
- if (option) {
310
- if (option.bold) {
311
- format.bold = !!option.bold;
312
- }
313
- if (option.fontFamily != null) {
314
- format.fontFamily = `${option.fontFamily}`;
315
- }
316
- if (option.fontSize != null) {
317
- format.fontSize = +option.fontSize;
159
+ maxDepth = Math.max(parsedForDepth.depth, maxDepth);
160
+ const isRoot = parsedForDepth.dirname == null;
161
+ const depth = isRoot
162
+ ? 0
163
+ : parsedForDepth.depth - (parsedForDepth.isIndex ? 1 : 0);
164
+ const facts = linkFactsByPageId.get(item.pageId);
165
+ const redirectFromUrls = redirectFromByDestId.get(item.pageId) ?? [];
166
+ const internalReferrers = item.dirIndexInboundLinkCount ?? item.inboundLinkCount ?? 0;
167
+ const data = [
168
+ createCellData({
169
+ value: item.displayTitle ?? item.title,
170
+ cellFormat: { padding: { left: Math.max(depth, 0) * 20 + 3 } },
171
+ note: truncateNoteText(`Full-title:\n${item.title}`),
172
+ }, defaultCellFormat),
173
+ createCellData({ value: item.title }, defaultCellFormat),
174
+ createCellData({ value: item.url, textFormat: { link: { uri: item.url } } }, defaultCellFormat),
175
+ createCellData({ value: item.protocol }, defaultCellFormat),
176
+ createCellData({ value: item.hostname }, defaultCellFormat),
177
+ createCellData({ value: item.path1 }, defaultCellFormat),
178
+ createCellData({ value: item.path2 }, defaultCellFormat),
179
+ createCellData({ value: item.path3 }, defaultCellFormat),
180
+ createCellData({ value: item.path4 }, defaultCellFormat),
181
+ createCellData({ value: item.path5 }, defaultCellFormat),
182
+ createCellData({ value: item.path6 }, defaultCellFormat),
183
+ createCellData({ value: item.path7 }, defaultCellFormat),
184
+ createCellData({ value: item.path8 }, defaultCellFormat),
185
+ createCellData({ value: item.path9 }, defaultCellFormat),
186
+ createCellData({ value: item.path10 }, defaultCellFormat),
187
+ createCellData({ value: item.status ?? -1 }, defaultCellFormat),
188
+ createCellData({
189
+ value: redirectFromUrls.length,
190
+ note: joinUrlsForNote(redirectFromUrls),
191
+ }, defaultCellFormat),
192
+ createCellData({ value: item.lang || 'N/A' }, defaultCellFormat),
193
+ createCellData({ value: item.charset }, defaultCellFormat),
194
+ createCellData({ value: facts?.internalLinks ?? 0 }, defaultCellFormat),
195
+ createCellData({ value: facts?.internalBadLinks ?? 0 }, defaultCellFormat),
196
+ createCellData({ value: facts?.externalLinks ?? 0 }, defaultCellFormat),
197
+ createCellData({ value: facts?.externalBadLinks ?? 0 }, defaultCellFormat),
198
+ createCellData({ value: internalReferrers }, defaultCellFormat),
199
+ createCellData({ value: item.description }, defaultCellFormat),
200
+ createCellData({ value: item.keywords }, defaultCellFormat),
201
+ createCellData({ value: item.noindex }, defaultCellFormat),
202
+ createCellData({ value: item.nofollow }, defaultCellFormat),
203
+ createCellData({ value: item.noarchive }, defaultCellFormat),
204
+ createCellData({ value: item.robotsRaw }, defaultCellFormat),
205
+ createCellData({ value: item.canonical }, defaultCellFormat),
206
+ createCellData({ value: item.manifest }, defaultCellFormat),
207
+ createCellData({ value: item.themeColor }, defaultCellFormat),
208
+ createCellData({ value: item.twitterCard }, defaultCellFormat),
209
+ createCellData({ value: item.twitterSite }, defaultCellFormat),
210
+ createCellData({ value: item.twitterCreator }, defaultCellFormat),
211
+ createCellData({ value: item.ogSiteName }, defaultCellFormat),
212
+ createCellData({ value: item.ogUrl, textFormat: { link: { uri: item.ogUrl ?? '' } } }, defaultCellFormat),
213
+ createCellData({ value: item.ogTitle }, defaultCellFormat),
214
+ createCellData({ value: item.ogDescription }, defaultCellFormat),
215
+ createCellData({ value: item.ogType }, defaultCellFormat),
216
+ createCellData({ value: item.ogImage }, defaultCellFormat),
217
+ createCellData({ value: item.ogImageAlt }, defaultCellFormat),
218
+ createCellData({ value: item.ogLocale }, defaultCellFormat),
219
+ createCellData({ value: item.ogArticlePublishedTime }, defaultCellFormat),
220
+ // Denormalised aggregates: written at scrape time so no per-page
221
+ // GROUP BY is needed here. `tagsProvidersCsv` is comma-separated
222
+ // for native Google Sheets list rendering.
223
+ createCellData({ value: item.jsonldCount }, defaultCellFormat),
224
+ createCellData({ value: item.tagsProvidersCsv }, defaultCellFormat),
225
+ // beholder MainContentsData / ScrollHeightData denormalised
226
+ // aggregates. `null` (page never fully rendered) or `0` (rendered,
227
+ // no main region / no elements of that kind found) render as
228
+ // blank / 0 respectively — no special-casing needed here.
229
+ createCellData({ value: item.mainContentSelector }, defaultCellFormat),
230
+ createCellData({ value: item.mainContentWordCount }, defaultCellFormat),
231
+ createCellData({ value: item.mainContentBodyWordCount }, defaultCellFormat),
232
+ createCellData({ value: item.mainContentHeadingCount }, defaultCellFormat),
233
+ createCellData({ value: item.mainContentImageCount }, defaultCellFormat),
234
+ createCellData({ value: item.mainContentTableCount }, defaultCellFormat),
235
+ createCellData({ value: item.mainContentButtonCount }, defaultCellFormat),
236
+ createCellData({ value: item.mainContentIframeCount }, defaultCellFormat),
237
+ createCellData({ value: item.mainContentVideoCount }, defaultCellFormat),
238
+ createCellData({ value: item.mainContentAudioCount }, defaultCellFormat),
239
+ createCellData({ value: item.mainContentCanvasCount }, defaultCellFormat),
240
+ createCellData({ value: item.mainContentCustomElementCount }, defaultCellFormat),
241
+ createCellData({ value: item.scrollHeightDesktop }, defaultCellFormat),
242
+ createCellData({ value: item.scrollHeightMobile }, defaultCellFormat),
243
+ ];
244
+ for (const report of reportPageData) {
245
+ const tableData = report.pageData.data[item.url];
246
+ const options = report.pageData.options
247
+ ? report.pageData.options[item.url]
248
+ : null;
249
+ if (!tableData) {
250
+ reportLog("%s did'nt have table of %s", report.name, item.url);
251
+ continue;
318
252
  }
319
- if (option.color != null) {
320
- // format.foregroundColor = option.color;
321
- }
322
- if (option.italic != null) {
323
- format.italic = !!option.italic;
324
- }
325
- if (option.strike != null) {
326
- format.strikethrough = !!option.strike;
327
- }
328
- if (option.underline != null) {
329
- format.underline = !!option.underline;
330
- }
331
- note = data?.note || `${option.note || ''}`;
253
+ reportLog('Add %s to table from %s', item.url, report.name);
254
+ data.push(...Object.keys(report.pageData.headers).map((key) => {
255
+ const option = options ? options[key] || null : null;
256
+ const cellData = tableData[key];
257
+ const format = {};
258
+ let note;
259
+ if (option) {
260
+ if (option.bold) {
261
+ format.bold = !!option.bold;
262
+ }
263
+ if (option.fontFamily != null) {
264
+ format.fontFamily = `${option.fontFamily}`;
265
+ }
266
+ if (option.fontSize != null) {
267
+ format.fontSize = +option.fontSize;
268
+ }
269
+ if (option.italic != null) {
270
+ format.italic = !!option.italic;
271
+ }
272
+ if (option.strike != null) {
273
+ format.strikethrough = !!option.strike;
274
+ }
275
+ if (option.underline != null) {
276
+ format.underline = !!option.underline;
277
+ }
278
+ note = truncateNoteText(cellData?.note || `${option.note || ''}`);
279
+ }
280
+ const value = cellData?.value;
281
+ return createCellData({ value, textFormat: format, note, ifNull: false }, defaultCellFormat);
282
+ }));
332
283
  }
333
- const value = data?.value;
334
- return createCellData({ value, textFormat: format, note, ifNull: false }, defaultCellFormat);
335
- }));
284
+ await sheet.appendRow(data);
285
+ sent++;
286
+ onProgress(sent, total);
287
+ }
336
288
  }
337
- return [data];
289
+ await sheet.flush();
338
290
  },
339
291
  async updateSheet(sheet) {
340
292
  await sheet.frozen(1, 1);
@@ -2,17 +2,23 @@ import type { CreateSheet } from '../sheets/types.js';
2
2
  /**
3
3
  * Creates the "Referrers Relational Table" sheet configuration.
4
4
  *
5
- * Produces a normalized many-to-many table linking each page to all
6
- * pages that reference it (referrers). Each row represents one
7
- * referrer-to-page relationship with the referrer's text content
8
- * and the page's HTTP status info.
5
+ * Produces a normalized many-to-many table linking each page to the pages
6
+ * that reference it (referrers). Each row is one `viewer_anchor_facts`
7
+ * edge — a unique `(source, resolved destination)` pair, with an
8
+ * occurrence `Count` column, plus the destination's HTTP status info.
9
9
  *
10
10
  * This relational format (as opposed to the denormalized referrer
11
11
  * column in "Links") enables pivot-table analysis and filtering
12
12
  * in Google Sheets -- e.g. "which pages link to this 404 page?"
13
13
  *
14
- * Redirect chains are noted: when the referrer originally linked to
15
- * a different URL that redirected to the current page, a
16
- * `[REDIRECTED FROM]` note is added.
14
+ * One row per edge (not per raw anchor observation): the redirect/alias
15
+ * resolution that collapses multiple raw anchors into one edge means a
16
+ * per-anchor "redirected from" note is no longer meaningful at this grain
17
+ * for every raw occurrence — but the edge's own raw href (before
18
+ * resolution) is still shown as a note on the "Link (To)" cell whenever it
19
+ * differs from the resolved destination, and the `Count` column reports how
20
+ * many raw anchor occurrences this edge summarizes.
21
+ * @param _reports
22
+ * @param accessor
17
23
  */
18
24
  export declare const createReferrersRelationalTable: CreateSheet;