File tree Expand file tree Collapse file tree 1 file changed +34
-6
lines changed
packages/optimizely-cms-sdk/src/graph Expand file tree Collapse file tree 1 file changed +34
-6
lines changed Original file line number Diff line number Diff line change 66 * This is used internally in the SDK
77 */
88
9+ /** Returns two versions of the same path. One with trailing slash and one without it */
10+ function normalizePath ( path : string ) {
11+ if ( path . endsWith ( '/' ) ) {
12+ return {
13+ pathWithTrailingSlash : path ,
14+ pathWithoutTrailingSlash : path . slice ( 0 , - 1 ) ,
15+ } ;
16+ } else {
17+ return {
18+ pathWithTrailingSlash : path + '/' ,
19+ pathWithoutTrailingSlash : path ,
20+ } ;
21+ }
22+ }
23+
924/**
1025 * Creates a {@linkcode ContentInput} object that filters results by a specific URL path.
1126 *
1227 * @param path - The URL path to filter by.
1328 * @returns A `GraphQueryArguments` object with a `where` clause that matches the given path.
1429 */
1530export function pathFilter ( path : string , host ?: string ) : ContentInput {
31+ const { pathWithTrailingSlash, pathWithoutTrailingSlash } =
32+ normalizePath ( path ) ;
33+
1634 return {
1735 where : {
18- _metadata : {
19- url : {
20- default : {
21- eq : path ,
36+ _or : [
37+ {
38+ _metadata : {
39+ url : {
40+ default : { eq : pathWithTrailingSlash } ,
41+ base : host ? { eq : host } : undefined ,
42+ } ,
2243 } ,
23- base : host ? { eq : host } : undefined ,
2444 } ,
25- } ,
45+ {
46+ _metadata : {
47+ url : {
48+ default : { eq : pathWithoutTrailingSlash } ,
49+ base : host ? { eq : host } : undefined ,
50+ } ,
51+ } ,
52+ } ,
53+ ] ,
2654 } ,
2755 } ;
2856}
You can’t perform that action at this time.
0 commit comments