Browse Source

Improve meta descriptions of public pages

pull/8369/head
Thomas Kaul 4 weeks ago
parent
commit
35190384c7
  1. 11
      apps/api/src/middlewares/html-template.middleware.spec.ts
  2. 9
      apps/api/src/middlewares/html-template.middleware.ts

11
apps/api/src/middlewares/html-template.middleware.spec.ts

@ -119,6 +119,17 @@ describe('HtmlTemplateMiddleware', () => {
).toContain(`content="${genericDescription}"`);
});
it('falls back to the generic description if the description of a personal finance tool contains another token than the name token', () => {
expect(
getResponseBody({
locale: createLocale({
productDescription: 'Compare ${name} (${product})'
}),
originalUrl: productPath
})
).toContain(`content="${genericDescription}"`);
});
it('escapes the description for the use in an attribute', () => {
expect(
getResponseBody({

9
apps/api/src/middlewares/html-template.middleware.ts

@ -267,7 +267,14 @@ export class HtmlTemplateMiddleware implements NestMiddleware {
skipUntranslated: true
});
if (!description.includes('${name}')) {
const tokens = description.match(/[$]{[^}]+}/g) ?? [];
if (
tokens.length === 0 ||
tokens.some((token) => {
return token !== '${name}';
})
) {
return [];
}

Loading…
Cancel
Save