mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 12:11:23 +00:00
.vscode
assets
components
config
docs
framework
bigcommerce
commerce
shopify
api
auth
cart
common
get-all-pages.ts
get-page.ts
get-site-info.ts
customer
product
utils
wishlist
.env.template
README.md
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
lib
pages
public
scripts
.editorconfig
.env.template
.gitignore
.prettierignore
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
39 lines
706 B
TypeScript
39 lines
706 B
TypeScript
import { getConfig, ShopifyConfig } from '../api'
|
|
import getPageQuery from '../utils/queries/get-page-query'
|
|
import { Page } from './get-all-pages'
|
|
|
|
type Variables = {
|
|
slug: string
|
|
}
|
|
|
|
type ReturnType = {
|
|
page: Page
|
|
}
|
|
|
|
const getPage = async (options: {
|
|
variables: Variables
|
|
config: ShopifyConfig
|
|
preview?: boolean
|
|
}): Promise<ReturnType> => {
|
|
let { config, variables } = options ?? {}
|
|
config = getConfig(config)
|
|
|
|
const { data } = await config.fetch(getPageQuery, {
|
|
variables,
|
|
})
|
|
|
|
const { pageByHandle: page } = data
|
|
|
|
return {
|
|
page: page
|
|
? {
|
|
...page,
|
|
name: page.title,
|
|
url: page?.handle,
|
|
}
|
|
: null,
|
|
}
|
|
}
|
|
|
|
export default getPage
|