Skip to content

Commit

Permalink
Viser highlight i søketreff. Bruker riktig funksjon for amplitude
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-nom committed May 13, 2024
1 parent 7cd9cb7 commit d81482c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/client/src/views/context-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type AnalyticsEventArgs } from "../analytics/constants";
import { createEvent, CustomEvents } from "../events";
import { Context } from "decorator-shared/params";
import { CustomLinkElement } from "../helpers/custom-link-element";
import { amplitudeEvent } from "../analytics/amplitude";

class ContextLink extends CustomLinkElement {
handleActiveContext = (
Expand Down Expand Up @@ -41,7 +42,7 @@ class ContextLink extends CustomLinkElement {
context: window.__DECORATOR_DATA__.params.context,
...eventArgs,
};
window.analyticsEvent(payload);
amplitudeEvent(payload);
}
};

Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/views/lenke-med-sporing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AnalyticsEventArgs } from "../analytics/constants";
import { tryParse } from "decorator-shared/json";
import { CustomLinkElement } from "../helpers/custom-link-element";
import { amplitudeEvent } from "../analytics/amplitude";

export class LenkeMedSporingElement extends CustomLinkElement {
constructor() {
Expand All @@ -18,7 +19,7 @@ export class LenkeMedSporingElement extends CustomLinkElement {
context: window.__DECORATOR_DATA__.params.context,
...eventArgs,
};
window.analyticsEvent(payload);
amplitudeEvent(payload);
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/views/search-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import html from "decorator-shared/html";
import debounce from "lodash.debounce";
import cls from "../styles/search-form.module.css";
import { env, param } from "../params";
import { amplitudeEvent } from "../analytics/amplitude";

class SearchMenu extends HTMLElement {
form: HTMLFormElement | null = null;
Expand Down Expand Up @@ -51,7 +52,7 @@ class SearchMenu extends HTMLElement {
.map(([key, value]) => `${key}=${value}`)
.join("&")}`;

window.analyticsEvent({
amplitudeEvent({
eventName: "søk",
destination: url,
category: "dekorator-header",
Expand Down
9 changes: 1 addition & 8 deletions packages/server/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ export const search = ({
)
.then((res) => res.json() as Promise<SearchResult>)
.then((result) => ({
hits: result.hits?.slice(0, 5).map((hit) => ({
// TODO: kan limit(5) gjøres i søketjenesten
...hit,
highlight: hit.highlight // TODO: replace() i søketjenesten
.replace(/<\/?[^>]+(>|$)/g, "") // Remove html
.replace(/\[.*?(\])/g, "") // Remove shortcodes
.replace(/(\[|<).*?(\(...\))/g, ""), // Remove incomplete html/shortcodes
})),
hits: result.hits.slice(0, 5),
total: result.total,
}))
.catch((err) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/server/src/views/search-hits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import html from "decorator-shared/html";
import html, { unsafeHtml } from "decorator-shared/html";
import { SearchResult, Texts } from "decorator-shared/types";
import cls from "decorator-client/src/styles/search-hits.module.css";
import { ForwardChevron } from "decorator-shared/views/icons";
Expand Down Expand Up @@ -42,7 +42,9 @@ export const SearchHits = ({
<h2 class="${cls.title}">
${hit.displayName}
</h2>
<div>${hit.highlight}</div>
<div>
${unsafeHtml(hit.highlight)}
</div>
</div>
</lenke-med-sporing>
</li>
Expand Down

0 comments on commit d81482c

Please sign in to comment.