@rmdes/indiekit-endpoint-microsub 1.0.35 → 1.0.37

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.
@@ -35,6 +35,7 @@ import {
35
35
  validateExcludeTypes,
36
36
  validateExcludeRegex,
37
37
  } from "../utils/validation.js";
38
+ import { proxyItemImages } from "../media/proxy.js";
38
39
 
39
40
  /**
40
41
  * Reader index - redirect to channels
@@ -119,6 +120,14 @@ export async function channel(request, response) {
119
120
  showRead: showReadItems,
120
121
  });
121
122
 
123
+ // Proxy images through media endpoint for privacy
124
+ const proxyBaseUrl = application.url;
125
+ if (proxyBaseUrl && timeline.items) {
126
+ timeline.items = timeline.items.map((item) =>
127
+ proxyItemImages(item, proxyBaseUrl),
128
+ );
129
+ }
130
+
122
131
  // Count read items to show "View read items" button
123
132
  const readCount = await countReadItems(
124
133
  application,
@@ -12,6 +12,27 @@ import {
12
12
  parseLimit,
13
13
  } from "../utils/pagination.js";
14
14
 
15
+ /**
16
+ * Extract image URLs from HTML content (fallback for items without explicit photos)
17
+ * @param {string} html - HTML content
18
+ * @returns {string[]} Array of image URLs
19
+ */
20
+ function extractImagesFromHtml(html) {
21
+ if (!html) {
22
+ return [];
23
+ }
24
+ const urls = [];
25
+ const imgRegex = /<img[^>]+src=["']([^"']+)["'][^>]*>/gi;
26
+ let match;
27
+ while ((match = imgRegex.exec(html)) !== null) {
28
+ const src = match[1];
29
+ if (src && !urls.includes(src)) {
30
+ urls.push(src);
31
+ }
32
+ }
33
+ return urls;
34
+ }
35
+
15
36
  /**
16
37
  * Get items collection from application
17
38
  * @param {object} application - Indiekit application
@@ -201,6 +222,14 @@ function transformToJf2(item, userId) {
201
222
  const videos = normalizeMediaArray(item.video);
202
223
  const audios = normalizeMediaArray(item.audio);
203
224
 
225
+ // Fallback: extract images from HTML content if no explicit photos
226
+ if (photos.length === 0 && item.content?.html) {
227
+ const extracted = extractImagesFromHtml(item.content.html);
228
+ if (extracted.length > 0) {
229
+ photos.push(...extracted);
230
+ }
231
+ }
232
+
204
233
  if (photos.length > 0) jf2.photo = photos;
205
234
  if (videos.length > 0) jf2.video = videos;
206
235
  if (audios.length > 0) jf2.audio = audios;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-microsub",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "Microsub endpoint for Indiekit. Enables subscribing to feeds and reading content using the Microsub protocol.",
5
5
  "keywords": [
6
6
  "indiekit",
package/views/actor.njk CHANGED
@@ -121,8 +121,10 @@
121
121
  {# Tags #}
122
122
  {% if item.category and item.category.length > 0 %}
123
123
  <div class="item-card__categories">
124
- {% for cat in item.category | slice(0, 5) %}
124
+ {% for cat in item.category %}
125
+ {% if loop.index0 < 5 %}
125
126
  <span class="item-card__category">#{{ cat }}</span>
127
+ {% endif %}
126
128
  {% endfor %}
127
129
  </div>
128
130
  {% endif %}
@@ -131,9 +133,11 @@
131
133
  {% if item.photo and item.photo.length > 0 %}
132
134
  {% set photoCount = item.photo.length if item.photo.length <= 4 else 4 %}
133
135
  <div class="item-card__photos item-card__photos--{{ photoCount }}">
134
- {% for photo in item.photo | slice(0, 4) %}
136
+ {% for photo in item.photo %}
137
+ {% if loop.index0 < 4 %}
135
138
  <img src="{{ photo }}" alt="" class="item-card__photo" loading="lazy"
136
139
  onerror="this.parentElement.removeChild(this)">
140
+ {% endif %}
137
141
  {% endfor %}
138
142
  </div>
139
143
  {% endif %}
@@ -111,8 +111,10 @@
111
111
  {# Categories/Tags #}
112
112
  {% if item.category and item.category.length > 0 %}
113
113
  <div class="item-card__categories">
114
- {% for cat in item.category | slice(0, 5) %}
114
+ {% for cat in item.category %}
115
+ {% if loop.index0 < 5 %}
115
116
  <span class="item-card__category">#{{ cat | replace("#", "") }}</span>
117
+ {% endif %}
116
118
  {% endfor %}
117
119
  </div>
118
120
  {% endif %}
@@ -121,12 +123,14 @@
121
123
  {% if item.photo and item.photo.length > 0 %}
122
124
  {% set photoCount = item.photo.length if item.photo.length <= 4 else 4 %}
123
125
  <div class="item-card__photos item-card__photos--{{ photoCount }}">
124
- {% for photo in item.photo | slice(0, 4) %}
126
+ {% for photo in item.photo %}
127
+ {% if loop.index0 < 4 %}
125
128
  <img src="{{ photo }}"
126
129
  alt=""
127
130
  class="item-card__photo"
128
131
  loading="lazy"
129
132
  onerror="this.parentElement.removeChild(this)">
133
+ {% endif %}
130
134
  {% endfor %}
131
135
  </div>
132
136
  {% endif %}