Fixed title and tags being empty for some search queries

This commit is contained in:
squidfunk 2022-12-07 20:41:44 +01:00
parent 0570b1aa5c
commit 13680a5863
11 changed files with 21 additions and 17 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -211,7 +211,7 @@
"base": base_url, "base": base_url,
"features": features, "features": features,
"translations": {}, "translations": {},
"search": "assets/javascripts/workers/search.cd82efe4.min.js" | url "search": "assets/javascripts/workers/search.7c75be7a.min.js" | url
} -%} } -%}
{%- if config.extra.version -%} {%- if config.extra.version -%}
{%- set _ = app.update({ "version": config.extra.version }) -%} {%- set _ = app.update({ "version": config.extra.version }) -%}
@ -245,7 +245,7 @@
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
{% if page.meta and page.meta.ᴴₒᴴₒᴴₒ %} {% if page.meta and page.meta.ᴴₒᴴₒᴴₒ %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/extra.d0c7f9ad.min.css' | url }}"> <link rel="stylesheet" href="{{ 'assets/stylesheets/extra.300c463b.min.css' | url }}">
<script src="{{ 'assets/javascripts/extra/bundle.f719a234.min.js' | url }}" defer></script> <script src="{{ 'assets/javascripts/extra/bundle.f719a234.min.js' | url }}" defer></script>
{% endif %} {% endif %}
</body> </body>

View File

@ -173,9 +173,9 @@ class SearchIndex:
# Create entry for section # Create entry for section
entry = { entry = {
"location": url,
"title": title, "title": title,
"text": text, "text": text
"location": url
} }
# Set document tags # Set document tags

View File

@ -235,6 +235,10 @@ export class Search {
if (field in match) if (field in match)
positions.push(...match[field].position) positions.push(...match[field].position)
/* Skip field, if no highlighting is necessary */
if (!positions.length)
continue
// @ts-expect-error - @todo fix typings // @ts-expect-error - @todo fix typings
if (Array.isArray(doc[field])) { if (Array.isArray(doc[field])) {
// @ts-expect-error - @todo fix typings // @ts-expect-error - @todo fix typings

View File

@ -38,7 +38,6 @@ import { Position, PositionTable } from "../tokenizer"
export function highlighter( export function highlighter(
value: string, table: PositionTable, positions: Position[] value: string, table: PositionTable, positions: Position[]
): string { ): string {
const slices: string[] = []
/* Map matches to blocks */ /* Map matches to blocks */
const blocks = new Map<number, number[]>() const blocks = new Map<number, number[]>()
@ -56,6 +55,7 @@ export function highlighter(
} }
/* Compute slices */ /* Compute slices */
const slices: string[] = []
for (const [block, indexes] of blocks) { for (const [block, indexes] of blocks) {
const t = table[block] const t = table[block]

View File

@ -173,9 +173,9 @@ class SearchIndex:
# Create entry for section # Create entry for section
entry = { entry = {
"location": url,
"title": title, "title": title,
"text": text, "text": text
"location": url
} }
# Set document tags # Set document tags