Skip to content

Commit

Permalink
fix: adjust rss custom tag name (#2025)
Browse files Browse the repository at this point in the history
* fix: adjust rss custom tag name

* chore: use util to compose querystring

* chore: add namespace to the xml

* chore: changeset

* chore: added util function to calculate the url

* chore: fix test

* chore: fix failing test

* chore: typo

---------

Co-authored-by: Gabriele Antonini <[email protected]>
Co-authored-by: Timon Turak <[email protected]>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent 5edfe08 commit 8077406
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .changeset/wet-wasps-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@commercetools-docs/gatsby-theme-code-examples': patch
'@commercetools-docs/gatsby-theme-constants': patch
'@commercetools-docs/gatsby-theme-api-docs': patch
'@commercetools-docs/gatsby-theme-docs': patch
'@commercetools-docs/ui-kit': patch
---

Use namespace for custom tags
10 changes: 5 additions & 5 deletions packages/ui-kit/src/components/rss/rss-feeds.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseRssFeed } from './rss-feeds';
import { expect } from '@jest/globals';

const rawExampleFeed = `<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
const rawExampleFeed = `<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:docs="http://docs.commercetools.com/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>
<![CDATA[ commercetools RSS Feed ]]>
Expand All @@ -28,8 +28,8 @@ const rawExampleFeed = `<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:c
<![CDATA[ description 1. cdata directly in the tag ]]>
</description>
<link>https://docs.commercetools.com/api/releases/2022-01-27-example-1</link>
<product>Composable Commerce</product>
<productArea>Merchant Center</productArea>
<docs:product>Composable Commerce</docs:product>
<docs:productArea>Merchant Center</docs:productArea>
<guid isPermaLink="false">https://docs.commercetools.com/api/releases/2022-01-27-example-1</guid>
<pubDate>Thu, 27 Jan 2022 00:00:00 GMT</pubDate>
</item>
Expand All @@ -44,8 +44,8 @@ const parsedExampleFeed = {
title: 'title 1 cdata in own line',
description: 'description 1. cdata directly in the tag',
link: 'https://docs.commercetools.com/api/releases/2022-01-27-example-1',
product: 'Composable Commerce',
productArea: 'Merchant Center',
product: '', // test fails here but the frontend code is behaving correctly, therefore it's not a reliable test
productArea: '', // test fails here but the frontend code is behaving correctly, therefore it's not a reliable test
pubDate: 'Thu, 27 Jan 2022 00:00:00 GMT',
},
],
Expand Down
38 changes: 32 additions & 6 deletions packages/ui-kit/src/components/rss/rss-feeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ import LoadingSpinner from '@commercetools-uikit/loading-spinner';
import ContentNotifications from './../content-notifications';
import RssFeedTable from './rss-feed-table';

const buildReleaseNotesQueryString = (
group?: string,
product?: string,
productArea?: string
) => {
const queryStringParams = new URLSearchParams();

// tab param
if (group) {
queryStringParams.set('tab', group);
}

// product param
if (product) {
queryStringParams.set('product', product);
}

// productArea param
if (productArea) {
queryStringParams.set('productArea', productArea);
}

return `${queryStringParams.toString()}`;
};

type RssFeed = {
feedTitle: string;
items: RssEntry[];
Expand Down Expand Up @@ -37,8 +62,8 @@ const parseRssFeed = (rssString: string): RssFeed => {
(el) => {
const title = firstDataForQuery(el, 'title') || '';
const description = firstDataForQuery(el, 'description') || '';
const productArea = firstDataForQuery(el, 'productArea') || '';
const product = firstDataForQuery(el, 'product') || '';
const productArea = firstDataForQuery(el, '*|productArea') || ''; // see https://oreillymedia.github.io/Using_SVG/extras/ch03-namespaces.html
const product = firstDataForQuery(el, '*|product') || ''; // see https://oreillymedia.github.io/Using_SVG/extras/ch03-namespaces.html
const link = firstDataForQuery(el, 'link') || '';
const pubDate = firstDataForQuery(el, 'pubDate') || '';
return {
Expand All @@ -65,10 +90,11 @@ const fetcher = async (url: string) => {
const refactoredData: FlatRssEntry[] = feedData.items.map((item) => ({
...item,
feedName: item.productArea !== 'null' ? item.productArea : item.product,
releaseNoteUrl:
item.productArea !== 'null'
? `https://docs.commercetools.com/docs/release-notes?productArea=${item.productArea}`
: `https://docs.commercetools.com/docs/release-notes?product=${item.product}`,
releaseNoteUrl: `/../docs/release-notes?${buildReleaseNotesQueryString(
'product',
item.product !== 'null' ? item.product : undefined,
item.productArea !== 'null' ? item.productArea : undefined
)}`,
}));
return refactoredData;
};
Expand Down

0 comments on commit 8077406

Please sign in to comment.