|
11 | 11 | (function() { |
12 | 12 | 'use strict'; |
13 | 13 |
|
| 14 | + // Default prompt for generating summaries |
| 15 | + const DEFAULT_PROMPT = 'Write a short, witty one-sentence summary of this hack day (max 10 words):'; |
| 16 | + |
14 | 17 | // Store parsed feed items for reuse |
15 | 18 | let feedItems = null; |
16 | 19 | // Store the language model session |
@@ -126,18 +129,27 @@ Don't use emojis. Don't start with "A" or "The".` |
126 | 129 | * @returns {HTMLElement|null} |
127 | 130 | */ |
128 | 131 | function findTaglineElement(url) { |
129 | | - // Extract the path from the URL (e.g., "/hacks/50/" from "https://remotehack.space/hacks/50/") |
130 | | - const urlPath = new URL(url).pathname; |
131 | | - |
132 | | - // Find the link that matches this path |
133 | | - const links = document.querySelectorAll('.past-events a'); |
134 | | - for (const link of links) { |
135 | | - const linkPath = new URL(link.href).pathname; |
136 | | - if (linkPath === urlPath) { |
137 | | - // Find the tagline element within the same list item |
138 | | - const li = link.closest('li'); |
139 | | - return li?.querySelector('.hack-tagline'); |
| 132 | + // Validate URL before processing |
| 133 | + if (!url || typeof url !== 'string') { |
| 134 | + return null; |
| 135 | + } |
| 136 | + |
| 137 | + try { |
| 138 | + // Extract the path from the URL (e.g., "/hacks/50/" from "https://remotehack.space/hacks/50/") |
| 139 | + const urlPath = new URL(url).pathname; |
| 140 | + |
| 141 | + // Find the link that matches this path |
| 142 | + const links = document.querySelectorAll('.past-events a'); |
| 143 | + for (const link of links) { |
| 144 | + const linkPath = new URL(link.href).pathname; |
| 145 | + if (linkPath === urlPath) { |
| 146 | + // Find the tagline element within the same list item |
| 147 | + const li = link.closest('li'); |
| 148 | + return li?.querySelector('.hack-tagline'); |
| 149 | + } |
140 | 150 | } |
| 151 | + } catch (error) { |
| 152 | + console.warn('[Prompt API] Invalid URL in feed item:', url); |
141 | 153 | } |
142 | 154 | return null; |
143 | 155 | } |
@@ -177,7 +189,7 @@ Content: ${item.description}`; |
177 | 189 | * Update all taglines on the page with generated summaries |
178 | 190 | * @param {string} prompt - The prompt to use for generation |
179 | 191 | */ |
180 | | - async function updateTaglines(prompt = 'Write a short, witty one-sentence summary of this hack day (max 10 words):') { |
| 192 | + async function updateTaglines(prompt = DEFAULT_PROMPT) { |
181 | 193 | const available = await isPromptAPIAvailable(); |
182 | 194 | if (!available) { |
183 | 195 | console.info('[Prompt API] Skipping tagline updates - API not available'); |
|
0 commit comments