Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 3x 3x 3x 30x 3x 15x 3x 3x 3x 9x 9x 12x 9x 3x | import React from "react";
import {
WEB_FEED_CONTENT,
WEB_LIMITS,
WEB_REFRESH,
WEB_SCOPES,
WebSourceForm,
} from "./webSource";
const inputBase =
"w-full px-3 py-2 text-sm rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 dark:focus:ring-gray-500 transition-colors";
const errorBase =
"w-full px-3 py-2 text-sm rounded-lg border border-red-300 dark:border-red-700 bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-red-200 dark:focus:ring-red-900 transition-colors";
const Label: React.FC<{
htmlFor?: string;
label: string;
description?: string;
required?: boolean;
}> = ({ htmlFor, label, description, required }) => (
<div className="mb-1.5">
<label
htmlFor={htmlFor}
className="text-sm font-medium text-gray-700 dark:text-gray-300"
>
{label}
{required && <span className="ml-0.5 text-red-500">*</span>}
</label>
{description && (
<p className="text-xs text-gray-400 dark:text-gray-500 mt-0.5">
{description}
</p>
)}
</div>
);
const FieldError: React.FC<{ message?: string }> = ({ message }) =>
message ? <p className="text-xs text-red-500 mt-1">{message}</p> : null;
/**
* What a website source crawls, how far, and how often. Used by both the
* New and Edit pages; the stored shape is `webConfigFromForm`'s.
*/
const WebSourceConfigForm: React.FC<{
config: WebSourceForm;
onChange: (c: WebSourceForm) => void;
errors: Partial<Record<keyof WebSourceForm, string>>;
}> = ({ config, onChange, errors }) => {
const set = <K extends keyof WebSourceForm>(
key: K,
value: WebSourceForm[K],
) => onChange({ ...config, [key]: value });
return (
<div className="space-y-5">
<div>
<Label
htmlFor="web-urls"
label="URLs"
description="One https:// URL per line — pages, sitemaps or RSS / Atom feeds. Every page keeps a snapshot each time its text changes."
required
/>
<textarea
id="web-urls"
value={config.urls}
onChange={(e) => set("urls", e.target.value)}
placeholder={
"e.g.\nhttps://docs.example.com/guide\nhttps://example.com/sitemap.xml"
}
rows={4}
className={
(errors.urls ? errorBase : inputBase) +
" resize-none font-mono text-xs"
}
/>
<FieldError message={errors.urls} />
</div>
<fieldset>
<legend className="text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5">
What to crawl
</legend>
<div className="grid gap-2 sm:grid-cols-3">
{WEB_SCOPES.map((scope) => {
const selected = config.scope === scope.value;
return (
<label
key={scope.value}
className={`flex cursor-pointer flex-col gap-1 rounded-lg border px-3 py-2.5 transition-colors ${
selected
? "border-gray-900 dark:border-gray-100 bg-gray-50 dark:bg-gray-800"
: "border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"
}`}
>
<span className="flex items-center gap-2 text-sm font-medium text-gray-800 dark:text-gray-200">
<input
type="radio"
name="web-scope"
value={scope.value}
checked={selected}
onChange={() => set("scope", scope.value)}
className="accent-gray-900 dark:accent-gray-100"
/>
{scope.label}
</span>
<span className="text-xs text-gray-400 dark:text-gray-500">
{scope.description}
</span>
</label>
);
})}
</div>
</fieldset>
<div className="grid gap-5 sm:grid-cols-3">
<div>
<Label
htmlFor="web-max-pages"
label="Page limit"
description={`Per crawl, up to ${WEB_LIMITS.maxPages}.`}
/>
<input
id="web-max-pages"
type="number"
min={1}
max={WEB_LIMITS.maxPages}
value={config.max_pages}
onChange={(e) => set("max_pages", Number(e.target.value))}
className={errors.max_pages ? errorBase : inputBase}
/>
<FieldError message={errors.max_pages} />
</div>
<div>
<Label
htmlFor="web-max-depth"
label="Link depth"
description={
config.scope === "page"
? "Not used — only the listed pages are read."
: "Links followed away from a listed URL."
}
/>
<div className="flex items-center gap-3 h-9">
<input
id="web-max-depth"
type="range"
min={0}
max={WEB_LIMITS.maxDepth}
step={1}
value={config.max_depth}
disabled={config.scope === "page"}
onChange={(e) => set("max_depth", Number(e.target.value))}
className="flex-1 accent-gray-900 dark:accent-gray-100 disabled:opacity-40"
/>
<span className="text-sm font-semibold text-gray-800 dark:text-gray-200 w-4 text-right">
{config.max_depth}
</span>
</div>
</div>
<div>
<Label
htmlFor="web-refresh"
label="Refresh"
description="How often to look for changes."
/>
<select
id="web-refresh"
value={config.refresh}
onChange={(e) =>
set("refresh", e.target.value as WebSourceForm["refresh"])
}
className={inputBase}
>
{WEB_REFRESH.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
</div>
</div>
<div className="rounded-lg border border-gray-200 dark:border-gray-700 px-3 py-3 space-y-3">
<label className="flex items-start gap-2 text-sm text-gray-700 dark:text-gray-300">
<input
type="checkbox"
checked={config.follow_external}
onChange={(e) => set("follow_external", e.target.checked)}
className="mt-0.5 accent-gray-900 dark:accent-gray-100"
/>
<span>
Also read the pages they link to on other sites
<span className="block text-xs text-gray-400 dark:text-gray-500">
For listings and aggregators — a news front page, a curated list —
whose value is the articles they point at. One hop: those pages'
own links are not followed. Answers can then cite the article
itself, "via" the page it was listed on.
</span>
</span>
</label>
{config.follow_external && (
<div className="pl-6 max-w-[14rem]">
<Label
htmlFor="web-max-external"
label="Linked page limit"
description={`Per crawl, up to ${WEB_LIMITS.maxExternalPages}.`}
/>
<input
id="web-max-external"
type="number"
min={1}
max={WEB_LIMITS.maxExternalPages}
value={config.max_external_pages}
onChange={(e) => set("max_external_pages", Number(e.target.value))}
className={errors.max_external_pages ? errorBase : inputBase}
/>
<FieldError message={errors.max_external_pages} />
</div>
)}
</div>
<details className="group rounded-lg border border-gray-200 dark:border-gray-700 px-3 py-2">
<summary className="cursor-pointer text-sm font-medium text-gray-700 dark:text-gray-300">
Feeds, retention and credit
</summary>
<div className="mt-3 space-y-4">
<div>
<Label
htmlFor="web-feed-content"
label="When a URL is a feed"
description="Its entries are the pages it lists, newest first."
/>
<select
id="web-feed-content"
value={config.feed_content}
onChange={(e) =>
set("feed_content", e.target.value as WebSourceForm["feed_content"])
}
className={inputBase}
>
{WEB_FEED_CONTENT.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
<p className="text-xs text-gray-400 dark:text-gray-500 mt-1">
{WEB_FEED_CONTENT.find((o) => o.value === config.feed_content)
?.description}
</p>
</div>
<div className="max-w-[14rem]">
<Label
htmlFor="web-max-age"
label="Keep pages for (days)"
description="Older pages are removed with their snapshots. Blank keeps every page — the right choice for a record, not for news."
/>
<input
id="web-max-age"
type="number"
min={1}
max={WEB_LIMITS.maxAgeDays}
value={config.max_age_days}
placeholder="Keep all"
onChange={(e) => set("max_age_days", e.target.value)}
className={errors.max_age_days ? errorBase : inputBase}
/>
<FieldError message={errors.max_age_days} />
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div>
<Label
htmlFor="web-attribution"
label="Attribution"
description="Shown with every passage cited from this source — what the site's licence asks for."
/>
<textarea
id="web-attribution"
value={config.attribution}
onChange={(e) => set("attribution", e.target.value)}
rows={2}
placeholder="e.g. Contains public sector information licensed under the Open Government Licence v3.0."
className={
(errors.attribution ? errorBase : inputBase) + " resize-none text-xs"
}
/>
<FieldError message={errors.attribution} />
</div>
<div>
<Label
htmlFor="web-licence-url"
label="Licence link"
description="Linked beside the attribution."
/>
<input
id="web-licence-url"
value={config.licence_url}
onChange={(e) => set("licence_url", e.target.value)}
placeholder="https://"
className={
(errors.licence_url ? errorBase : inputBase) + " font-mono text-xs"
}
/>
<FieldError message={errors.licence_url} />
</div>
</div>
</div>
</details>
<details className="group rounded-lg border border-gray-200 dark:border-gray-700 px-3 py-2">
<summary className="cursor-pointer text-sm font-medium text-gray-700 dark:text-gray-300">
Filters, link handling and sitemap
</summary>
<div className="mt-3 space-y-4">
<div className="grid gap-4 sm:grid-cols-2">
<div>
<Label
htmlFor="web-include"
label="Only include paths"
description="One pattern per line, e.g. /docs/* — blank means everything in scope."
/>
<textarea
id="web-include"
value={config.include}
onChange={(e) => set("include", e.target.value)}
rows={3}
className={inputBase + " resize-none font-mono text-xs"}
/>
</div>
<div>
<Label
htmlFor="web-exclude"
label="Exclude paths"
description="Always wins over include, e.g. /blog/drafts/*"
/>
<textarea
id="web-exclude"
value={config.exclude}
onChange={(e) => set("exclude", e.target.value)}
rows={3}
className={inputBase + " resize-none font-mono text-xs"}
/>
</div>
</div>
<label className="flex items-start gap-2 text-sm text-gray-700 dark:text-gray-300">
<input
type="checkbox"
checked={config.skip_low_value}
onChange={(e) => set("skip_low_value", e.target.checked)}
className="mt-0.5 accent-gray-900 dark:accent-gray-100"
/>
<span>
Skip links that are never content
<span className="block text-xs text-gray-400 dark:text-gray-500">
Vote, hide, share and log-in links, profile and account pages,
images and feeds. Also stops fetching a kind of page that keeps
coming back empty or behind a login.
</span>
</span>
</label>
<label className="flex items-start gap-2 text-sm text-gray-700 dark:text-gray-300">
<input
type="checkbox"
checked={config.use_sitemap}
onChange={(e) => set("use_sitemap", e.target.checked)}
className="mt-0.5 accent-gray-900 dark:accent-gray-100"
/>
<span>
Read the site's /sitemap.xml
<span className="block text-xs text-gray-400 dark:text-gray-500">
Finds pages that are not linked from the ones listed. Pages it
lists still have to be in scope.
</span>
</span>
</label>
</div>
</details>
<p className="text-xs text-gray-400 dark:text-gray-500">
Pages are fetched politely — robots.txt is honoured and one request a
second per site at most — so a large crawl takes a few minutes.
</p>
</div>
);
};
export default WebSourceConfigForm;
|