@openpeepshq/core 0.18.0 → 0.26.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/dist/db/pg/schema/documents.js +13 -0
- package/dist/db/pg/sql/0022_add_article_slug_indexes.sql +2 -0
- package/dist/db/pg/sql/meta/0022_snapshot.json +4701 -0
- package/dist/db/pg/sql/meta/_journal.json +7 -0
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/jams/index.d.ts +1 -0
- package/dist/jams/index.js +1 -0
- package/dist/jams/spotlight.d.ts +12 -0
- package/dist/jams/spotlight.js +52 -0
- package/dist/posts/finders.d.ts +13 -0
- package/dist/posts/finders.js +48 -0
- package/dist/posts/helpers/index.d.ts +8 -0
- package/dist/posts/index.d.ts +1 -0
- package/dist/posts/index.js +1 -0
- package/dist/posts/mapping.d.ts +28 -0
- package/dist/posts/mutations.d.ts +4 -0
- package/dist/posts/mutations.js +9 -1
- package/dist/posts/slugPolicy.d.ts +20 -0
- package/dist/posts/slugPolicy.js +42 -0
- package/dist/seo/index.js +57 -32
- package/dist/seo/route.d.ts +33 -7
- package/dist/seo/route.js +85 -4
- package/dist/stats/mapping.d.ts +2 -0
- package/package.json +4 -4
package/dist/seo/route.d.ts
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
* Pure parsing of the content routes the crawler layer recognises. Kept free of
|
|
3
|
-
* data-layer imports so the rules are unit-testable and so this can be loaded
|
|
4
|
-
* where opening a database connection would be wrong.
|
|
5
|
-
*/
|
|
6
|
-
export type SeoRouteKind = 'post' | 'group' | 'profile';
|
|
1
|
+
export type SeoRouteKind = 'post' | 'group' | 'profile' | 'slug';
|
|
7
2
|
export type SeoRoute = {
|
|
8
|
-
kind:
|
|
3
|
+
kind: 'post';
|
|
4
|
+
handle: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'group';
|
|
7
|
+
handle: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'profile';
|
|
9
10
|
handle: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'slug';
|
|
13
|
+
/** The article slug as written in the path. */
|
|
14
|
+
slug: string;
|
|
15
|
+
/** Profile-scoped slugs resolve against this profile's handle. */
|
|
16
|
+
handle?: string;
|
|
17
|
+
instanceScoped: boolean;
|
|
10
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Top-level segments that own a route in the web app and therefore can never
|
|
21
|
+
* be a slug path. Kept in sync with `platform/web` routes.
|
|
22
|
+
*/
|
|
23
|
+
export declare const RESERVED_TOP_LEVEL_ROUTES: string[];
|
|
24
|
+
/**
|
|
25
|
+
* A profile handle is 1–16 characters of `[a-zA-Z0-9_-]`, so the web router's
|
|
26
|
+
* `/:handle` route owns every bare slug-shaped segment of length ≤ 16 (a slug
|
|
27
|
+
* is lowercase/digits/hyphens only, a subset of handle shape). Such a segment
|
|
28
|
+
* can never resolve as an instance-scoped slug — `/my-slug` loads the profile
|
|
29
|
+
* page for handle `my-slug`, or 404s. Longer slug-shaped segments can be no
|
|
30
|
+
* handle, so only those qualify as instance slugs. The plugin's availability
|
|
31
|
+
* check enforces the same rule at write time. The shape is shared from
|
|
32
|
+
* `@openpeepshq/common/lib` (single source of truth).
|
|
33
|
+
*/
|
|
34
|
+
export declare const isHandleShaped: (value: string) => boolean;
|
|
35
|
+
/** Profile sub-routes the web router owns under `/:handle/<x>`. */
|
|
36
|
+
export declare const RESERVED_PROFILE_SUBROUTES: string[];
|
|
11
37
|
/**
|
|
12
38
|
* A trailing slash addresses the same page as the bare path; `webNavigator`
|
|
13
39
|
* never emits one, so the canonical spelling has none. Tolerating it here stops
|
package/dist/seo/route.js
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure parsing of the content routes the crawler layer recognises. Kept free of
|
|
3
|
+
* data-layer imports so the rules are unit-testable and so this can be loaded
|
|
4
|
+
* where opening a database connection would be wrong.
|
|
5
|
+
*/
|
|
6
|
+
import { isHandleShapedSlug } from '@openpeepshq/common/lib';
|
|
7
|
+
/**
|
|
8
|
+
* Top-level segments that own a route in the web app and therefore can never
|
|
9
|
+
* be a slug path. Kept in sync with `platform/web` routes.
|
|
10
|
+
*/
|
|
11
|
+
export const RESERVED_TOP_LEVEL_ROUTES = [
|
|
12
|
+
'about',
|
|
13
|
+
'articles',
|
|
14
|
+
'auth',
|
|
15
|
+
'admin',
|
|
16
|
+
'code-of-conduct',
|
|
17
|
+
'conversations',
|
|
18
|
+
'docs',
|
|
19
|
+
'events',
|
|
20
|
+
'explore',
|
|
21
|
+
'feeds',
|
|
22
|
+
'groups',
|
|
23
|
+
'home',
|
|
24
|
+
'jams',
|
|
25
|
+
'members',
|
|
26
|
+
'notifications',
|
|
27
|
+
'payment',
|
|
28
|
+
'plugins',
|
|
29
|
+
'posts',
|
|
30
|
+
'resources',
|
|
31
|
+
'settings',
|
|
32
|
+
'tags',
|
|
33
|
+
'test',
|
|
34
|
+
'welcome',
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* A profile handle is 1–16 characters of `[a-zA-Z0-9_-]`, so the web router's
|
|
38
|
+
* `/:handle` route owns every bare slug-shaped segment of length ≤ 16 (a slug
|
|
39
|
+
* is lowercase/digits/hyphens only, a subset of handle shape). Such a segment
|
|
40
|
+
* can never resolve as an instance-scoped slug — `/my-slug` loads the profile
|
|
41
|
+
* page for handle `my-slug`, or 404s. Longer slug-shaped segments can be no
|
|
42
|
+
* handle, so only those qualify as instance slugs. The plugin's availability
|
|
43
|
+
* check enforces the same rule at write time. The shape is shared from
|
|
44
|
+
* `@openpeepshq/common/lib` (single source of truth).
|
|
45
|
+
*/
|
|
46
|
+
export const isHandleShaped = isHandleShapedSlug;
|
|
47
|
+
/** Profile sub-routes the web router owns under `/:handle/<x>`. */
|
|
48
|
+
export const RESERVED_PROFILE_SUBROUTES = ['followers', 'following'];
|
|
1
49
|
/**
|
|
2
50
|
* A trailing slash addresses the same page as the bare path; `webNavigator`
|
|
3
51
|
* never emits one, so the canonical spelling has none. Tolerating it here stops
|
|
@@ -12,8 +60,41 @@ export const seoRoute = (pathname, { indexProfiles }) => {
|
|
|
12
60
|
const group = /^\/groups\/@?([^/]+?)\/?$/.exec(pathname)?.[1];
|
|
13
61
|
if (group)
|
|
14
62
|
return { kind: 'group', handle: group };
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
63
|
+
// Only the `/@handle` profile route is gated by `indexProfiles`; article
|
|
64
|
+
// slugs (below) are post routes and resolve regardless, matching the sitemap.
|
|
65
|
+
if (indexProfiles) {
|
|
66
|
+
const profile = /^\/@([^/]+?)\/?$/.exec(pathname)?.[1];
|
|
67
|
+
if (profile)
|
|
68
|
+
return { kind: 'profile', handle: profile };
|
|
69
|
+
}
|
|
70
|
+
// Article slugs are post routes, not profile routes: a slug URL is a clean
|
|
71
|
+
// spelling of an article that `crawlableEntries()` always advertises in the
|
|
72
|
+
// sitemap (posts are never gated by `indexProfiles`). So slug recognition
|
|
73
|
+
// must run regardless of the flag — otherwise a community with profile
|
|
74
|
+
// indexing off would advertise `/{slug}` in its sitemap while the meta and
|
|
75
|
+
// canonical-redirect resolvers treat it as a non-route.
|
|
76
|
+
//
|
|
77
|
+
// Profile-scoped article slug: `/{handle}/{slug}` (or `/@handle/{slug}`).
|
|
78
|
+
// The handle may not be a real profile — the slug finder then resolves
|
|
79
|
+
// nothing, which is the same as a route that was never recognised.
|
|
80
|
+
const profileSlug = /^\/(?:@)?([^/]+)\/([\w-]+)\/?$/.exec(pathname);
|
|
81
|
+
if (profileSlug &&
|
|
82
|
+
!RESERVED_TOP_LEVEL_ROUTES.includes(profileSlug[1]) &&
|
|
83
|
+
!RESERVED_PROFILE_SUBROUTES.includes(profileSlug[2])) {
|
|
84
|
+
return {
|
|
85
|
+
kind: 'slug',
|
|
86
|
+
handle: profileSlug[1],
|
|
87
|
+
slug: profileSlug[2],
|
|
88
|
+
instanceScoped: false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Instance-scoped article slug: bare `/{slug}`. Handle-shaped segments are
|
|
92
|
+
// owned by the `/:handle` profile route, so only the rest qualify.
|
|
93
|
+
const instanceSlug = /^\/([\w-]+)\/?$/.exec(pathname)?.[1];
|
|
94
|
+
if (instanceSlug &&
|
|
95
|
+
!RESERVED_TOP_LEVEL_ROUTES.includes(instanceSlug) &&
|
|
96
|
+
!isHandleShaped(instanceSlug)) {
|
|
97
|
+
return { kind: 'slug', slug: instanceSlug, instanceScoped: true };
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
19
100
|
};
|
package/dist/stats/mapping.d.ts
CHANGED
|
@@ -200,6 +200,8 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
|
|
|
200
200
|
language?: string | undefined;
|
|
201
201
|
image?: string | undefined;
|
|
202
202
|
title?: string | undefined;
|
|
203
|
+
slug?: string | undefined;
|
|
204
|
+
instanceScoped?: boolean | undefined;
|
|
203
205
|
} | {
|
|
204
206
|
type: "resource";
|
|
205
207
|
title: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"type-fest": "^4.31.0",
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
|
-
"@openpeepshq/common": "0.
|
|
40
|
+
"@openpeepshq/common": "0.28.0",
|
|
41
41
|
"@openpeepshq/fetch-client": "^0.3.0",
|
|
42
|
-
"@openpeepshq/
|
|
43
|
-
"@openpeepshq/
|
|
42
|
+
"@openpeepshq/geocoder": "^0.1.2",
|
|
43
|
+
"@openpeepshq/i18n": "^0.29.0"
|
|
44
44
|
},
|
|
45
45
|
"main": "dist/index.js",
|
|
46
46
|
"types": "dist/index.d.ts",
|