Skip to content

Instantly share code, notes, and snippets.

@imkarmadev
Last active August 31, 2020 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkarmadev/0426594490413248a69f452b9ea303e0 to your computer and use it in GitHub Desktop.
Save imkarmadev/0426594490413248a69f452b9ea303e0 to your computer and use it in GitHub Desktop.
{
"Main": {
"uid": {
"type": "UID",
"config": {
"label": "Page Name",
"placeholder": "Page name to fetch document"
}
},
"document_title": {
"type": "Text",
"config": {
"label": "document_title",
"placeholder": "Redesign :: Index page",
"useAsTitle": true
}
},
"domain": {
"type": "Select",
"config": {
"options": [
"solutions",
"perspectives",
"campaigns",
"press"
],
"default_value": "solutions",
"label": "domain"
}
},
"subRouteLevel1": {
"type": "Text",
"config": {
"label": "sub route level 1",
"placeholder": "sub route level 1"
}
},
"subRouteLevel2": {
"type": "Text",
"config": {
"label": "sub route level 2",
"placeholder": "sub route level 2"
}
},
"background": {
"type": "Image",
"config": {
"constraint": {
"width": 1920
},
"thumbnails": [],
"label": "background"
}
},
"marquee": {
"type": "Text",
"config": {
"label": "marquee",
"placeholder": "marquee text"
}
}
}
}
export const getDynamicDocument = async <T>(
root: string,
pid?: string,
target?: string
): Promise<SearchResponseType<T>> => {
const API = await Prismic.getApi(BASE_URL)
const predicates = []
predicates.push(Prismic.Predicates.any('my.primarytest.domain', [root]))
if (pid) {
predicates.push(Prismic.Predicates.at('my.primarytest.subRouteLevel1', pid))
}
if (target) {
predicates.push(Prismic.Predicates.at('my.primarytest.subRouteLevel2', target))
} else {
predicates.push(Prismic.Predicates.missing('my.primarytest.subRouteLevel2'))
}
return await API.query(predicates, { pageSize: 100 })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment