mirror of
https://github.com/vercel/commerce.git
synced 2025-07-28 04:31:22 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
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
38 lines
741 B
TypeScript
38 lines
741 B
TypeScript
import { getConfig, SwellConfig } from '../api'
|
|
|
|
type Variables = {
|
|
first?: number
|
|
}
|
|
|
|
type ReturnType = {
|
|
pages: Page[]
|
|
}
|
|
|
|
export type Page = {
|
|
id: string
|
|
name: string
|
|
url: string
|
|
sort_order?: number
|
|
body: string
|
|
}
|
|
|
|
const getAllPages = async (options?: {
|
|
variables?: Variables
|
|
config: SwellConfig
|
|
preview?: boolean
|
|
}): Promise<ReturnType> => {
|
|
let { config, variables = { first: 250 } } = options ?? {}
|
|
config = getConfig(config)
|
|
const { locale, fetch } = config
|
|
const data = await fetch('content', 'list', ['pages'])
|
|
const pages =
|
|
data?.results?.map(({ slug, ...rest }: { slug: string }) => ({
|
|
url: `/${locale}/${slug}`,
|
|
...rest,
|
|
})) ?? []
|
|
|
|
return { pages }
|
|
}
|
|
|
|
export default getAllPages
|