or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

content-integration.mddata-types-configuration.mdindex.mdmodule-configuration.mdserver-composables.mdxml-html-utilities.md

content-integration.mddocs/

0

# Content Integration

1

2

Nuxt Content integration with sitemap-specific schema validation and collection enhancement for seamless content-driven sitemap generation.

3

4

```typescript { .api }

5

import { schema, asSitemapCollection } from '@nuxtjs/sitemap/content';

6

import type { SitemapSchema } from '@nuxtjs/sitemap/content';

7

```

8

9

## Capabilities

10

11

### Sitemap Schema

12

13

Zod schema for validating sitemap metadata in Nuxt Content frontmatter.

14

15

```typescript { .api }

16

/**

17

* Zod schema object for sitemap frontmatter validation

18

* Defines the structure of sitemap-specific fields in content files

19

*/

20

const schema: ZodObject<{

21

sitemap: ZodObject<{

22

loc: ZodOptional<ZodString>;

23

lastmod: ZodOptional<ZodDate>;

24

changefreq: ZodOptional<ZodUnion<[

25

ZodLiteral<'always'>, ZodLiteral<'hourly'>, ZodLiteral<'daily'>,

26

ZodLiteral<'weekly'>, ZodLiteral<'monthly'>, ZodLiteral<'yearly'>, ZodLiteral<'never'>

27

]>>;

28

priority: ZodOptional<ZodNumber>;

29

images: ZodOptional<ZodArray<ZodObject<ImageSchema>>>;

30

videos: ZodOptional<ZodArray<ZodObject<VideoSchema>>>;

31

}>;

32

}>;

33

34

/**

35

* TypeScript type derived from the schema

36

*/

37

type SitemapSchema = TypeOf<typeof schema>;

38

```

39

40

### Collection Enhancement

41

42

Function to enhance Nuxt Content collections with sitemap schema validation.

43

44

```typescript { .api }

45

/**

46

* Enhances a Nuxt Content collection with sitemap schema validation

47

* @param collection - The Nuxt Content collection to enhance

48

* @returns Enhanced collection with sitemap schema validation

49

*/

50

function asSitemapCollection<T extends ZodRawShape>(

51

collection: Collection<T>

52

): Collection<T>;

53

```

54

55

### Schema Field Types

56

57

**Basic Sitemap Fields**

58

59

```typescript { .api }

60

interface SitemapContentFields {

61

/** Custom URL location (overrides default content URL) */

62

loc?: string;

63

/** Last modification date */

64

lastmod?: Date;

65

/** How frequently the page is likely to change */

66

changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';

67

/** Priority of this URL relative to other URLs on your site (0.0 to 1.0) */

68

priority?: number;

69

/** Associated images for this content */

70

images?: ImageEntry[];

71

/** Associated videos for this content */

72

videos?: VideoEntry[];

73

}

74

```

75

76

**Image Metadata Schema**

77

78

```typescript { .api }

79

interface ImageEntry {

80

/** Image URL location */

81

loc: string;

82

/** Image caption */

83

caption?: string;

84

/** Geographic location of the image */

85

geo_location?: string;

86

/** Image title */

87

title?: string;

88

/** License URL for the image */

89

license?: string;

90

}

91

```

92

93

**Video Metadata Schema**

94

95

```typescript { .api }

96

interface VideoEntry {

97

/** Video content URL */

98

content_loc: string;

99

/** Video player URL */

100

player_loc?: string;

101

/** Duration in seconds */

102

duration?: string;

103

/** Expiration date for the video */

104

expiration_date?: Date;

105

/** Video rating (0.0 to 5.0) */

106

rating?: number;

107

/** View count */

108

view_count?: number;

109

/** Publication date */

110

publication_date?: Date;

111

/** Whether the video is family friendly */

112

family_friendly?: boolean;

113

/** Video tag */

114

tag?: string;

115

/** Video category */

116

category?: string;

117

/** Geographic restrictions */

118

restriction?: {

119

relationship?: 'allow';

120

value?: string;

121

};

122

/** Gallery location URL */

123

gallery_loc?: string;

124

/** Price information */

125

price?: string;

126

/** Whether a subscription is required */

127

requires_subscription?: boolean;

128

/** Uploader information */

129

uploader?: string;

130

}

131

```

132

133

**Usage Examples:**

134

135

```typescript

136

// content/blog/my-post.md frontmatter

137

/*

138

---

139

title: My Blog Post

140

sitemap:

141

priority: 0.8

142

changefreq: weekly

143

images:

144

- loc: /images/blog/my-post-hero.jpg

145

caption: Hero image for my blog post

146

title: Blog Post Hero

147

- loc: /images/blog/my-post-diagram.png

148

caption: Technical diagram

149

videos:

150

- content_loc: /videos/blog/my-post-demo.mp4

151

duration: "120"

152

family_friendly: true

153

category: tutorial

154

---

155

*/

156

157

// Enhance a Nuxt Content collection

158

import { asSitemapCollection } from '@nuxtjs/sitemap/content';

159

import { defineCollection, z } from '@nuxt/content';

160

161

export const blogCollection = asSitemapCollection(

162

defineCollection({

163

name: 'blog',

164

pattern: 'blog/**/*.md',

165

schema: z.object({

166

title: z.string(),

167

description: z.string(),

168

publishedAt: z.date(),

169

})

170

})

171

);

172

173

// Using the schema in validation

174

import { schema } from '@nuxtjs/sitemap/content';

175

176

const contentWithSitemap = {

177

title: 'My Article',

178

sitemap: {

179

priority: 0.9,

180

changefreq: 'weekly',

181

images: [{

182

loc: '/hero-image.jpg',

183

caption: 'Article hero image'

184

}]

185

}

186

};

187

188

const result = schema.parse(contentWithSitemap);

189

```

190

191

## Integration with Nuxt Content

192

193

**Automatic Content-Driven Sitemaps**

194

195

When using `strictNuxtContentPaths: true` in module configuration, the module automatically:

196

197

1. Discovers all content files in your content directory

198

2. Extracts sitemap metadata from frontmatter using the schema

199

3. Generates sitemap entries with proper URLs based on content file paths

200

4. Applies any custom sitemap fields from the frontmatter

201

5. Includes images and videos referenced in the content

202

203

**Content URL Generation**

204

205

The module automatically generates URLs for content based on:

206

- Content file path structure

207

- Nuxt Content route generation rules

208

- Custom `loc` field overrides in frontmatter

209

- i18n locale prefixes (when using @nuxtjs/i18n)

210

211

**Schema Validation Benefits**

212

213

Using the sitemap schema provides:

214

- Type safety for sitemap-specific frontmatter fields

215

- Validation of image and video metadata

216

- IDE autocompletion for sitemap properties

217

- Runtime validation of content metadata

218

- Consistent structure across all content files