Skip to content
Snippets Groups Projects
index.js 10.8 KiB
Newer Older
import { groq } from 'next-sanity'
Tarje.Lavik's avatar
Tarje.Lavik committed
import { activityStreamFields, siteSettings } from './fragments'
const basePath = process.env.NEXT_PUBLIC_BASE_PATH
Tarje Lavik's avatar
Tarje Lavik committed

/**
 * Enum of Classes that should generate pages
 * @readonly
 * @enum {array}
 */
export const publicDocumentTypes = [
  'HumanMadeObject',
  'Actor',
  'Concept',
  'ObjectType',
  'Place',
Tarje.Lavik's avatar
Tarje.Lavik committed
  'Event',
  'LinguisticDocument',
Tarje Lavik's avatar
Tarje Lavik committed
export const actorsQuery = groq`
Tarje Lavik's avatar
Tarje Lavik committed
  {
    "items": *[_type in ["Actor", "Group"]] | order(label, desc){ 
      _id,
      _type,
      label,
      hasType[]-> {
        _id,
        label
      },
      image,
      "count": count(*[references(^._id)]),
    },
    ${siteSettings}
  }
`

Tarje Lavik's avatar
Tarje Lavik committed
export const alertQuery = groq`
Tarje Lavik's avatar
Tarje Lavik committed
  *[_type == "Alert"][0] | order(_createdAt desc) {
    ...
  }
`

Tarje Lavik's avatar
Tarje Lavik committed
export const conceptsQuery = groq`
Tarje Lavik's avatar
Tarje Lavik committed
  {
Tarje Lavik's avatar
Tarje Lavik committed
    "items": *[_type in ["Concept", "ObjectType"]] | order(label.no desc){ 
Tarje Lavik's avatar
Tarje Lavik committed
      _id,
      _type,
      label,
      "count": count(*[references(^._id)]),
    },
    ${siteSettings}
  }
`

Tarje Lavik's avatar
Tarje Lavik committed
export const registryQuery = groq`
Tarje Lavik's avatar
Tarje Lavik committed
  {
    "items": *[_type in ["Concept", "ObjectType", "Actor", "Group"]] | order(label.no){ 
Tarje Lavik's avatar
Tarje Lavik committed
      _id,
      _type,
      label,
      "count": count(*[references(^._id)]),
    },
    ${siteSettings}
  }
`

Tarje Lavik's avatar
Tarje Lavik committed
export const frontpageQuery = groq`
Tarje Lavik's avatar
Tarje Lavik committed
  {
    "frontpage": *[ _id == "frontpage" ][0] {
      _id,
      ...,
      navMenu-> {
        ...,
        items[] {
          ...,
          "route": landingPageRoute->.slug.current
        }
      },
      content[] {
        disabled != true => {
          ...
        },
        _type == 'MiradorGallery' && disabled != true => @{
          ...,
          items[] {
            "manifest": coalesce(manifestRef->.subjectOfManifest, manifestUrl),
            canvasUrl,
          },
        },
        _type == 'SingleObject'  && disabled != true => @{
          ...,
          item-> {
          "manifest": coalesce(subjectOfManifest, manifestUrl),
            canvasUrl,
          }
        },
        _type == 'Grid' => @{
          ...,
          items[] {
            ...,
            "route": landingPageRoute->.slug.current
          }
Tarje Lavik's avatar
Tarje Lavik committed
        }
      }
    },
    "latest": *[ _type == "HumanMadeObject"][0..10] {
      _id,
      label,
      hasType[]-> {
        ...
      },
      image,	
Tarje Lavik's avatar
Tarje Lavik committed
    },
    ${siteSettings}
Tarje Lavik's avatar
Tarje Lavik committed
export const idsQuery = groq`
  *[_type in $publicDocumentTypes] {
Tarje Lavik's avatar
Tarje Lavik committed
export const routesQuery = groq`
Tarje Lavik's avatar
Tarje Lavik committed
  *[ _type == "Route" ] {
    _id,
    _type,
    slug
  }
`

Tarje Lavik's avatar
Tarje Lavik committed
export const routeQuery = groq`
Tarje Lavik's avatar
Tarje Lavik committed
  {
    "route": *[ _type == "Route" && slug.current == $slug ] {
Tarje Lavik's avatar
Tarje Lavik committed
      ...,
      page->{
        ...,
        navMenu->{
          ...,
          items[]{
            ...,
            "route": landingPageRoute->.slug.current
          }
        },
Tarje.Lavik's avatar
Tarje.Lavik committed
          _type == 'reference' => @->{
            _id,
            _type,
            label,
            shortDescription,
            image,
            memberOf[]->{
              _id,
              label,
              image
            }
          },
          _type == 'PageHeader' => @{
            ...,
            "palette": illustration.image.asset->.metadata.palette{
              darkMuted,
              darkVibrant,
              dominant,
              lightMuted,
              vibrantMuted,
              muted,
              vibrant
            }
          },
          _type == 'MiradorGallery' => @{
            ...,
            items[] {
              _id,
              label,
              view,
              "owner": manifestRef->.hasCurrentOwner[]->{
                _id,
                label
              },
              "manifest": coalesce(
                manifestRef->.subjectOfManifest, 
                manifestUrl,
                "/api/manifest/" + manifestRef->._id
              ),
              canvasUrl,
            },
          },
          _type == 'ActorCollection' => {
            ...,
            items[] {
              "label": coalesce(title, item->label.no),
              "description": coalesce(description, item->referredToBy[0].body),
              "image": coalesce(image, item->image),
              file,
              item-> {
                _id,
                label,
                shortDescription,
                referredToBy[] {
                  ...
                },
                image
              }
            }
          },
          _type == 'SingleObject' => @{
            ...,
            view,
            item-> {
              _id,
              label,
              "owner": hasCurrentOwner[]-> {
                _id,
                label
              },
              "manifest": coalesce(
                subjectOfManifest, 
                manifestUrl,
                "${basePath}/api/manifest/" + _id
Tarje.Lavik's avatar
Tarje.Lavik committed
          _type == 'SubStory' => {
            ...,
            content[] {
              ...,
              _type == 'SingleObject' => {
                ...,
                item-> {
                  _id,
                  label,
                  "owner": hasCurrentOwner[]-> {
                    _id,
                    label
                  },
                  "manifest": coalesce(
                    subjectOfManifest, 
                    manifestUrl,
                    "${basePath}/api/manifest/" + _id
                  ),
                  canvasUrl,
                }
              },
              _type == 'PageHeader' => {
                ...,
                "palette": illustration.image.asset->.metadata.palette{
                  darkMuted,
                  darkVibrant,
                  dominant,
                  lightMuted,
                  vibrantMuted,
                  muted,
                  vibrant
                }
              },
              _type == 'MiradorGallery' => {
                ...,
                items[] {
Tarje.Lavik's avatar
Tarje.Lavik committed
                  ...,
                  "owner": manifestRef->.hasCurrentOwner[]->{
                    _id,
                    label
                  },
                  "manifest": coalesce(
                    manifestRef->.subjectOfManifest, 
                    manifestUrl,
                    "/api/manifest/" + manifestRef->._id
                  ),
                  canvasUrl,
                },
              },
              _type == 'SingleObject' => {
                ...,
                view,
                item-> {
                  _id,
                  label,
                  "owner": hasCurrentOwner[]-> {
                    _id,
                    label
                  },
                  "manifest": coalesce(
                    subjectOfManifest, 
                    manifestUrl,
                    "${basePath}/api/manifest/" + _id
Tarje Lavik's avatar
Tarje Lavik committed
        content[] {
          ...,
Tarje Lavik's avatar
Tarje Lavik committed
          _type == 'PageHeader' => @{
            ...,
            "palette": illustration.image.asset->.metadata.palette{
              darkMuted,
              darkVibrant,
              dominant,
              lightMuted,
              vibrantMuted,
              muted,
              vibrant
            }
          },
Tarje Lavik's avatar
Tarje Lavik committed
          _type == 'MiradorGallery' => @{
            ...,
            items[] {
Tarje Lavik's avatar
Tarje Lavik committed
              view,
              "owner": manifestRef->.hasCurrentOwner[]->{
Tarje Lavik's avatar
Tarje Lavik committed
              "manifest": coalesce(
                manifestRef->.subjectOfManifest, 
                manifestUrl,
                "/api/manifest/" + manifestRef->._id
              ),
Tarje Lavik's avatar
Tarje Lavik committed
              canvasUrl,
            },
          },
          _type == 'SingleObject' => @{
            ...,
Tarje Lavik's avatar
Tarje Lavik committed
            view,
Tarje Lavik's avatar
Tarje Lavik committed
            item-> {
              _id,
              label,
              "owner": hasCurrentOwner[]-> {
                _id,
                label
              },
Tarje Lavik's avatar
Tarje Lavik committed
              "manifest": coalesce(
                subjectOfManifest, 
                manifestUrl,
                "${basePath}/api/manifest/" + _id
Tarje Lavik's avatar
Tarje Lavik committed
            }
          },
          _type == 'ActorCollection' => @{
            ...,
            items[] {
              ...,
              _id,
              title,
              "label": coalesce(title, "test"),
Tarje.Lavik's avatar
Tarje.Lavik committed
              shortDescription,
              description,
              item-> {
                _id,
                label,
                shortDescription,
                referredToBy[] {
                  ...
                },
                image
              }
            }
          },
Tarje Lavik's avatar
Tarje Lavik committed
/* List query */
Tarje Lavik's avatar
Tarje Lavik committed
export const humanMadeObjectsQuery = groq`{
Tarje Lavik's avatar
Tarje Lavik committed
  "items": *[_type == "HumanMadeObject"] | order(label){ 
Tarje Lavik's avatar
Tarje Lavik committed
    _id,
    _type,
    label,
    preferredIdentifier,
Tarje Lavik's avatar
Tarje Lavik committed
    homepage,
Tarje Lavik's avatar
Tarje Lavik committed
    hasType[]-> {
      _id,
      label
    },
    image,
    "description": referredToBy[]{
      ...
    },
    hasCurrentOwner[0]->{
      _id,
    },
    "creation": activityStream[]{
      _type in ["Production", "BeginningOfExistence"] => @{
        "creators": contributionAssignedBy[]{
          "name": assignedActor->.label,
        	"_id": assignedActor->._id
        },
				timespan
      }
    },
Tarje Lavik's avatar
Tarje Lavik committed
    "aspectRatio": image.asset->.metadata.dimensions.aspectRatio,
  },
  ${siteSettings}
}`

Tarje Lavik's avatar
Tarje Lavik committed
export const typeQuery = groq`
Tarje Lavik's avatar
Tarje Lavik committed
  *[_id == $id][0] {
    _type
  }
`

Tarje Lavik's avatar
Tarje Lavik committed
export const eventsQuery = groq`{
  "items": [
    ...*[_type in ["Activity", "Event"]]{
      label,
      hasType[]->{
        _id,
        label
      },
      timespan[]{
        ...,
        "orderDate": coalesce(date, beginOfTheBegin)
      },
      tookPlaceAt[]->{
        _id,
        label
      },
    ...*[defined(activityStream)].activityStream[featured == true]{
      ${activityStreamFields}
    }
  ],
Tarje Lavik's avatar
Tarje Lavik committed

export const contactCopyQuery = groq`{
  "tags": *[_type == "media.tag"]| order(name.current desc){
    name,
    "images": *[references(^._id)]{
      ...,
Tarje Lavik's avatar
Tarje Lavik committed
      "isThumbnail": defined(*[_type == "HumanMadeObject" && references(^._id)]),
      "countAssetUsage": count(*[_type != "HumanMadeObject" && references(^._id)])
Tarje Lavik's avatar
Tarje Lavik committed
    }
  },
  ${siteSettings}
}`

export const physicalExhibitionQuery = groq`{
  "item": *[_type == 'Exhibition'][0]{
    ...,
    language[]->{
      _id,
      label
    },
    referredToBy[]{
      ...,
      language->{
        _id,
        label
      },
      body[] {
        ...,
        _type == 'ExhibitionElement' => @{
          ...,
          forseesUseOf-> {
            ...
          },
          item-> {
            _id,
            _type,
            hasType[]->{
              _id,
              label
            },
            label,
            image
          }
        }
      }
    }
  },
  ${siteSettings}
Tarje.Lavik's avatar
Tarje.Lavik committed
}`