Skip to content

Commit

Permalink
✨ feat(create-drupal-decoupled) Add support to preview (#79)
Browse files Browse the repository at this point in the history
* 🐛 fix(create-drupal-decoupled) Add typename to support redirects

* ✨ feat(create-drupal-decoupled) Add calculate path to scaffolding files

* ✨ feat(create-drupal-decoupled) Add support to previews using calculate paths
  • Loading branch information
enZane authored Jul 31, 2024
1 parent b013793 commit 26a5e88
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-beers-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@octahedroid/create-drupal-decoupled": minor
---

Fix redirects and add calculate path to support redirects
4 changes: 4 additions & 0 deletions packages/create-drupal-decoupled/src/helpers/scaffolding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const SCAFFOLD_FILES_PER_FRONTEND: Readonly<ScaffoldFilesPerFrontend> = {
folderPath: 'app/utils',
fileName: 'drupal-client.server.ts',
},
{
folderPath: 'app/utils',
fileName: 'calculate-path.server.ts'
},
{
folderPath: '.',
fileName: '.env.example',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { gql } from 'urql'
import { metaTags } from 'drupal-remix'

import { getDrupalClient } from '~/utils/drupal-client.server'
import { calculatePath } from '~/utils/calculate-path.server'

const GET_DRUPAL_CONTENT_ERROR = 'Error fetching data from Drupal'

Expand All @@ -22,7 +23,7 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
})
}

export const loader = async ({ params }: LoaderFunctionArgs) => {
export const loader = async ({ params, request }: LoaderFunctionArgs) => {
const path = params['*']
const drupalClient = await getDrupalClient()
const { data, error } = await drupalClient.query(
Expand All @@ -32,6 +33,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
... on RouteInternal {
entity {
... on NodeArticle {
__typename
title
path
image {
Expand Down Expand Up @@ -64,6 +66,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
}
}
... on NodePage {
__typename
title
path
body {
Expand Down Expand Up @@ -94,14 +97,18 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
}
}
... on RouteRedirect {
__typename
url
status
}
}
}
`,
{
path,
path: calculatePath({
path,
url: request.url,
}),
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
interface CalculatePathArgs {
path: string | undefined;
url: Request['url'];
}

export const calculatePath = ({ path = "/", url }: CalculatePathArgs): string => {
if (path.startsWith("node/preview")) {
const { searchParams } = new URL(url);
if (searchParams.has("token")) {
return `${path}?token=${searchParams.get("token")}`;
}
}

return path;
}

0 comments on commit 26a5e88

Please sign in to comment.