@pagepocket/main-content-unit 0.12.0 → 0.13.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.
@@ -1,15 +1,15 @@
1
- import { Unit, type FileTree, type UnitContext, type UnitPatch, type UnitRuntime } from "@pagepocket/lib";
1
+ import { SnapshotUnit, type UnitContext, type UnitRuntime } from "@pagepocket/lib";
2
2
  export type MainContentUnitOptions = {
3
3
  markdown?: boolean;
4
4
  };
5
- export declare class MainContentUnit extends Unit {
6
- readonly id = "mainContent";
7
- readonly kind = "extract.mainContent";
5
+ export declare class MainContentUnit extends SnapshotUnit {
6
+ readonly id = "buildSnapshot";
7
+ readonly description = "Extracting main content";
8
+ readonly snapshotType = "main-content";
8
9
  private options;
9
10
  constructor(options?: MainContentUnitOptions);
10
- merge(returnValue: UnitPatch, pluginContributedValue?: UnitPatch): UnitPatch;
11
- run(ctx: UnitContext, _rt: UnitRuntime): Promise<{
12
- files: FileTree;
11
+ build(ctx: UnitContext, _rt: UnitRuntime): Promise<{
12
+ files: import("@pagepocket/lib").FileTree;
13
13
  html: {
14
14
  htmlString: string;
15
15
  baseUrl: string;
@@ -1,23 +1,15 @@
1
- import { mergeFileTrees, Unit } from "@pagepocket/lib";
1
+ import { SnapshotUnit } from "@pagepocket/lib";
2
2
  import { Defuddle } from "defuddle/node";
3
3
  import { buildContentTree } from "./build-content-tree.js";
4
- export class MainContentUnit extends Unit {
4
+ export class MainContentUnit extends SnapshotUnit {
5
5
  constructor(options) {
6
6
  super();
7
- this.id = "mainContent";
8
- this.kind = "extract.mainContent";
7
+ this.id = "buildSnapshot";
8
+ this.description = "Extracting main content";
9
+ this.snapshotType = "main-content";
9
10
  this.options = options ?? {};
10
11
  }
11
- merge(returnValue, pluginContributedValue = {}) {
12
- const mergedValue = { ...returnValue, ...pluginContributedValue };
13
- const returnFiles = returnValue.files;
14
- const pluginFiles = pluginContributedValue.files;
15
- if (!isFileTree(returnFiles) || !isFileTree(pluginFiles)) {
16
- return mergedValue;
17
- }
18
- return { ...mergedValue, files: mergeFileTrees(returnFiles, pluginFiles) };
19
- }
20
- async run(ctx, _rt) {
12
+ async build(ctx, _rt) {
21
13
  const capture = ctx.value.capture;
22
14
  if (!capture) {
23
15
  throw new Error("MainContentUnit requires ctx.value.capture");
@@ -44,19 +36,3 @@ export class MainContentUnit extends Unit {
44
36
  return result.content;
45
37
  }
46
38
  }
47
- const isFileTree = (value) => {
48
- if (!value || typeof value !== "object") {
49
- return false;
50
- }
51
- if (!("root" in value)) {
52
- return false;
53
- }
54
- const root = value.root;
55
- if (!root || typeof root !== "object") {
56
- return false;
57
- }
58
- const rootRecord = root;
59
- return (rootRecord.kind === "directory" &&
60
- typeof rootRecord.path === "string" &&
61
- Array.isArray(rootRecord.entries));
62
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagepocket/main-content-unit",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "PagePocket unit: extract main content from captured HTML using defuddle and rewrite resource URLs to local paths",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,8 +13,8 @@
13
13
  "cheerio": "^1.0.0",
14
14
  "defuddle": "^0.6.0",
15
15
  "jsdom": "^26.0.0",
16
- "@pagepocket/lib": "0.12.0",
17
- "@pagepocket/shared": "0.12.0"
16
+ "@pagepocket/lib": "0.13.0",
17
+ "@pagepocket/shared": "0.13.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "typescript": "^5.4.5",