build-registry leser na **Source:**/**Primary source:**-header via ny lib/kb-headers.mjs (parseSourceHeader, 7 enhetstester) og logger dekning (0/N i dag). Hver URL-entry far reserverte felt authority_source:null + course:null (bakoverkompatibelt). Populering med korrekt semantikk utsatt til verifiseringslaget (lag 3) - minimal-reservert per operator-valg. Eksisterende status-felt (poll: tracked/not_in_sitemap/unpolled) urort for a unnga kollisjon. kb-update 56 tester gronne. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01REiKFhP4w6xGXXqWKpPCJJ
26 lines
950 B
JavaScript
26 lines
950 B
JavaScript
// kb-headers.mjs — Parse optional authority headers from KB reference files.
|
|
// Zero dependencies. Scans only the top of the file (header region) where the
|
|
// **Source:** / **Primary source:** line lives, mirroring report-changes'
|
|
// parseLastUpdated convention.
|
|
|
|
const HEADER_REGION_BYTES = 500;
|
|
|
|
const SOURCE_PATTERNS = [
|
|
/\*\*Source:\*\*\s*(\S+)/i,
|
|
/\*\*Primary source:\*\*\s*(\S+)/i,
|
|
];
|
|
|
|
/**
|
|
* Extract the declared authority source URL from a KB reference file's header.
|
|
* @param {string} content — full file content (only the first 500 bytes are scanned)
|
|
* @returns {string|null} the source URL, or null if no header is present
|
|
*/
|
|
export function parseSourceHeader(content) {
|
|
if (!content || typeof content !== 'string') return null;
|
|
const head = content.slice(0, HEADER_REGION_BYTES);
|
|
for (const pattern of SOURCE_PATTERNS) {
|
|
const match = head.match(pattern);
|
|
if (match) return match[1].trim();
|
|
}
|
|
return null;
|
|
}
|