Skip to content

Commit

Permalink
Help Center: Add site domain to HC doc /plans link (#97861)
Browse files Browse the repository at this point in the history
  • Loading branch information
agrullon95 authored Jan 2, 2025
1 parent ceb16c7 commit 4f53279
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/data-stores/src/help-center/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface HelpCenterSite {
ID: number | string;
name: string;
URL: string;
domain: string;
plan: Plan;
is_wpcom_atomic: boolean;
jetpack: boolean;
Expand Down
14 changes: 14 additions & 0 deletions packages/help-center/src/hooks/use-content-filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useMemo } from '@wordpress/element';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useHelpCenterContext } from '../contexts/HelpCenterContext';

const isThisASupportArticleLink = ( href: string ) =>
/wordpress\.com(\/\w\w)?(?=\/support\/)|support\.wordpress\.com/.test( href );
Expand All @@ -8,6 +9,7 @@ export const useContentFilter = ( node: HTMLDivElement | null ) => {
const navigate = useNavigate();
const [ searchParams ] = useSearchParams();
const link = searchParams.get( 'link' ) || '';
const { site } = useHelpCenterContext();

const filters = useMemo(
() => [
Expand Down Expand Up @@ -42,6 +44,18 @@ export const useContentFilter = ( node: HTMLDivElement | null ) => {
},
},

{
pattern: 'a[href*="wordpress.com/plans/"], a[href^="/"]',
action: ( element: HTMLAnchorElement ) => {
const href = element.getAttribute( 'href' ) as string;
const currentSiteDomain = site?.domain;

if ( currentSiteDomain ) {
element.setAttribute( 'href', new URL( `${ href + currentSiteDomain }` ).href );
}
},
},

/**
* Fix table of content jump-to links.
*/
Expand Down

0 comments on commit 4f53279

Please sign in to comment.