mirror of
https://github.com/vercel/commerce.git
synced 2025-08-09 10:21:25 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
local
local-old
shopify
swell
api
auth
cart
common
get-all-pages.ts
get-page.ts
get-site-info.ts
customer
product
utils
wishlist
.env.template
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
swell-js.d.ts
types.ts
vendure
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
34 lines
701 B
TypeScript
34 lines
701 B
TypeScript
import { getConfig, SwellConfig } from '../api'
|
|
import { Page } from './get-all-pages'
|
|
|
|
type Variables = {
|
|
id: string
|
|
}
|
|
|
|
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
|
|
|
const getPage = async (options: {
|
|
variables: Variables
|
|
config: SwellConfig
|
|
preview?: boolean
|
|
}): Promise<GetPageResult> => {
|
|
let { config, variables } = options ?? {}
|
|
|
|
config = getConfig(config)
|
|
const { locale } = config
|
|
const { id } = variables
|
|
const result = await config.fetch('content', 'get', ['pages', id])
|
|
const page = result
|
|
|
|
return {
|
|
page: page
|
|
? {
|
|
...page,
|
|
url: `/${locale}/${page.slug}`,
|
|
}
|
|
: null,
|
|
}
|
|
}
|
|
|
|
export default getPage
|