Skip to content
Snippets Groups Projects
index.js 7.84 KiB
Newer Older
Tarje Lavik's avatar
Tarje Lavik committed
import {siteSettings} from './defaults'

/**
 * Enum of Classes that should generate pages
 * @readonly
 * @enum {array}
 */
export const publicDocumentTypes = [
  'HumanMadeObject',
  'Actor',
  'Group',
  'Concept',
  'ObjectType',
  'Place',
]

export const actorsQuery = `
  {
    "items": *[_type in ["Actor", "Group"]] | order(label, desc){ 
      _id,
      _type,
      label,
      hasType[]-> {
        _id,
        label
      },
      image,
      "count": count(*[references(^._id)]),
    },
    ${siteSettings}
  }
`

export const alertQuery = `
  *[_type == "Alert"][0] | order(_createdAt desc) {
    ...
  }
`

export const conceptsQuery = `
  {
    "items": *[_type in ["Concept", "ObjectType"]] | order(label.nor desc){ 
      _id,
      _type,
      label,
      "count": count(*[references(^._id)]),
    },
    ${siteSettings}
  }
`

export const registryQuery = `
  {
    "items": *[_type in ["Concept", "ObjectType", "Actor", "Group"]] | order(label, label.nor){ 
      _id,
      _type,
      label,
      "count": count(*[references(^._id)]),
    },
    ${siteSettings}
  }
`

export const frontpageQuery = `
  {
    "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 = `
  *[_type in [...$publicDocumentTypes]] {
    _id
  }
`

export const routesQuery = `
  *[ _type == "Route" ] {
    _id,
    _type,
    slug
  }
`

export const routeQuery = `
  {
    "route": *[ _type == "Route" && slug.current == $joinID ][0] {
      ...,
      page->{
        ...,
        navMenu->{
          ...,
          items[]{
            ...,
            "route": landingPageRoute->.slug.current
          }
        },
        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[] {
              _id,
              label,
              "owner": hasCurrentOwner[]->{
                _id,
                label
              },
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' => @{
            ...,
            item-> {
              _id,
              label,
              "owner": hasCurrentOwner[]-> {
                _id,
                label
              },
Tarje Lavik's avatar
Tarje Lavik committed
              "manifest": coalesce(
                subjectOfManifest, 
                manifestUrl,
                "/api/manifest/" + _id
              ),
Tarje Lavik's avatar
Tarje Lavik committed
            }
          }
        }
      }
    },
    ${siteSettings}
  }
`

export const humanMadeObjectsQuery = `{
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}
}`

export const typeQuery = `
  *[_id == $id][0] {
    _type
  }
`

// Fields
export const humanMadeObjectFields = `
  _id,
  _type,
  depicts[]-> {
    _id,
    label,
    image
  },
  label,
  hasType[]-> {
    ...
  },
Tarje Lavik's avatar
Tarje Lavik committed
  homepage,
Tarje Lavik's avatar
Tarje Lavik committed
  image{
    ...,
    "palette": asset->.metadata.palette{
Tarje Lavik's avatar
Tarje Lavik committed
      darkMuted,
Tarje Lavik's avatar
Tarje Lavik committed
      darkVibrant,
      dominant,
      lightMuted,
      vibrantMuted,
      muted,
      vibrant
    }
  },
Tarje Lavik's avatar
Tarje Lavik committed
  subjectOfManifest,
  "manifest": coalesce(
    subjectOfManifest, 
    "/api/manifest/" + _id
  ),
Tarje Lavik's avatar
Tarje Lavik committed
  preferredIdentifier,
  identifiedBy[] {
    ...,
    hasType[]-> {
      ...
    },
    language[]-> {
      ...
    }
  },
  activityStream[]{
    _type == 'reference' => @->{
      ...,
      contributionAssignedBy[]{
Tarje Lavik's avatar
Tarje Lavik committed
        ...,
Tarje Lavik's avatar
Tarje Lavik committed
          _id,
          label,
          image{
            asset->
          }
        }
      }
    },
    ...,
    hasType[]-> {
      ...
    },
    tookPlaceAt[]->,
    movedFrom->{
      _id,
      label,
      geoJSON
    },
    movedTo->{
      _id,
      label,
      geoJSON
    },
    contributionAssignedBy[]{
Tarje Lavik's avatar
Tarje Lavik committed
      _type == 'reference' => @->{
Tarje Lavik's avatar
Tarje Lavik committed
          _id,
          label,
          image{
            asset->
          }
        }
      },
      ...,
Tarje Lavik's avatar
Tarje Lavik committed
        _id,
        label,
        image{
          asset->
        }
      }
    },
    target->{
      _id,
      label,
      image{
        asset->
      }
    }
  },
  referredToBy[] {
    ...,
    body[] {
      ...,
      _type == 'reference' => @->{
        _id,
        _type,
        preferredIdentifier,
        label,
        subjectOfManifest,
        image{
          ...,
          asset->
        }
      }
    },
    hasType[]-> {
      ...
    },
    language-> {
      ...
    }
  },
  hasCurrentOwner[]-> {
    _id,
Tarje Lavik's avatar
Tarje Lavik committed
  },
  subject[]-> {
    ...
  },
`

export const groupFields = `
  _id,
  _type,
  label,
  hasType[]-> {
    ...
  },
  image {
    ...
  },
  referredToBy[] {
    ...
  },
  "hasMember": *[_type in ["Actor", "Group"] && references(^._id)]{ 
    _id,
    _type,
    label
  },
  "mentionedIn": *[_type in ["HumanMadeObject"] && references(^._id)]{ 
    _id,
    _type,
    label,
    preferredIdentifier,
    hasType[]-> {
      _id,
      label
    },
    image,
    "description": referredToBy[]{
      ...
    },
    hasCurrentOwner[0]->{
      _id,
    },
    "creation": activityStream[]{
      _type in ["Production", "BeginningOfExistence"] => @{
        "creators": contributionAssignedBy[]{
          "name": assignedActor->.label,
        	"_id": assignedActor->._id
        },
				timespan
      }
    },
    "aspectRatio": image.asset->.metadata.dimensions.aspectRatio,
Tarje Lavik's avatar
Tarje Lavik committed
  }
`

export const pageFields = `
  ...,
  navMenu->{
    ...,
    items[]{
      ...,
      "route": landingPageRoute->.slug.current
    }
  },
  content[] {
    ...,
    _type == 'MiradorGallery' => @{
      ...,
      items[] {
        "manifest": coalesce(manifestRef->.subjectOfManifest, manifestUrl),
        canvasUrl,
      },
    },
    _type == 'SingleObject' => @{
      ...,
      item-> {
        "manifest": coalesce(subjectOfManifest, manifestUrl),
Tarje Lavik's avatar
Tarje Lavik committed
        canvasUrl,
      }
    }
    _type == 'Grid' => @{
      ...,
      items[] {
        ...,
        "route": landingPageRoute->.slug.current
      }
    }
Tarje Lavik's avatar
Tarje Lavik committed
  }