@rmdes/indiekit-endpoint-micropub 1.0.0-beta.30 → 1.0.0-beta.31

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.
@@ -58,6 +58,10 @@ export const queryController = async (request, response, next) => {
58
58
  response.json(getMf2Properties(mf2, properties));
59
59
  } else {
60
60
  // Return mf2 for published posts
61
+ const categoryParam = request.query.category;
62
+ const searchParam = request.query.search;
63
+ const hasExtraFilter = Boolean(categoryParam || searchParam);
64
+
61
65
  let cursor = {
62
66
  items: [],
63
67
  hasNext: false,
@@ -65,7 +69,39 @@ export const queryController = async (request, response, next) => {
65
69
  };
66
70
 
67
71
  if (postsCollection) {
68
- cursor = await getCursor(postsCollection, after, before, limit);
72
+ if (hasExtraFilter) {
73
+ // Filter by category and/or full-text search
74
+ // Aligns with Micropub-extensions property-value filtering
75
+ const filterQuery = {};
76
+ if (categoryParam) {
77
+ filterQuery["properties.category"] = String(categoryParam);
78
+ }
79
+ if (searchParam) {
80
+ // Escape regex special characters to prevent injection
81
+ const escaped = String(searchParam).replace(
82
+ /[.*+?^${}()|[\]\\]/g,
83
+ "\\$&",
84
+ );
85
+ filterQuery.$or = [
86
+ { "properties.name": { $regex: escaped, $options: "i" } },
87
+ { "properties.content.text": { $regex: escaped, $options: "i" } },
88
+ { "properties.content": { $regex: escaped, $options: "i" } },
89
+ ];
90
+ }
91
+ const findLimit = limit > 0 ? limit : 40;
92
+ const filteredItems = await postsCollection
93
+ .find(filterQuery)
94
+ .sort({ _id: -1 })
95
+ .limit(findLimit)
96
+ .toArray();
97
+ cursor = {
98
+ items: filteredItems,
99
+ hasNext: false,
100
+ hasPrev: false,
101
+ };
102
+ } else {
103
+ cursor = await getCursor(postsCollection, after, before, limit);
104
+ }
69
105
  }
70
106
 
71
107
  const items = [];
@@ -4,6 +4,29 @@ import { getPostTemplateProperties } from "./utils.js";
4
4
 
5
5
  const debug = makeDebug("indiekit:endpoint-micropub:post-content");
6
6
 
7
+ /**
8
+ * Call an optional lifecycle method on all registered syndicators.
9
+ * Failures are non-fatal — the Micropub operation has already succeeded.
10
+ *
11
+ * @param {object} publication - Publication config (has syndicationTargets)
12
+ * @param {string} method - Method name: 'update' | 'delete' | 'undelete'
13
+ * @param {...any} args - Arguments forwarded to the method
14
+ */
15
+ async function callSyndicatorHook(publication, method, ...args) {
16
+ const targets = publication.syndicationTargets ?? [];
17
+ await Promise.allSettled(
18
+ targets
19
+ .filter((s) => typeof s[method] === "function")
20
+ .map((s) =>
21
+ s[method](...args).catch((err) =>
22
+ debug(
23
+ `[syndicate:hook] ${method} failed for "${s.name}": ${err.message}`,
24
+ ),
25
+ ),
26
+ ),
27
+ );
28
+ }
29
+
7
30
  export const postContent = {
8
31
  /**
9
32
  * Create post
@@ -70,6 +93,8 @@ export const postContent = {
70
93
 
71
94
  delete postData._originalPath;
72
95
 
96
+ await callSyndicatorHook(publication, "update", properties, url);
97
+
73
98
  return {
74
99
  location: properties.url,
75
100
  status: hasUpdatedUrl ? 201 : 200,
@@ -103,6 +128,8 @@ export const postContent = {
103
128
 
104
129
  await store.deleteFile(path, { message });
105
130
 
131
+ await callSyndicatorHook(publication, "delete", properties.url);
132
+
106
133
  return {
107
134
  status: 200,
108
135
  json: {
@@ -135,6 +162,8 @@ export const postContent = {
135
162
 
136
163
  await store.createFile(path, content, { message });
137
164
 
165
+ await callSyndicatorHook(publication, "undelete", properties.url);
166
+
138
167
  return {
139
168
  location: properties.url,
140
169
  status: 200,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-micropub",
3
- "version": "1.0.0-beta.30",
3
+ "version": "1.0.0-beta.31",
4
4
  "description": "Micropub endpoint for Indiekit with custom type-based post discovery. Enables publishing content to your website using the Micropub protocol.",
5
5
  "keywords": [
6
6
  "indiekit",
@@ -48,6 +48,9 @@
48
48
  "newbase60": "^1.3.1",
49
49
  "turndown": "^7.1.1"
50
50
  },
51
+ "scripts": {
52
+ "test": "node --test tests/**/*.test.js"
53
+ },
51
54
  "publishConfig": {
52
55
  "access": "public"
53
56
  }