Skip to content

Commit d8d4056

Browse files
committed
Merge branch 'main' into chore/update-env-template
2 parents 0a72cce + 3bb6d0f commit d8d4056

File tree

4 files changed

+84
-3
lines changed

4 files changed

+84
-3
lines changed

manual-installation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ If you want to start with some sample content, you can import the provided datas
4848
To import the dataset, run the following command in your terminal:
4949

5050
```bash
51-
npx sanity dataset import demoData.tar.gz production
51+
npx sanity dataset import sample-data.tar.gz production
5252
```
5353

5454
This assumes your dataset is named `production`. If your dataset is named differently, replace `production` with the name of your dataset.

nextjs-app/app/sitemap.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { MetadataRoute } from "next";
2+
import { sanityFetch } from "@/sanity/lib/live";
3+
import { sitemapData } from "@/sanity/lib/queries";
4+
import { headers } from "next/headers";
5+
6+
/**
7+
* This file creates a sitemap (sitemap.xml) for the application. Learn more about sitemaps in Next.js here: https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap
8+
* Be sure to update the `changeFrequency` and `priority` values to match your application's content.
9+
*/
10+
11+
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
12+
const allPostsAndPages = await sanityFetch({
13+
query: sitemapData,
14+
});
15+
const headersList = await headers();
16+
const sitemap: MetadataRoute.Sitemap = [];
17+
const domain: String = headersList.get("host") as string;
18+
sitemap.push({
19+
url: domain as string,
20+
lastModified: new Date(),
21+
priority: 1,
22+
changeFrequency: "monthly",
23+
});
24+
25+
if (allPostsAndPages != null && allPostsAndPages.data.length != 0) {
26+
let priority: number;
27+
let changeFrequency:
28+
| "monthly"
29+
| "always"
30+
| "hourly"
31+
| "daily"
32+
| "weekly"
33+
| "yearly"
34+
| "never"
35+
| undefined;
36+
let url: string;
37+
38+
for (const p of allPostsAndPages.data) {
39+
switch (p._type) {
40+
case "page":
41+
priority = 0.8;
42+
changeFrequency = "monthly";
43+
url = `${domain}/${p.slug}`;
44+
break;
45+
case "post":
46+
priority = 0.5;
47+
changeFrequency = "never";
48+
url = `${domain}/posts/${p.slug}`;
49+
break;
50+
}
51+
sitemap.push({
52+
lastModified: p._updatedAt || new Date(),
53+
priority,
54+
changeFrequency,
55+
url,
56+
});
57+
}
58+
}
59+
60+
return sitemap;
61+
}

nextjs-app/sanity.types.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export type SettingsQueryResult = {
505505
};
506506
} | null;
507507
// Variable: getPageQuery
508-
// Query: *[_type == 'page' && slug.current == $slug][0]{ _id, _type, name, slug, heading, subheading, "pageBuilder": pageBuilder[]{ ..., _type == "callToAction" => { link { ..., _type == "link" => { "page": page->slug.current, "post": post->slug.current } }, }, _type == "infoSection" => { content[]{ ..., markDefs[]{ ..., _type == "link" => { "page": page->slug.current, "post": post->slug.current } } } }, }, }
508+
// Query: *[_type == 'page' && slug.current == $slug][0]{ _id, _type, name, slug, heading, subheading, "pageBuilder": pageBuilder[]{ ..., _type == "callToAction" => { ..., link { ..., _type == "link" => { "page": page->slug.current, "post": post->slug.current } }, } }, }
509509
export type GetPageQueryResult = {
510510
_id: string;
511511
_type: "page";
@@ -556,6 +556,17 @@ export type GetPageQueryResult = {
556556
}> | null;
557557
}> | null;
558558
} | null;
559+
// Variable: sitemapData
560+
// Query: *[_type == "page" || _type == "post" && defined(slug.current)] | order(_type asc) { "slug": slug.current, _type, _updatedAt, }
561+
export type SitemapDataResult = Array<{
562+
slug: string;
563+
_type: "page";
564+
_updatedAt: string;
565+
} | {
566+
slug: string;
567+
_type: "post";
568+
_updatedAt: string;
569+
}>;
559570
// Variable: allPostsQuery
560571
// Query: *[_type == "post" && defined(slug.current)] | order(date desc, _updatedAt desc) { _id, "status": select(_originalId in path("drafts.**") => "draft", "published"), "title": coalesce(title, "Untitled"), "slug": slug.current, excerpt, coverImage, "date": coalesce(date, _updatedAt), "author": author->{firstName, lastName, picture}, }
561572
export type AllPostsQueryResult = Array<{
@@ -708,7 +719,8 @@ import "@sanity/client";
708719
declare module "@sanity/client" {
709720
interface SanityQueries {
710721
"*[_type == \"settings\"][0]": SettingsQueryResult;
711-
"\n *[_type == 'page' && slug.current == $slug][0]{\n _id,\n _type,\n name,\n slug,\n heading,\n subheading,\n \"pageBuilder\": pageBuilder[]{\n ...,\n _type == \"callToAction\" => {\n \n link {\n ...,\n \n _type == \"link\" => {\n \"page\": page->slug.current,\n \"post\": post->slug.current\n }\n\n }\n,\n },\n _type == \"infoSection\" => {\n content[]{\n ...,\n markDefs[]{\n ...,\n \n _type == \"link\" => {\n \"page\": page->slug.current,\n \"post\": post->slug.current\n }\n\n }\n }\n },\n },\n }\n": GetPageQueryResult;
722+
"\n *[_type == 'page' && slug.current == $slug][0]{\n _id,\n _type,\n name,\n slug,\n heading,\n subheading,\n \"pageBuilder\": pageBuilder[]{\n ...,\n _type == \"callToAction\" => {\n ...,\n \n link {\n ...,\n \n _type == \"link\" => {\n \"page\": page->slug.current,\n \"post\": post->slug.current\n }\n\n }\n,\n }\n },\n }\n": GetPageQueryResult;
723+
"\n *[_type == \"page\" || _type == \"post\" && defined(slug.current)] | order(_type asc) {\n \"slug\": slug.current,\n _type,\n _updatedAt,\n }\n": SitemapDataResult;
712724
"\n *[_type == \"post\" && defined(slug.current)] | order(date desc, _updatedAt desc) {\n \n _id,\n \"status\": select(_originalId in path(\"drafts.**\") => \"draft\", \"published\"),\n \"title\": coalesce(title, \"Untitled\"),\n \"slug\": slug.current,\n excerpt,\n coverImage,\n \"date\": coalesce(date, _updatedAt),\n \"author\": author->{firstName, lastName, picture},\n\n }\n": AllPostsQueryResult;
713725
"\n *[_type == \"post\" && _id != $skip && defined(slug.current)] | order(date desc, _updatedAt desc) [0...$limit] {\n \n _id,\n \"status\": select(_originalId in path(\"drafts.**\") => \"draft\", \"published\"),\n \"title\": coalesce(title, \"Untitled\"),\n \"slug\": slug.current,\n excerpt,\n coverImage,\n \"date\": coalesce(date, _updatedAt),\n \"author\": author->{firstName, lastName, picture},\n\n }\n": MorePostsQueryResult;
714726
"\n *[_type == \"post\" && slug.current == $slug] [0] {\n content[]{\n ...,\n markDefs[]{\n ...,\n \n _type == \"link\" => {\n \"page\": page->slug.current,\n \"post\": post->slug.current\n }\n\n }\n },\n \n _id,\n \"status\": select(_originalId in path(\"drafts.**\") => \"draft\", \"published\"),\n \"title\": coalesce(title, \"Untitled\"),\n \"slug\": slug.current,\n excerpt,\n coverImage,\n \"date\": coalesce(date, _updatedAt),\n \"author\": author->{firstName, lastName, picture},\n\n }\n": PostQueryResult;

nextjs-app/sanity/lib/queries.ts

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ export const getPageQuery = defineQuery(`
5353
}
5454
`);
5555

56+
export const sitemapData = defineQuery(`
57+
*[_type == "page" || _type == "post" && defined(slug.current)] | order(_type asc) {
58+
"slug": slug.current,
59+
_type,
60+
_updatedAt,
61+
}
62+
`);
63+
5664
export const allPostsQuery = defineQuery(`
5765
*[_type == "post" && defined(slug.current)] | order(date desc, _updatedAt desc) {
5866
${postFields}

0 commit comments

Comments
 (0)