(search) hide spoiler content of sources

This commit is contained in:
Valentyne Stigloher 2024-12-28 00:29:13 +01:00
parent 9f5b83583d
commit e337e046a1
2 changed files with 11 additions and 2 deletions

View File

@ -42,7 +42,7 @@ interface LoadedSearchKind {
}
const DEFAULT_OPTIONS: Options<SearchDocument> = {
fields: ['title', 'titleSmall', 'content'],
fields: ['title', 'titleSmall', 'content', 'contentHidden'],
storeFields: ['kind'],
};
@ -132,6 +132,7 @@ const transformResult = (indices: Map<SearchDocument['kind'],
const transformed = structuredClone(document);
transformed.title = highlightMatches(document.title, termsByField.title);
transformed.content = highlightMatches(document.content, termsByField.content, true);
delete transformed.contentHidden;
if (kind.transformDocument) {
kind.transformDocument(transformed, termsByField);
}
@ -474,14 +475,20 @@ const kinds: SearchKind[] = [
title += `, ${source.year}`;
let content = '';
let contentHidden = '';
if (source.comment) {
content += `${source.comment} `;
}
content += source.fragments
const fragments = source.fragments
.replaceAll('[[', '')
.replaceAll(']]', '')
.replaceAll('|', ' ')
.replaceAll(/(?<!\\)@/g, '; ');
if (source.spoiler) {
contentHidden += fragments;
} else {
content += fragments;
}
const images = source.images ? source.images.split(',') : [];
const image = images.length > 0
@ -495,6 +502,7 @@ const kinds: SearchKind[] = [
title,
image: image ? { src: image } : undefined,
content,
contentHidden,
};
});
},

View File

@ -12,6 +12,7 @@ export interface SearchDocument {
titleSmall?: string | undefined;
image?: SearchDocumentImage | undefined;
content: string;
contentHidden?: string;
date?: string;
authors?: string[];
}