From 1637351bd84d011536c39994586bcf76b59b4f04 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:03:42 -0300 Subject: [PATCH] chore(deps): bump @ircsignpost/signpost-base from 16.5.0 to 16.6.0 (#18) Bumps [@ircsignpost/signpost-base](https://github.com/unitedforukraine/signpost-base) from 16.5.0 to 16.6.0. - [Commits](https://github.com/unitedforukraine/signpost-base/commits) --- updated-dependencies: - dependency-name: "@ircsignpost/signpost-base" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- lib/constants.ts | 2 + next-sitemap.config.mjs | 1 + package.json | 2 +- pages/search-results-page.tsx | 1 + pages/server-sitemap.xml/index.tsx | 2 + pages/services/[service].tsx | 65 +++++++++++++++++++++++++++++- yarn.lock | 8 ++-- 7 files changed, 74 insertions(+), 7 deletions(-) diff --git a/lib/constants.ts b/lib/constants.ts index 34423ac0..217fc0d8 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -66,6 +66,8 @@ export const GOOGLE_ANALYTICS_IDS = [ // https://www.algolia.com/account/api-keys/ export const ALGOLIA_SEARCH_APP_ID = 'BWATZIXLX6'; export const ALGOLIA_SEARCH_API_KEY = '0d9093280e7b2bc2b6ca12ed4180fd0a'; +export const ALGOLIA_SEARCH_API_KEY_WRITE = + process.env.ALGOLIA_SEARCH_API_KEY_WRITE ?? ''; // See README for more info on how to create indexes. export const ALGOLIA_ARTICLE_INDEX_NAME = diff --git a/next-sitemap.config.mjs b/next-sitemap.config.mjs index e352ed3e..a37a9da6 100644 --- a/next-sitemap.config.mjs +++ b/next-sitemap.config.mjs @@ -14,6 +14,7 @@ const config = { generateRobotsTxt: true, exclude: [ '/*/articles/*', + '/*/services/*', '/*/categories/*', '/*/sections/*', '/server-sitemap.xml', diff --git a/package.json b/package.json index 45e311a7..842ae59b 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "@algolia/client-search": "^4.14.2", "@changey/react-leaflet-markercluster": "^4.0.0-rc1", "@directus/sdk": "^10.3.3", - "@ircsignpost/signpost-base": "16.5.0", + "@ircsignpost/signpost-base": "16.6.0", "@next/env": "^12.2.4", "@react-spring/web": "^9.5.4", "@vercel/og": "^0.5.6", diff --git a/pages/search-results-page.tsx b/pages/search-results-page.tsx index 0ec15438..7632bb87 100644 --- a/pages/search-results-page.tsx +++ b/pages/search-results-page.tsx @@ -83,6 +83,7 @@ export default function SearchResultsPage({ strings={strings} siteUrl={siteUrl} footerLinks={footerLinks} + servicesFilter={[1]} signpostVersion={publicRuntimeConfig?.version} cookieBanner={ @@ -14,6 +15,7 @@ export async function getServerSideProps( const allPaths: string[] = await Promise.all([ /* Put dynamic paths here and exclude them from next-sitemap.config.mjs */ article.getStringPaths(), + service.getStringPaths(), category.getStringPaths(), section.getStringPaths(), ]).then((results: string[][]) => results.flat()); diff --git a/pages/services/[service].tsx b/pages/services/[service].tsx index 8bf60b59..847418a3 100644 --- a/pages/services/[service].tsx +++ b/pages/services/[service].tsx @@ -22,6 +22,7 @@ import { getCategoriesWithSections, getTranslationsFromDynamicContent, } from '@ircsignpost/signpost-base/dist/src/zendesk'; +import algoliasearch from 'algoliasearch/lite'; import { GetStaticProps } from 'next'; import getConfig from 'next/config'; import { useRouter } from 'next/router'; @@ -29,6 +30,10 @@ import React from 'react'; import { ABOUT_US_ARTICLE_ID, + ALGOLIA_ARTICLE_INDEX_NAME, + ALGOLIA_QUERY_INDEX_NAME, + ALGOLIA_SEARCH_API_KEY_WRITE, + ALGOLIA_SEARCH_APP_ID, CATEGORIES_TO_HIDE, CATEGORY_ICON_NAMES, DIRECTUS_AUTH_TOKEN, @@ -269,8 +274,11 @@ export const getStaticProps: GetStaticProps = async ({ service.translations = serviceTranslated; // If article does not exist, return an error. - if (!service || !service.translations.length || - service?.country !== DIRECTUS_COUNTRY_ID) { + if ( + !service || + !service.translations.length || + service?.country !== DIRECTUS_COUNTRY_ID + ) { const errorProps = await getErrorResponseProps( Number(params?.article), currentLocale, @@ -305,6 +313,53 @@ export const getStaticProps: GetStaticProps = async ({ }; } + if (service) { + const body_safe = stripHtmlTags(service.description || ''); + const title = service.name || ''; + const query = title; + const id = service.id; + const locale = currentLocale; + const updated_at_iso = service.date_updated; + const translations = service.translations; + const category = { id: '1', title: 'Services' }; + try { + const client = algoliasearch( + ALGOLIA_SEARCH_APP_ID, + ALGOLIA_SEARCH_API_KEY_WRITE + ); + const record = { + objectID: id, + id, + title, + body_safe, + locale, + category, + updated_at_iso, + translations, + }; + const index: any = client.initIndex(ALGOLIA_ARTICLE_INDEX_NAME); + await index.saveObject(record); + const indexquery: any = client.initIndex(ALGOLIA_QUERY_INDEX_NAME); + await indexquery.saveObject({ + objectID: id, + id, + title, + body_safe, + locale, + category, + updated_at_iso, + translations, + query, + }); + } catch (error) { + console.error( + `Error creating algolia index: ${ + JSON.stringify(error) ?? 'Uknown error' + }` + ); + } + } + service.description = serviceTranslated[0].description; service.name = serviceTranslated[0].name; @@ -329,3 +384,9 @@ export const getStaticProps: GetStaticProps = async ({ revalidate: REVALIDATION_TIMEOUT_SECONDS, }; }; + +function stripHtmlTags(html: string): string { + const regex = + /<[^>]*>|&[^;]+;||.*?<\/span>|&[A-Za-z]+;/g; + return html.replace(regex, ''); +} diff --git a/yarn.lock b/yarn.lock index 0ba2534e..6d2065d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -811,10 +811,10 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== -"@ircsignpost/signpost-base@16.5.0": - version "16.5.0" - resolved "https://registry.yarnpkg.com/@ircsignpost/signpost-base/-/signpost-base-16.5.0.tgz#e38ac2a1f9db19b9d8349852703af6585e8b4dc9" - integrity sha512-bvj1o2dUWVpfXr0J9TFK61MHD+RACCDgib/eHeJ0pinpCDGXIX81G+1fC69DfMNLPPb+0yxjbKXZzSk8p/dROA== +"@ircsignpost/signpost-base@16.6.0": + version "16.6.0" + resolved "https://registry.yarnpkg.com/@ircsignpost/signpost-base/-/signpost-base-16.6.0.tgz#5004bba5aaa7af22ceb0e6b59425067971664389" + integrity sha512-Jkx8BJkdcXNsViJwD7HQKIkuFoYfJ44kmSecDOwz3smUSix3qVkKA9kcYa6ax0f1D5r2amsCG/CzJjScPE2F5g== "@jridgewell/gen-mapping@^0.1.0": version "0.1.1"