Skip to content

Commit b00b8ea

Browse files
committed
Update Wikipedia citations (it's a stupid way but I just need it to work ASAP, will cleanmm code layer) and AI humanizing parsing (copilot updated the parsing because it was a busywork task and took two seconds)
1 parent b871ee5 commit b00b8ea

2 files changed

Lines changed: 69 additions & 6 deletions

File tree

src/pages/SimpleCite.tsx

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,52 @@ const scrubOrganizationalAuthor = (data: Metadata) => {
410410
return data;
411411
};
412412

413-
const finalizeMetadata = (data: Metadata) => scrubOrganizationalAuthor(promoteOriginFields(data));
413+
const handleWikipediaMetadata = (data: Metadata) => {
414+
const url = data.url.toLowerCase();
415+
const isWikipedia = url.includes('wikipedia.org') || url.includes('wikimedia.org');
416+
417+
if (!isWikipedia) return data;
418+
419+
const next = { ...data };
420+
421+
if (next.title) {
422+
next.title = next.title.replace(/\s*[-]\s*Wikipedia\s*$/i, '').trim();
423+
424+
const looksLikeDescription = /^(\d{4}s?\s+)?(period|time|era|event|series)\s+(of|in|during|that|when)/i.test(next.title);
425+
426+
if (looksLikeDescription) {
427+
try {
428+
const urlPath = new URL(data.url).pathname;
429+
const match = urlPath.match(/\/wiki\/([^#?]+)$/);
430+
if (match) {
431+
const pathTitle = decodeURIComponent(match[1]).replace(/_/g, ' ');
432+
if (pathTitle) {
433+
next.title = pathTitle;
434+
}
435+
}
436+
} catch {
437+
}
438+
}
439+
}
440+
441+
// Set proper Wikipedia author if missing or generic
442+
if (!next.author || next.author.toLowerCase().includes('wikipedia')) {
443+
next.author = 'Contributors to Wikimedia projects';
444+
}
445+
446+
if (!next.publisher || next.publisher.toLowerCase() === 'wikipedia') {
447+
next.publisher = 'Wikimedia Foundation, Inc.';
448+
}
449+
450+
if (!next.site || next.site.toLowerCase() === 'en.wikipedia.org') {
451+
next.site = 'Wikipedia';
452+
}
453+
454+
return next;
455+
};
456+
457+
const finalizeMetadata = (data: Metadata) =>
458+
handleWikipediaMetadata(scrubOrganizationalAuthor(promoteOriginFields(data)));
414459

415460
type JsonLdEntry = Record<string, unknown>;
416461

@@ -621,10 +666,15 @@ const gatherMetadataFromSource = async (targetUrl: string, useProxy = false) =>
621666

622667
const buildMetadataPrompt = (context: string, url: string) =>
623668
[
624-
'You are a meticulous citation metadata extractor.',
625-
'Return ONLY strict JSON with keys "title","author","year","publisher","site","accessed". Empty or missing values must be null.',
626-
'Never include prose, explanations, or markdown fences—respond with JSON only. Try to assume and use deep context for finding value.',
627-
`If the page is blocked (cookie walls, headless browser issues) and you cannot extract anything reliable, respond ONLY with the keyword ${AI_METADATA_FALLBACK_KEYWORD}.`,
669+
'extract citation metadata and return only strict json with keys "title","author","year","publisher","site","accessed". empty values must be null.',
670+
'never include prose, explanations, or markdown fences. respond with json only.',
671+
'if context starts with "title: [text]", use that exact text as title. otherwise extract from page header or h1.',
672+
'never use descriptions or summaries as title.',
673+
'for authors: look for "by [name]" or "author: [name]" patterns in the content. extract the actual person name, not site credits.',
674+
'for dates: look for "published time:" header or dates in format like "december 4, 2025" or "2025-12-04". extract year at minimum.',
675+
'for wikipedia: title from article name only. author should be "contributors to wikimedia projects".',
676+
`if page is blocked or unreadable, respond only with keyword ${AI_METADATA_FALLBACK_KEYWORD}.`,
677+
'if you can not find any of the above (by [name], or other specific strings) use common sense and see if there are any pother identifiers, maybe in the text itself, to find the correct data',
628678
`Context: ${context}`,
629679
`URL: ${url}`,
630680
].join('\n');

src/pages/SimpleSuite.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,20 @@ ${localPass}
273273
headers: { Accept: 'text/plain' },
274274
});
275275
const result = await response.text();
276-
const trimmed = result.trim();
276+
let trimmed = result.trim();
277+
278+
// Handle JSON response format if API returns structured data
279+
try {
280+
const parsed = JSON.parse(trimmed);
281+
if (parsed && typeof parsed === 'object') {
282+
// Extract content from various possible fields
283+
trimmed = parsed.content || parsed.text || parsed.reasoning_content || trimmed;
284+
}
285+
} catch {
286+
// Not JSON, use the raw text
287+
}
288+
289+
trimmed = trimmed.trim();
277290
setInput(trimmed);
278291
setDiffHtml(humanBuildDiffHtml(value, trimmed, styles.diffChanged));
279292
setStatus('Done. Changed parts are highlighted.');

0 commit comments

Comments
 (0)