Skip to content

Commit

Permalink
Shortcuts don't use the query params #328
Browse files Browse the repository at this point in the history
  • Loading branch information
pmi committed May 7, 2024
1 parent 43fff4c commit 9cf7b58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/guillotine/validateShortcut.ts
Expand Up @@ -9,15 +9,21 @@ import {UrlProcessor} from '../common/UrlProcessor';

export function validateShortcut(props: FetchContentResult): void {
const {data, meta, error} = props;
const pageUrl = data?.get?.data?.target?.pageUrl;
const dataObj = data?.get?.data;
const pageUrl = dataObj?.target?.pageUrl;
const parameters = dataObj?.parameters;
if (meta.type === 'base:shortcut' && pageUrl) {
if (meta.renderMode !== RENDER_MODE.NEXT) {
// do not show shortcut targets in preview/edit mode
console.warn(404, `Shortcuts are not available in ${RENDER_MODE.NEXT} render mode`);
notFound();
}

const destination = UrlProcessor.process(pageUrl, meta, true);
let destination = UrlProcessor.process(pageUrl, meta, true);
if (parameters) {
const searchParams = parameters.map(({name, value}) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`).join('&');
destination += '?' + searchParams;
}
console.debug(`Redirecting shortcut content [${meta.path}] to`, destination);
redirect(destination, RedirectType.replace);
}
Expand All @@ -34,4 +40,4 @@ export function validateShortcut(props: FetchContentResult): void {
console.warn(404, `Can not render content at [${meta.path}]`);
notFound();
}
}
}
4 changes: 4 additions & 0 deletions src/query/Shortcut.ts
Expand Up @@ -7,6 +7,10 @@ export const getShortcutQuery = `
target {
pageUrl(type: absolute)
}
parameters {
name
value
}
}
}
}
Expand Down

0 comments on commit 9cf7b58

Please sign in to comment.