Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 2x 2x 1x 1x 1x 3x 2x 1x 1x 3x 1x 2x 1x 1x 1x 1x | import * as R from 'ramda';
export const getQueryOfNextPageContext = (ctx: any) => {
Iif (!ctx) {
return {};
}
const { pathname = '', asPath = '', query } = ctx;
const routes = R.pipe(
R.split('/'),
R.filter((item: string) => /\[\w+\]/.test(item)),
R.map((item: string) => R.replace(']', '', R.replace('[', '', item))),
)(pathname);
const path = R.pipe(R.split('#'), R.slice(0, 1))(asPath) || [];
const paths = path.length
? R.pipe(
R.split('/'),
R.filter((item: string) => item !== ''),
)(path[0] as string)
: [];
const result = routes.map((key: string, index: number) => {
return {
[`${key}`]: paths[index],
};
});
let newQuery: Record<string, any> = {};
Iif (!routes.length) {
newQuery.path = paths[0] || 'desktop';
} else {
newQuery = R.mergeAll(result) || {};
}
return {
...query,
...newQuery,
};
};
|