-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure_source.html
More file actions
650 lines (612 loc) · 41.4 KB
/
configure_source.html
File metadata and controls
650 lines (612 loc) · 41.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
{% extends "base.html" %}
{% block title %}Configure {{ source.name }} - Far Reach Jobs Admin{% endblock %}
{% block content %}
<div class="mb-6 flex justify-between items-center">
<div>
<h2 class="text-2xl font-bold text-gray-900 dark:text-white">Configure Source</h2>
<p class="text-gray-600 dark:text-gray-300">Set up CSS selectors for {{ source.name }}</p>
</div>
<div class="flex gap-2">
<a href="/admin" class="px-4 py-2 bg-gray-500 hover:bg-gray-600 text-white font-medium rounded-md transition-colors">
Back to Dashboard
</a>
<form method="post" action="/admin/logout">
<button type="submit" class="px-4 py-2 bg-gray-500 hover:bg-gray-600 text-white font-medium rounded-md transition-colors">
Logout
</button>
</form>
</div>
</div>
{% if error %}
<div class="bg-red-50 dark:bg-red-900/30 text-red-700 dark:text-red-200 border border-red-200 dark:border-red-800 rounded-md p-3 mb-6">
{{ error }}
</div>
{% endif %}
{% if success %}
<div class="bg-green-50 dark:bg-green-900/30 text-green-700 dark:text-green-200 border border-green-200 dark:border-green-800 rounded-md p-4 mb-6">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
<span>{{ success }}</span>
<button type="button"
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-md transition-colors flex items-center gap-2 whitespace-nowrap"
hx-post="/admin/sources/{{ source.id }}/scrape"
hx-target="#scrape-modal-result"
hx-swap="innerHTML"
onclick="showScrapeModal('{{ source.name }}', {{ 'true' if source.use_playwright or source.use_playwright is none else 'false' }})">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
Scrape Now
</button>
</div>
</div>
{% endif %}
{% if warning %}
<div class="bg-yellow-50 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-200 border border-yellow-200 dark:border-yellow-800 rounded-md p-3 mb-6">
{{ warning }}
</div>
{% endif %}
{% if api_scraper %}
<!-- API Scraper Banner -->
<div class="bg-green-50 dark:bg-green-900/20 rounded-lg border-2 border-green-300 dark:border-green-700 p-6 mb-6">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div class="flex items-start gap-3">
<div class="flex-shrink-0 w-10 h-10 bg-green-100 dark:bg-green-800 rounded-full flex items-center justify-center">
<svg class="w-6 h-6 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
</div>
<div>
<h3 class="text-lg font-semibold text-green-800 dark:text-green-200 flex items-center gap-2">
{{ api_scraper.name }} Detected
<span class="px-2 py-0.5 text-xs font-medium bg-green-200 dark:bg-green-700 text-green-800 dark:text-green-200 rounded-full">Auto-configured</span>
</h3>
<p class="text-sm text-green-700 dark:text-green-300 mt-1">
{{ api_scraper.description }}
</p>
</div>
</div>
<button type="button"
class="px-5 py-3 bg-green-600 hover:bg-green-700 text-white font-medium rounded-lg transition-colors flex items-center gap-2 whitespace-nowrap shadow-sm"
hx-post="/admin/sources/{{ source.id }}/scrape"
hx-target="#scrape-modal-result"
hx-swap="innerHTML"
onclick="showScrapeModal('{{ source.name }}', {{ 'true' if source.use_playwright or source.use_playwright is none else 'false' }})">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"></path>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
Run Scraper Now
</button>
</div>
</div>
{% else %}
<!-- Check if scraper is ready to run (has required configuration) -->
{% set is_configured = (source.scraper_class == 'GenericScraper' and source.selector_job_container and source.selector_title and source.selector_url) or (source.scraper_class == 'SitemapScraper' and source.sitemap_url) or (source.scraper_class == 'DynamicScraper' and source.custom_scraper_code) %}
{% if is_configured %}
<!-- Ready to Scrape Banner -->
<div class="bg-blue-50 dark:bg-blue-900/20 rounded-lg border-2 border-blue-300 dark:border-blue-700 p-6 mb-6">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div class="flex items-start gap-3">
<div class="flex-shrink-0 w-10 h-10 bg-blue-100 dark:bg-blue-800 rounded-full flex items-center justify-center">
<svg class="w-6 h-6 text-blue-600 dark:text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
<div>
<h3 class="text-lg font-semibold text-blue-800 dark:text-blue-200 flex items-center gap-2">
Scraper Configured
<span class="px-2 py-0.5 text-xs font-medium bg-blue-200 dark:bg-blue-700 text-blue-800 dark:text-blue-200 rounded-full">Ready</span>
</h3>
<p class="text-sm text-blue-700 dark:text-blue-300 mt-1">
{% if source.scraper_class == 'SitemapScraper' %}
Sitemap scraper is configured and ready to run.
{% elif source.scraper_class == 'DynamicScraper' %}
Custom scraper code is configured and ready to run.
{% else %}
CSS selectors are configured. Run a scrape to test the configuration.
{% endif %}
</p>
</div>
</div>
<button type="button"
class="px-5 py-3 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors flex items-center gap-2 whitespace-nowrap shadow-sm"
hx-post="/admin/sources/{{ source.id }}/scrape"
hx-target="#scrape-modal-result"
hx-swap="innerHTML"
onclick="showScrapeModal('{{ source.name }}', {{ 'true' if source.use_playwright or source.use_playwright is none else 'false' }})">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"></path>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
Run Scraper Now
</button>
</div>
</div>
{% endif %}
<!-- AI Analysis Section (only for non-API scrapers) -->
<div class="bg-purple-50 dark:bg-purple-900/20 rounded-lg border border-purple-200 dark:border-purple-800 p-6 mb-6">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div>
<h3 class="text-lg font-semibold text-purple-800 dark:text-purple-200 flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"></path>
</svg>
AI-Powered Selector Detection
</h3>
<p class="text-sm text-purple-700 dark:text-purple-300 mt-1">
{% if is_configured %}
Re-analyze to update selectors if the page structure has changed
{% else %}
Let AI analyze the job listings page and suggest CSS selectors automatically
{% endif %}
</p>
</div>
<button type="button" id="analyze-btn"
hx-post="/admin/sources/{{ source.id }}/analyze"
hx-target="#ai-results"
hx-swap="innerHTML"
hx-timeout="60000"
class="px-4 py-2 bg-purple-600 hover:bg-purple-700 text-white font-medium rounded-md transition-colors flex items-center gap-2 whitespace-nowrap disabled:opacity-50 disabled:cursor-not-allowed">
<svg class="w-4 h-4 hidden animate-spin" id="analyze-spinner" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<span id="analyze-text">Analyze Page with AI</span>
</button>
</div>
<!-- Loading state shown while analyzing -->
<div id="ai-loading" class="hidden mt-4">
<div class="bg-white dark:bg-gray-800 rounded-lg border border-purple-200 dark:border-purple-700 p-8">
<div class="flex flex-col items-center justify-center gap-4">
<div class="relative">
<div class="w-16 h-16 border-4 border-purple-200 dark:border-purple-800 rounded-full"></div>
<div class="absolute top-0 left-0 w-16 h-16 border-4 border-purple-600 rounded-full animate-spin border-t-transparent"></div>
</div>
<div class="text-center">
<p class="text-lg font-medium text-purple-800 dark:text-purple-200">Analyzing page structure...</p>
<p class="text-sm text-purple-600 dark:text-purple-400 mt-1">This may take 10-30 seconds</p>
</div>
</div>
</div>
</div>
<div id="ai-results" class="mt-4"></div>
</div>
{% endif %}
<form method="post" action="/admin/sources/{{ source.id }}/configure" class="space-y-6">
<!-- Basic Info -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 transition-colors">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-4">
<h3 class="text-lg font-semibold dark:text-white">Basic Information</h3>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="name" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Source Name</label>
<input type="text" id="name" name="name" required value="{{ source.name }}"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white">
</div>
<div>
<label for="base_url" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Base URL</label>
<input type="url" id="base_url" name="base_url" required value="{{ source.base_url }}"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Main website URL (used for robots.txt and relative links)</p>
</div>
</div>
<div class="mt-4">
<label for="listing_url" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Job Listings Page URL(s)</label>
<textarea id="listing_url" name="listing_url" rows="3" placeholder="{{ source.base_url }}"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">{{ source.listing_url or '' }}</textarea>
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">URL(s) of pages containing job listings. One URL per line for multiple pages (e.g., certified and classified positions). Leave blank to use Base URL.</p>
</div>
<div class="mt-4">
<label for="default_location" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Default Location</label>
<input type="text" id="default_location" name="default_location" value="{{ source.default_location or '' }}"
placeholder="e.g., Bethel, Kotzebue, Nome"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Fallback location when jobs don't have location info. Used for filtering by city/community.</p>
</div>
<div class="mt-4">
<label for="default_state" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Default State</label>
<input type="text" id="default_state" name="default_state" value="{{ source.default_state or '' }}"
placeholder="e.g., AK, WA, CA"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Fallback state code when jobs don't have state info. Applied to location display (e.g., "Bethel, AK").</p>
</div>
</div>
<!-- Scraper Type -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 transition-colors">
<h3 class="text-lg font-semibold dark:text-white mb-2">Scraper Type</h3>
<p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
Choose how this source should be scraped.
</p>
<div>
<label for="scraper_class" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Scraper Type</label>
<select id="scraper_class" name="scraper_class"
onchange="toggleScraperSections()"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white">
<option value="GenericScraper" {% if source.scraper_class == 'GenericScraper' %}selected{% endif %}>Generic (CSS Selectors)</option>
<option value="SitemapScraper" {% if source.scraper_class == 'SitemapScraper' %}selected{% endif %}>Sitemap (XML URL Parsing)</option>
<option value="DynamicScraper" {% if source.scraper_class == 'DynamicScraper' %}selected{% endif %}>Dynamic (AI-Generated Custom Code)</option>
</select>
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">
<strong>Generic:</strong> Uses CSS selectors to extract jobs from HTML pages.<br>
<strong>Sitemap:</strong> Extracts jobs from XML sitemaps. Best for JS-heavy sites with sitemaps.<br>
<strong>Dynamic:</strong> Uses AI-generated custom scraper code. Only use if others don't work.
</p>
</div>
<div class="mt-4">
<label class="flex items-center gap-3 cursor-pointer">
<input type="checkbox" id="use_playwright" name="use_playwright" value="1"
{% if source.use_playwright is not none %}{% if source.use_playwright %}checked{% endif %}{% else %}checked{% endif %}
class="w-4 h-4 text-blue-600 bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded focus:ring-blue-500 focus:ring-2">
<span class="text-sm font-medium text-gray-700 dark:text-gray-300">Use Playwright (Headless Browser)</span>
</label>
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1 ml-7">
Enabled by default. Uses a real browser to render JavaScript-heavy pages. Disable only for simple static HTML sites.
</p>
</div>
</div>
<!-- Sitemap Configuration (shown when SitemapScraper selected) -->
<div id="sitemap-config" class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 transition-colors {% if source.scraper_class != 'SitemapScraper' %}hidden{% endif %}">
<h3 class="text-lg font-semibold dark:text-white mb-2">Sitemap Configuration</h3>
<p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
Configure how to extract jobs from the XML sitemap. Job details are parsed from URL structure.
</p>
<div class="space-y-4">
<div>
<label for="sitemap_url" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Sitemap URL <span class="text-red-500">*</span>
</label>
<input type="url" id="sitemap_url" name="sitemap_url" value="{{ source.sitemap_url or '' }}"
placeholder="https://example.com/sitemaps/jobs.xml"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">URL of the XML sitemap containing job URLs (check /sitemap.xml or /robots.txt for sitemap locations)</p>
</div>
<div>
<label for="sitemap_url_pattern" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
URL Filter Pattern
</label>
<input type="text" id="sitemap_url_pattern" name="sitemap_url_pattern" value="{{ source.sitemap_url_pattern or '' }}"
placeholder="-ak/|-AK/"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Regex pattern to filter URLs (e.g., "-ak/" for Alaska jobs only). Leave blank for all jobs.</p>
</div>
<div>
<label for="organization" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Organization Name
</label>
<input type="text" id="organization" name="organization" value="{{ source.organization or '' }}"
placeholder="e.g., Alaska Airlines"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Organization name for all jobs. If blank, uses source name.</p>
</div>
</div>
<div class="mt-4 bg-blue-50 dark:bg-blue-900/30 rounded-lg border border-blue-200 dark:border-blue-800 p-4">
<h4 class="font-medium text-blue-800 dark:text-blue-200 mb-2">How Sitemap Scraper Works</h4>
<ul class="list-disc list-inside text-sm text-blue-700 dark:text-blue-300 space-y-1">
<li>Fetches XML sitemap and extracts all job URLs</li>
<li>Filters URLs by pattern (if configured)</li>
<li>Parses job title and location from URL structure</li>
<li>Example: <code class="bg-blue-100 dark:bg-blue-800 px-1 rounded text-xs">/kotzebue-ak/customer-service-agent/</code> → Title: "Customer Service Agent", Location: "Kotzebue, AK"</li>
<li>No JavaScript rendering needed - fast and reliable</li>
</ul>
</div>
</div>
<!-- Required Selectors (hidden when SitemapScraper selected) -->
<div id="css-selectors-required" class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 transition-colors {% if source.scraper_class == 'SitemapScraper' %}hidden{% endif %}">
<h3 class="text-lg font-semibold dark:text-white mb-2">Required CSS Selectors</h3>
<p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
These selectors are required for the scraper to find jobs. Use browser DevTools to inspect the page structure.
</p>
<div class="space-y-4">
<div>
<label for="selector_job_container" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Job Container Selector <span class="text-red-500">*</span>
</label>
<input type="text" id="selector_job_container" name="selector_job_container" value="{{ source.selector_job_container or '' }}"
placeholder=".job-card, tr.job-row, article.listing"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Selector for the repeating element containing each job listing</p>
</div>
<div>
<label for="selector_title" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Title Selector <span class="text-red-500">*</span>
</label>
<input type="text" id="selector_title" name="selector_title" value="{{ source.selector_title or '' }}"
placeholder=".job-title, h2 a, .title"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Selector for the job title within each container</p>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="selector_url" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
URL Link Selector <span class="text-red-500">*</span>
</label>
<input type="text" id="selector_url" name="selector_url" value="{{ source.selector_url or '' }}"
placeholder="a.job-link, h2 a, a[href]"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Selector for the link element</p>
</div>
<div>
<label for="url_attribute" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">URL Attribute</label>
<input type="text" id="url_attribute" name="url_attribute" value="{{ source.url_attribute or 'href' }}"
placeholder="href"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Attribute containing the URL (usually "href")</p>
</div>
</div>
</div>
</div>
<!-- Optional Selectors (hidden when SitemapScraper selected) -->
<div id="css-selectors-optional" class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 transition-colors {% if source.scraper_class == 'SitemapScraper' %}hidden{% endif %}">
<h3 class="text-lg font-semibold dark:text-white mb-2">Optional CSS Selectors</h3>
<p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
These fields are optional but help provide more complete job information.
</p>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="selector_organization" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Organization Selector</label>
<input type="text" id="selector_organization" name="selector_organization" value="{{ source.selector_organization or '' }}"
placeholder=".company-name, .employer"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
</div>
<div>
<label for="selector_location" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Location Selector</label>
<input type="text" id="selector_location" name="selector_location" value="{{ source.selector_location or '' }}"
placeholder=".location, .job-location"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
</div>
<div>
<label for="selector_job_type" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Job Type Selector</label>
<input type="text" id="selector_job_type" name="selector_job_type" value="{{ source.selector_job_type or '' }}"
placeholder=".job-type, .employment-type"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
</div>
<div>
<label for="selector_salary" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Salary Selector</label>
<input type="text" id="selector_salary" name="selector_salary" value="{{ source.selector_salary or '' }}"
placeholder=".salary, .compensation"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
</div>
<div class="sm:col-span-2">
<label for="selector_description" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Description Selector</label>
<input type="text" id="selector_description" name="selector_description" value="{{ source.selector_description or '' }}"
placeholder=".job-description, .summary"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
</div>
</div>
</div>
<!-- Pagination (hidden when SitemapScraper selected) -->
<div id="css-selectors-pagination" class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 transition-colors {% if source.scraper_class == 'SitemapScraper' %}hidden{% endif %}">
<h3 class="text-lg font-semibold dark:text-white mb-2">Pagination (Optional)</h3>
<p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
Configure these if jobs span multiple pages.
</p>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="selector_next_page" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Next Page Selector</label>
<input type="text" id="selector_next_page" name="selector_next_page" value="{{ source.selector_next_page or '' }}"
placeholder="a.next-page, .pagination a[rel='next']"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white dark:placeholder-gray-500 font-mono text-sm">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Selector for the "next page" link</p>
</div>
<div>
<label for="max_pages" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Max Pages</label>
<input type="number" id="max_pages" name="max_pages" value="{{ source.max_pages or 10 }}" min="1" max="100"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-white dark:bg-gray-700 dark:text-white">
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">Maximum number of pages to scrape (1-100)</p>
</div>
</div>
</div>
<!-- Actions -->
<div class="flex gap-4">
<button type="submit" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-md transition-colors">
Save Configuration
</button>
<a href="/admin" class="px-6 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 font-medium rounded-md transition-colors">
Cancel
</a>
</div>
</form>
<!-- Scrape Modal -->
<div id="scrape-modal" class="hidden fixed inset-0 z-50 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true">
<div class="flex items-center justify-center min-h-screen px-4 pt-4 pb-20 text-center sm:p-0">
<!-- Background overlay -->
<div class="fixed inset-0 bg-gray-500 dark:bg-gray-900 bg-opacity-75 dark:bg-opacity-75 transition-opacity" onclick="closeScrapeModal()"></div>
<!-- Modal panel -->
<div class="relative inline-block align-bottom bg-white dark:bg-gray-800 rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-md sm:w-full sm:p-6">
<!-- Loading state -->
<div id="scrape-modal-loading">
<div class="flex flex-col items-center justify-center py-8">
<div class="relative">
<div class="w-16 h-16 border-4 border-blue-200 dark:border-blue-800 rounded-full"></div>
<div class="absolute top-0 left-0 w-16 h-16 border-4 border-blue-600 rounded-full animate-spin border-t-transparent"></div>
</div>
<p class="mt-4 text-lg font-medium text-gray-900 dark:text-white">Running scraper...</p>
<p id="scrape-modal-source" class="mt-1 text-sm text-gray-500 dark:text-gray-400"></p>
<p id="scrape-modal-playwright" class="mt-2 text-xs text-gray-400 dark:text-gray-500"></p>
</div>
</div>
<!-- Results will be loaded here -->
<div id="scrape-modal-result"></div>
</div>
</div>
</div>
<!-- Help Section -->
<div class="mt-8 bg-blue-50 dark:bg-blue-900/30 rounded-lg border border-blue-200 dark:border-blue-800 p-6">
<h3 class="text-lg font-semibold text-blue-800 dark:text-blue-200 mb-2">How to Find CSS Selectors</h3>
<ol class="list-decimal list-inside space-y-2 text-sm text-blue-700 dark:text-blue-300">
<li>Open the job listings page in your browser</li>
<li>Right-click on a job listing and select "Inspect" or press F12</li>
<li>Find the HTML element that wraps each job - this is your <strong>Job Container</strong></li>
<li>Within that container, find elements for title, link, location, etc.</li>
<li>Use CSS selectors like <code class="bg-blue-100 dark:bg-blue-800 px-1 rounded">.class-name</code>, <code class="bg-blue-100 dark:bg-blue-800 px-1 rounded">#id</code>, or <code class="bg-blue-100 dark:bg-blue-800 px-1 rounded">tag.class</code></li>
</ol>
<div class="mt-4">
<h4 class="font-medium text-blue-800 dark:text-blue-200 mb-1">Example Selectors:</h4>
<ul class="list-disc list-inside text-sm text-blue-700 dark:text-blue-300 space-y-1">
<li><code class="bg-blue-100 dark:bg-blue-800 px-1 rounded">.job-listing</code> - selects elements with class "job-listing"</li>
<li><code class="bg-blue-100 dark:bg-blue-800 px-1 rounded">h2.title a</code> - selects links inside h2 elements with class "title"</li>
<li><code class="bg-blue-100 dark:bg-blue-800 px-1 rounded">[data-job-id]</code> - selects elements with a data-job-id attribute</li>
<li><code class="bg-blue-100 dark:bg-blue-800 px-1 rounded">tr.job-row td:nth-child(2)</code> - selects the 2nd column of table rows</li>
</ul>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
// Toggle scraper-specific configuration sections
function toggleScraperSections() {
const scraperClass = document.getElementById('scraper_class').value;
const sitemapConfig = document.getElementById('sitemap-config');
const cssRequired = document.getElementById('css-selectors-required');
const cssOptional = document.getElementById('css-selectors-optional');
const cssPagination = document.getElementById('css-selectors-pagination');
if (scraperClass === 'SitemapScraper') {
sitemapConfig.classList.remove('hidden');
cssRequired.classList.add('hidden');
cssOptional.classList.add('hidden');
cssPagination.classList.add('hidden');
} else {
sitemapConfig.classList.add('hidden');
cssRequired.classList.remove('hidden');
cssOptional.classList.remove('hidden');
cssPagination.classList.remove('hidden');
}
}
(function() {
const analyzeBtn = document.getElementById('analyze-btn');
const analyzeSpinner = document.getElementById('analyze-spinner');
const analyzeText = document.getElementById('analyze-text');
const loadingDiv = document.getElementById('ai-loading');
const resultsDiv = document.getElementById('ai-results');
// Scrape modal functions
window.showScrapeModal = function(sourceName, usePlaywright) {
const modal = document.getElementById('scrape-modal');
const loadingDiv = document.getElementById('scrape-modal-loading');
const resultDiv = document.getElementById('scrape-modal-result');
const sourceText = document.getElementById('scrape-modal-source');
const playwrightText = document.getElementById('scrape-modal-playwright');
// Reset state
loadingDiv.classList.remove('hidden');
resultDiv.innerHTML = '';
sourceText.textContent = sourceName || '';
if (playwrightText) {
playwrightText.textContent = usePlaywright ? 'Using Playwright (browser)' : 'Using httpx (fast)';
}
// Show modal
modal.classList.remove('hidden');
document.body.style.overflow = 'hidden';
};
window.closeScrapeModal = function() {
const modal = document.getElementById('scrape-modal');
modal.classList.add('hidden');
document.body.style.overflow = '';
};
window.onScrapeComplete = function() {
// Hide loading, show results
const loadingDiv = document.getElementById('scrape-modal-loading');
loadingDiv.classList.add('hidden');
};
// Handle Escape key to close modal
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
const modal = document.getElementById('scrape-modal');
if (!modal.classList.contains('hidden')) {
closeScrapeModal();
}
}
});
// Hide loading spinner when scrape completes (HTMX swap into modal result)
document.body.addEventListener('htmx:afterSwap', function(event) {
if (event.detail.target.id === 'scrape-modal-result') {
onScrapeComplete();
}
});
// Show loading state when analysis starts
document.body.addEventListener('htmx:beforeRequest', function(event) {
if (event.detail.elt.id === 'analyze-btn') {
analyzeBtn.disabled = true;
analyzeSpinner.classList.remove('hidden');
analyzeText.textContent = 'Analyzing...';
loadingDiv.classList.remove('hidden');
resultsDiv.innerHTML = '';
}
});
// Hide loading state when analysis completes
document.body.addEventListener('htmx:afterSwap', function(event) {
if (event.detail.target.id === 'ai-results') {
analyzeBtn.disabled = false;
analyzeSpinner.classList.add('hidden');
analyzeText.textContent = 'Analyze Page with AI';
loadingDiv.classList.add('hidden');
}
});
// Reset UI state helper
function resetAnalyzeUI() {
analyzeBtn.disabled = false;
analyzeSpinner.classList.add('hidden');
analyzeText.textContent = 'Analyze Page with AI';
loadingDiv.classList.add('hidden');
}
// Show error message helper
function showError(message) {
resultsDiv.innerHTML = `
<div class="bg-red-50 dark:bg-red-900/30 text-red-700 dark:text-red-200 border border-red-200 dark:border-red-800 rounded-md p-4">
<div class="flex items-center gap-2">
<svg class="w-5 h-5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span><strong>Error:</strong> ${message}</span>
</div>
</div>`;
}
// Handle HTTP errors (4xx, 5xx)
document.body.addEventListener('htmx:responseError', function(event) {
if (event.detail.target.id === 'ai-results') {
resetAnalyzeUI();
showError('Server returned an error. Please try again.');
}
});
// Handle network errors (connection failed, CORS, etc.)
document.body.addEventListener('htmx:sendError', function(event) {
if (event.detail.target.id === 'ai-results') {
resetAnalyzeUI();
showError('Network error. Please check your connection and try again.');
}
});
// Handle timeouts
document.body.addEventListener('htmx:timeout', function(event) {
if (event.detail.target.id === 'ai-results') {
resetAnalyzeUI();
showError('Request timed out. The page may be too complex to analyze.');
}
});
// Apply selector value to target form field
function applySelector(button) {
const targetId = button.dataset.target;
const codeEl = button.parentElement.querySelector('.selector-value');
const field = document.getElementById(targetId);
if (field && codeEl) {
field.value = codeEl.textContent.trim();
field.classList.add('ring-2', 'ring-purple-500');
setTimeout(() => field.classList.remove('ring-2', 'ring-purple-500'), 1500);
// Scroll field into view
field.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
// Use event delegation for Apply buttons (works for dynamically added content)
document.body.addEventListener('click', function(event) {
// Handle individual Apply buttons
if (event.target.classList.contains('apply-btn')) {
event.preventDefault();
applySelector(event.target);
}
// Handle Apply All button
if (event.target.id === 'apply-all-btn' || event.target.closest('#apply-all-btn')) {
event.preventDefault();
document.querySelectorAll('#ai-results .apply-btn').forEach(btn => applySelector(btn));
}
});
})();
</script>
{% endblock %}