File size: 1,912 Bytes
5301c48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { groq } from 'next-sanity'

// Get all posts with basic information
export const allPostsQuery = groq`
*[_type == "post"] | order(publishedAt desc) {
  _id,
  title,
  "slug": slug.current,
  publishedAt,
  excerpt,
  mainImage {
    image {
      asset->{
        _id,
        url,
        metadata {
          dimensions
        }
      }
    }
  }
}`

// Get a single post by slug with all sections
export const postBySlugQuery = groq`
*[_type == "post" && slug.current == $slug][0] {
  _id,
  _createdAt,
  title,
  "slug": slug.current,
  publishedAt,
  excerpt,
  mainImage {
    image {
      asset->{
        _id,
        url,
        metadata
      },
      hotspot,
      crop
    },
    description
  },
  sections[] {
    _type,
    _key,
    _type == "postSection" => {
      sectionTitle,
      sectionImage {
        image {
          asset->{
            _id,
            url,
            metadata
          },
          hotspot,
          crop
        },
        description
      },
      sectionBody[] {
        ...,
        _type == "block" => {
          ...,
          markDefs[]
        }
      }
    },
    _type == "markdownSection" => {
      content
    }
  }
}`

// Get latest posts for homepage or sidebar
export const latestPostsQuery = groq`
*[_type == "post"] | order(publishedAt desc)[0...3] {
  _id,
  title,
  "slug": slug.current,
  publishedAt,
  excerpt,
  mainImage {
    image {
      asset->{
        _id,
        url,
        metadata {
          dimensions
        }
      }
    }
  }
}`

// Get posts by date range
export const postsByDateQuery = groq`
*[_type == "post" && publishedAt >= $startDate && publishedAt <= $endDate] | order(publishedAt desc) {
  _id,
  title,
  "slug": slug.current,
  publishedAt,
  excerpt,
  mainImage {
    image {
      asset->{
        _id,
        url,
        metadata {
          dimensions
        }
      }
    }
  }
}`