@rmdes/indiekit-endpoint-blogroll 1.0.11 → 1.0.12

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.
@@ -249,12 +249,14 @@ function sanitizeBlog(blog) {
249
249
  * @returns {object} Sanitized item
250
250
  */
251
251
  function sanitizeItem(item) {
252
+ const published = item.published ? new Date(item.published) : null;
252
253
  return {
253
254
  id: item._id.toString(),
254
255
  url: item.url,
255
256
  title: item.title,
256
257
  summary: item.summary,
257
258
  published: item.published,
259
+ isFuture: published ? published > new Date() : false,
258
260
  author: item.author,
259
261
  photo: item.photo,
260
262
  categories: item.categories,
package/lib/sync/feed.js CHANGED
@@ -134,14 +134,14 @@ function parseJsonFeed(content, feedUrl, maxItems) {
134
134
  const items = (feed.items || []).slice(0, maxItems).map((item) => ({
135
135
  uid: generateUid(feedUrl, item.id || item.url),
136
136
  url: item.url || item.external_url,
137
- title: item.title || "Untitled",
137
+ title: decodeEntities(item.title) || "Untitled",
138
138
  content: {
139
139
  html: item.content_html
140
140
  ? sanitizeHtml(item.content_html, SANITIZE_OPTIONS)
141
141
  : undefined,
142
142
  text: item.content_text,
143
143
  },
144
- summary: item.summary || truncateText(item.content_text, 300),
144
+ summary: decodeEntities(item.summary) || truncateText(item.content_text, 300),
145
145
  published: item.date_published ? new Date(item.date_published) : new Date(),
146
146
  updated: item.date_modified ? new Date(item.date_modified) : undefined,
147
147
  author: item.author || (item.authors?.[0]),
@@ -171,7 +171,7 @@ function normalizeItem(item, feedUrl) {
171
171
  return {
172
172
  uid: generateUid(feedUrl, item.guid || item.link),
173
173
  url: item.link || item.origlink,
174
- title: item.title || "Untitled",
174
+ title: decodeEntities(item.title) || "Untitled",
175
175
  content: {
176
176
  html: description ? sanitizeHtml(description, SANITIZE_OPTIONS) : undefined,
177
177
  text: stripHtml(description),
@@ -200,16 +200,37 @@ function generateUid(feedUrl, itemId) {
200
200
  }
201
201
 
202
202
  /**
203
- * Strip HTML tags from string
203
+ * Strip HTML tags and decode HTML entities from string
204
204
  * @param {string} html - HTML string
205
205
  * @returns {string} Plain text
206
206
  */
207
207
  function stripHtml(html) {
208
208
  if (!html) return "";
209
- return html
210
- .replace(/<[^>]*>/g, " ")
211
- .replace(/\s+/g, " ")
212
- .trim();
209
+ return decodeEntities(
210
+ html
211
+ .replace(/<[^>]*>/g, " ")
212
+ .replace(/\s+/g, " ")
213
+ .trim()
214
+ );
215
+ }
216
+
217
+ /**
218
+ * Decode HTML entities to their character equivalents
219
+ * @param {string} str - String with HTML entities
220
+ * @returns {string} Decoded string
221
+ */
222
+ function decodeEntities(str) {
223
+ if (!str) return "";
224
+ return str
225
+ .replace(/&amp;/g, "&")
226
+ .replace(/&lt;/g, "<")
227
+ .replace(/&gt;/g, ">")
228
+ .replace(/&quot;/g, '"')
229
+ .replace(/&apos;/g, "'")
230
+ .replace(/&#39;/g, "'")
231
+ .replace(/&#x27;/g, "'")
232
+ .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code)))
233
+ .replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16)));
213
234
  }
214
235
 
215
236
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-blogroll",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Blogroll endpoint for Indiekit. Aggregates blog feeds from OPML, JSON feeds, or manual entry.",
5
5
  "keywords": [
6
6
  "indiekit",