@pkcprotocol/active-page-sort 0.0.1 → 0.0.2
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/README.md +9 -8
- package/dist/types.d.ts +4 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -8,7 +8,8 @@ A board's catalog shows threads in bump order: the thread with the newest reply
|
|
|
8
8
|
|
|
9
9
|
- A thread's **bump time** is the newest of the post's own timestamp and the timestamps of its replies that are **not** no-bump replies.
|
|
10
10
|
- A **no-bump reply** is a reply whose content has a whole line equal to one of the configured keywords. The match is exact and case-sensitive: a content of `sage`, or a multi-line content with a line that is exactly `sage`, does not bump. `sage is overused` in prose, `Sage`, `#sage` and ` sage` all bump.
|
|
11
|
-
- Replies **under** a no-bump reply still count. Someone answering a saged reply bumps the thread as usual.
|
|
11
|
+
- Replies **under** a no-bump reply still count, at any depth. Someone answering a saged reply bumps the thread as usual.
|
|
12
|
+
- A reply the sort's exclusion options drop (by default: removed, deleted, disapproved or pending approval) never counts, and neither does anything under it. Deleting a saged reply also takes the answers under it out of the bump.
|
|
12
13
|
- A saged thread **sinks, it is never hidden**. The sort ranks, it does not filter.
|
|
13
14
|
- With the keyword option unset the sort is plain bump order, identical to pkc-js's built-in `active`.
|
|
14
15
|
|
|
@@ -18,7 +19,7 @@ The word `sage` appears nowhere in this package. The board supplies its vocabula
|
|
|
18
19
|
|
|
19
20
|
## How the sorting works
|
|
20
21
|
|
|
21
|
-
pkc-js regenerates a community's post pages on every publish cycle. For each configured sort it calls the sort file's `score` once per post, higher scores first, equal scores in insertion order. Because this sort declares `requireReplies`, pkc-js hands `score` every descendant of the post as one flat list (reduced by the sort's exclusion options, so removed or deleted replies are already gone), and the score is:
|
|
22
|
+
pkc-js regenerates a community's post pages on every publish cycle. For each configured sort it calls the sort file's `score` once per post, higher scores first, equal scores in insertion order. Because this sort declares `requireReplies`, pkc-js hands `score` every descendant of the post as one flat list (reduced by the sort's exclusion options, so removed or deleted replies are already gone, together with their subtrees), and the score is:
|
|
22
23
|
|
|
23
24
|
```
|
|
24
25
|
max(post.timestamp, ...replies.filter(not no-bump).map(reply => reply.timestamp))
|
|
@@ -34,7 +35,7 @@ The built-in `active` reads one number off each post's CommentUpdate (`lastReply
|
|
|
34
35
|
|
|
35
36
|
## Requirements
|
|
36
37
|
|
|
37
|
-
- pkc-js `>=0.0.
|
|
38
|
+
- pkc-js `>=0.0.110` (configurable page sorts, `settings.pages`, and the page sort types exported from the root)
|
|
38
39
|
- Node.js `>=22` on the machine running the community
|
|
39
40
|
- ESM-only environment
|
|
40
41
|
|
|
@@ -192,7 +193,7 @@ const saged = isNoBumpReplyForOptions(reply.content, community.pageSorts?.posts?
|
|
|
192
193
|
|
|
193
194
|
### 4. Re-sort a page locally (optional)
|
|
194
195
|
|
|
195
|
-
pkc-js exports no sorter: the package's `score` is the whole contract. A UI that wants to re-order threads between community publishes (a user's own reply just landed, say) applies `score` itself. This sort declares `requireReplies`, so it needs each thread's replies: walk a flat reply sort (`newFlat` / `oldFlat`) when the post carries one, otherwise the nested sort's pages recursively, and hand each post its descendants by `parentCid
|
|
196
|
+
pkc-js exports no sorter: the package's `score` is the whole contract. A UI that wants to re-order threads between community publishes (a user's own reply just landed, say) applies `score` itself. This sort declares `requireReplies`, so it needs each thread's replies: walk a flat reply sort (`newFlat` / `oldFlat`) when the post carries one, otherwise the nested sort's pages recursively, at every depth. Then drop the replies the published `exclude*` options exclude, and only then hand each post its descendants by `parentCid`, so a reply under a dropped reply is never reached. Reply pages are generated with the replies scope's exclusions, which keep deleted and removed replies; a walked tree passed through unfiltered counts a deleted reply the community did not, and the re-sort disagrees with the published order. pkc-js does not export its filter: `applyReplyExclusions` in `test/unit/resort-like-a-ui.ts` is a copy to start from. The worked example of the walk and the re-sort is `test/node-and-browser/pages/page-sorts-client-test-util.ts` in pkc-js; this package's own copy of the re-sort is `test/unit/resort-like-a-ui.ts`. A re-sorted page is still one slice of one sort: re-sorting it gives that slice in another order, not the whole board.
|
|
196
197
|
|
|
197
198
|
```ts
|
|
198
199
|
import activePageSort from "@pkcprotocol/active-page-sort";
|
|
@@ -216,8 +217,8 @@ Treat `community.pageSorts[].name` as data: look it up in your own registry, nev
|
|
|
216
217
|
| `SORT_NAME`, `DESCRIPTION`, `optionInputs`, `validatePageSortSettings` | The file's declared surface, for config UIs and tests |
|
|
217
218
|
| `NO_BUMP_KEYWORDS_OPTION` | `"noBumpKeywords"`, the option key. Renaming it is a new contract |
|
|
218
219
|
| `splitKeywords`, `isNoBumpContent`, `bumpTimestamp`, `isNoBumpReplyForOptions` | The matching rules, import-free, for browsers |
|
|
219
|
-
| `PageSortFile`, `PageSortFileFactory`, `PageSortFileFactoryInput`, `PageSortReplyEntry` | Re-exported pkc-js types |
|
|
220
|
-
| `
|
|
220
|
+
| `PageSortFile`, `PageSortFileInput`, `PageSortFileFactory`, `PageSortFileFactoryInput`, `PageSortFileFactoryArgs`, `PageSortScoreArgs`, `PageSortReplyEntry`, `PageSortScope`, `CommunityPageSortSetting` | Re-exported pkc-js types (root exports since pkc-js 0.0.110) |
|
|
221
|
+
| `PageSortSettingsEntry` | Alias of `CommunityPageSortSetting`, the `settings.pages` entry the factory receives |
|
|
221
222
|
|
|
222
223
|
## Development
|
|
223
224
|
|
|
@@ -232,9 +233,9 @@ npm run test:e2e # builds, starts a throwaway kubo daemon, runs a real commun
|
|
|
232
233
|
|---|---|
|
|
233
234
|
| `src/active-page-sort.ts` | The factory: `sortName`, `scope`, `requireReplies`, `optionInputs`, `score`, `validatePageSortSettings` |
|
|
234
235
|
| `src/no-bump.ts` | Keyword splitting, the line match, the bump-time fold. Imports nothing |
|
|
235
|
-
| `src/types.ts` | Re-exports
|
|
236
|
+
| `src/types.ts` | Re-exports of the pkc-js page sort types |
|
|
236
237
|
| `test/unit/` | The contract: match semantics, scorer, validation, and a client re-sort reproducing the community order |
|
|
237
|
-
| `test/e2e/` | A kubo daemon from the `kubo` npm package on ports 15301/18380/24301 (override with `KUBO_E2E_*_PORT`), a pkc-js community configured by `path`,
|
|
238
|
+
| `test/e2e/` | A kubo daemon from the `kubo` npm package on ports 15301/18380/24301 (override with `KUBO_E2E_*_PORT`), a pkc-js community configured by `path`, `sage` and normal replies at depths 1 to 3, author deletions that cut a subtree, read back by a second PKC over IPNS and re-sorted from the walked reply tree |
|
|
238
239
|
|
|
239
240
|
The e2e writes everything under `.tmp/` in the repository and removes it afterwards.
|
|
240
241
|
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { PageSortFile, PageSortFileFactory, PageSortFileFactoryInput, PageSortReplyEntry } from "@pkcprotocol/pkc-js";
|
|
2
|
-
export type { PageSortFile, PageSortFileFactory, PageSortFileFactoryInput, PageSortReplyEntry };
|
|
3
|
-
/**
|
|
4
|
-
export type
|
|
5
|
-
/** One `settings.pages.posts[i]` entry as pkc-js hands it to the factory. */
|
|
6
|
-
export type PageSortSettingsEntry = PageSortFileFactoryArgs["pageSortSettings"];
|
|
7
|
-
/** The argument `score` receives per comment, with `replies` present because this sort declares `requireReplies`. */
|
|
8
|
-
export type PageSortScoreArgs = Parameters<PageSortFile["score"]>[0];
|
|
1
|
+
import type { CommunityPageSortSetting, PageSortFile, PageSortFileFactory, PageSortFileFactoryArgs, PageSortFileFactoryInput, PageSortFileInput, PageSortReplyEntry, PageSortScope, PageSortScoreArgs } from "@pkcprotocol/pkc-js";
|
|
2
|
+
export type { CommunityPageSortSetting, PageSortFile, PageSortFileFactory, PageSortFileFactoryArgs, PageSortFileFactoryInput, PageSortFileInput, PageSortReplyEntry, PageSortScope, PageSortScoreArgs };
|
|
3
|
+
/** One `settings.pages.posts[i]` entry as pkc-js hands it to the factory. Alias of pkc-js's `CommunityPageSortSetting`. */
|
|
4
|
+
export type PageSortSettingsEntry = CommunityPageSortSetting;
|
|
9
5
|
/** The subset of a reply this package reads. A `PageSortReplyEntry` and a page entry are both supersets. */
|
|
10
6
|
export interface NoBumpReplyLike {
|
|
11
7
|
comment: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkcprotocol/active-page-sort",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Bump-order (active) page sort for pkc-js communities where replies carrying a configured keyword, such as sage, do not bump the thread",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@commitlint/cli": "20.4.3",
|
|
48
48
|
"@commitlint/config-conventional": "20.4.3",
|
|
49
|
-
"@pkcprotocol/pkc-js": "0.0.
|
|
49
|
+
"@pkcprotocol/pkc-js": "0.0.110",
|
|
50
50
|
"@release-it/conventional-changelog": "10.0.5",
|
|
51
51
|
"@types/node": "25.3.5",
|
|
52
52
|
"husky": "9.1.7",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"vitest": "4.0.18"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@pkcprotocol/pkc-js": ">=0.0.
|
|
59
|
+
"@pkcprotocol/pkc-js": ">=0.0.110"
|
|
60
60
|
},
|
|
61
61
|
"peerDependenciesMeta": {
|
|
62
62
|
"@pkcprotocol/pkc-js": {
|