refactor: extract article viewer link builder

Move the article viewer query-param logic out of ArticleContainer into a shared buildArticleViewerLink helper so it can be reused.
This commit is contained in:
Shivam Mishra
2026-06-02 16:01:00 +05:30
parent 6c8741b314
commit 16e638aeb7
2 changed files with 29 additions and 8 deletions
@@ -38,3 +38,24 @@ export const getMatchingLocale = (selectedLocale = '', allowedLocales = []) => {
// Return the first match that exists in the allowed list, or null
return priorityMatches.find(l => l && allowedLocales.includes(l)) ?? null;
};
/**
* Build the link consumed by the in-widget article viewer, appending the query
* params it expects (plain layout, theme and locale).
*
* @export
* @param {Object} options
* @param {string} options.link Relative article/portal path (e.g. `hc/slug/articles/foo`).
* @param {(string|null)} [options.locale] Resolved portal locale.
* @param {boolean} [options.prefersDarkMode] Whether the widget is in dark mode.
* @returns {string} The link with the article viewer query params appended.
*/
export const buildArticleViewerLink = ({ link, locale, prefersDarkMode }) => {
const params = new URLSearchParams({
show_plain_layout: 'true',
theme: prefersDarkMode ? 'dark' : 'light',
...(locale && { locale }),
});
return `${link}?${params.toString()}`;
};