Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 08391cf

Browse files
authored
feat: improve guides and foundations discovery (#657)
1 parent 62ad561 commit 08391cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+472
-138
lines changed

contentlayer.config.ts

Lines changed: 104 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { defineDocumentType, makeSource } from 'contentlayer2/source-files'
1+
import {
2+
ComputedFields,
3+
defineDocumentType,
4+
defineNestedType,
5+
FieldDefs,
6+
makeSource,
7+
} from 'contentlayer2/source-files'
28
import { extractTocHeadings } from './src/mdx/remark-toc-headings.mjs'
39
import path from 'path'
410
import fs from 'fs'
@@ -7,87 +13,132 @@ const contentDirPath = 'docs'
713

814
const branch = process.env.NEXT_PUBLIC_GITHUB_BRANCH || 'main'
915

16+
const baseFields: FieldDefs = {
17+
title_seo: {
18+
type: 'string',
19+
description:
20+
'The meta title of the doc, this will override the title extracted from the markdown and the nav title',
21+
},
22+
description: {
23+
type: 'string',
24+
description: 'The description of the doc',
25+
},
26+
image: {
27+
type: 'string',
28+
description: 'The image of the doc',
29+
},
30+
image_alt: {
31+
type: 'string',
32+
description: 'The image alt of the doc',
33+
},
34+
disable_edit: {
35+
type: 'boolean',
36+
description: 'Disable the github edit button',
37+
},
38+
}
39+
40+
const computedFields: ComputedFields = {
41+
slug: {
42+
type: 'string',
43+
resolve: (doc) => doc._raw.flattenedPath,
44+
},
45+
toc: { type: 'json', resolve: (doc) => extractTocHeadings(doc.body.raw) },
46+
title: {
47+
type: 'string',
48+
resolve: async (doc) => {
49+
const headings = await extractTocHeadings(doc.body.raw, [1])
50+
51+
return headings[0]?.value
52+
},
53+
},
54+
editUrl: {
55+
type: 'string',
56+
resolve: (doc) =>
57+
`https://github.com/nitrictech/docs/edit/${branch}/docs/${doc._raw.sourceFilePath}`,
58+
},
59+
lastModified: {
60+
type: 'date',
61+
resolve: (doc) => {
62+
// Get the full path to the markdown file
63+
const filePath = path.join(
64+
process.cwd(),
65+
contentDirPath,
66+
doc._raw.sourceFilePath,
67+
)
68+
// Extract and return the last modified date
69+
const stats = fs.statSync(filePath)
70+
return stats.mtime // This is the last modified date
71+
},
72+
},
73+
}
74+
1075
const Doc = defineDocumentType(() => ({
1176
name: 'Doc',
12-
filePathPattern: '**/*.mdx',
77+
filePathPattern: '!**/guides/**/*.mdx',
78+
fields: baseFields,
79+
computedFields,
80+
}))
81+
82+
const Featured = defineNestedType(() => ({
83+
name: 'Featured',
1384
fields: {
14-
title_seo: {
85+
image: {
1586
type: 'string',
1687
description:
17-
'The meta title of the doc, this will override the title extracted from the markdown and the nav title',
88+
'The featured image of the post, not the same as og image. Use 1024x1024 with transparent background.',
89+
required: true,
1890
},
19-
description: {
91+
image_alt: {
2092
type: 'string',
21-
description: 'The description of the doc',
93+
description: 'The featured image alt of the post',
94+
required: true,
2295
},
23-
image: {
24-
type: 'string',
25-
description: 'The image of the doc',
96+
},
97+
}))
98+
99+
const Guide = defineDocumentType(() => ({
100+
name: 'Guide',
101+
filePathPattern: '**/guides/**/*.mdx',
102+
fields: {
103+
...baseFields,
104+
published_at: {
105+
type: 'date',
106+
description: 'The date the guide was published',
107+
required: true,
26108
},
27-
image_alt: {
28-
type: 'string',
29-
description: 'The image alt of the doc',
109+
updated_at: {
110+
type: 'date',
111+
description:
112+
'The date the guide was last updated, will be set to published_at if not set',
30113
},
31-
disable_edit: {
32-
type: 'boolean',
33-
description: 'Disable the github edit button',
114+
featured: {
115+
type: 'nested',
116+
of: Featured,
34117
},
35118
tags: {
36119
type: 'list',
37120
of: {
38121
type: 'string',
39122
},
40-
description: 'The tags of the post, used by guides',
123+
description: 'The tags of the post',
124+
required: true,
41125
},
42126
languages: {
43127
type: 'list',
44128
of: {
45129
type: 'string',
46130
},
47-
description: 'The languages of the content, used by guides',
131+
description: 'The languages of the content',
48132
},
49133
start_steps: {
50134
type: 'markdown',
51-
description: 'The start steps of the doc, used by guides',
52-
},
53-
},
54-
computedFields: {
55-
slug: {
56-
type: 'string',
57-
resolve: (doc) => doc._raw.flattenedPath,
58-
},
59-
toc: { type: 'json', resolve: (doc) => extractTocHeadings(doc.body.raw) },
60-
title: {
61-
type: 'string',
62-
resolve: async (doc) => {
63-
const headings = await extractTocHeadings(doc.body.raw, [1])
64-
65-
return headings[0]?.value
66-
},
67-
},
68-
editUrl: {
69-
type: 'string',
70-
resolve: (doc) =>
71-
`https://github.com/nitrictech/docs/edit/${branch}/docs/${doc._raw.sourceFilePath}`,
72-
},
73-
lastModified: {
74-
type: 'date',
75-
resolve: (doc) => {
76-
// Get the full path to the markdown file
77-
const filePath = path.join(
78-
process.cwd(),
79-
contentDirPath,
80-
doc._raw.sourceFilePath,
81-
)
82-
// Extract and return the last modified date
83-
const stats = fs.statSync(filePath)
84-
return stats.mtime // This is the last modified date
85-
},
135+
description: 'The start steps of the doc',
86136
},
87137
},
138+
computedFields,
88139
}))
89140

90141
export default makeSource({
91142
contentDirPath,
92-
documentTypes: [Doc],
143+
documentTypes: [Doc, Guide],
93144
})

docs/guides/dart/flutter.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ start_steps: |
1313
cd examples/v1/flutter
1414
flutter pub get
1515
nitric start
16+
featured:
17+
image: /docs/images/guides/flutter/featured.png
18+
image_alt: 'Building a Full Stack Flutter Application in Dart featured image'
19+
published_at: 2024-10-30
1620
---
1721

1822
# Building a Full Stack Flutter Application in Dart

docs/guides/dart/serverless-rest-api-example.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tags:
66
- Key Value Store
77
languages:
88
- dart
9+
published_at: 2024-04-24
910
---
1011

1112
# Building a REST API with Nitric

docs/guides/deploying/azure-pipelines.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ description: Deploy to AWS, Google Cloud or Microsoft Azure using Azure DevOps a
33
tags:
44
- CI/CD
55
- Azure
6+
published_at: 2023-11-01
7+
updated_at: 2024-02-04
68
---
79

810
# Deployment Automation with Azure Pipelines and Nitric

docs/guides/deploying/github-actions.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
description: Deploy to AWS, Google Cloud or Microsoft Azure using GitHub Actions and the Nitric CLI
33
tags:
44
- CI/CD
5+
published_at: 2023-12-21
6+
updated_at: 2024-08-20
57
---
68

79
# Deployment Automation with GitHub Actions and Nitric

docs/guides/deploying/gitlab-ci.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
description: Deploy to AWS, Google Cloud or Microsoft Azure using GitLab CI and the Nitric CLI
33
tags:
44
- CI/CD
5+
published_at: 2023-11-01
6+
updated_at: 2024-08-20
57
---
68

79
# Deployment Automation with GitLab CI and Nitric

docs/guides/deploying/google-cloud-build.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ description: Deploy to AWS, Google Cloud or Microsoft Azure using Google Cloud B
33
tags:
44
- CI/CD
55
- Google
6+
published_at: 2023-11-01
7+
updated_at: 2024-08-20
68
---
79

810
# Deployment Automation with Google Cloud Build and Nitric

docs/guides/go/realtime-messaging.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ start_steps: |
1010
cd examples/v1/websocket-app
1111
go mod tidy
1212
nitric start
13+
featured:
14+
image: /docs/images/guides/realtime-messaging/featured.png
15+
image_alt: 'Building a chat app in Go with WebSockets and Nitric featured image'
16+
published_at: 2024-10-16
1317
---
1418

1519
# Building a chat app in Go with WebSockets and Nitric

docs/guides/go/serverless-rest-api-example.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ tags:
66
- Key Value Store
77
languages:
88
- go
9+
published_at: 2023-08-11
10+
updated_at: 2024-10-03
911
---
1012

1113
# Building your first API with Nitric

docs/guides/jvm/serverless-rest-api-example.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description: Use the Nitric framework to easily build and deploy JVM REST APIs f
44
tags:
55
- API
66
- Key Value Store
7+
published_at: 2023-10-12
78
---
89

910
<Note>

0 commit comments

Comments
 (0)