Skip to content

Commit bba831e

Browse files
db-cloudflaremaheshwarip
authored andcommitted
[Style guide] Tutorial template (#17431)
* Add new tutorial template * Update tutorial template
1 parent b8276ae commit bba831e

File tree

2 files changed

+113
-13
lines changed

2 files changed

+113
-13
lines changed

src/content/docs/style-guide/documentation-content-strategy/content-types/tutorial.mdx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,7 @@ import { GlossaryDefinition, Render } from "~/components";
1111

1212
## Template
1313

14-
We have a [pre-built template](https://github.com/cloudflare/cloudflare-docs/blob/production/archetypes/tutorial.md) that helps you follow our general structure and content guidelines.
15-
16-
You can copy the file directly or - if you have [Hugo](https://github.com/cloudflare/cloudflare-docs?tab=readme-ov-file#setup) installed on your local machine - you can run the following command:
17-
18-
```sh
19-
hugo new content --kind tutorial {new_file_location}
20-
```
21-
22-
In practice, that might look like:
23-
24-
```sh
25-
hugo new content --kind tutorial content/workers/tutorials/new-tutorial.md
26-
```
14+
We have a [tutorial template](https://github.com/cloudflare/cloudflare-docs/blob/production/templates/tutorial-template.mdx) that helps you follow our general structure and content guidelines.
2715

2816
## Guidelines
2917

templates/tutorial-template.mdx

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
updated: YYYY-MM-DD
3+
difficulty: Beginner | Intermediate | Expert
4+
content_type: 📝 Tutorial
5+
pcx_content_type: tutorial
6+
title: Tutorial title. Second-person imperative verb phrase that reflects user goal or job-to-be-done. For example, 'Create a Worker' or 'Build a Pages application'.
7+
products:
8+
- Workers
9+
languages:
10+
- TypeScript
11+
---
12+
13+
import { Render, PackageManagers } from "~/components";
14+
15+
(Introduce the purpose of this tutorial here. Describe the application which will be built by the end of this tutorial and the tools that will be used to achieve this. You can also optionally describe the intended audience, include a [GitHub link](https://github.com/) to completed code, and even outline a summary of the steps that the reader will be performing throughout this tutorial.
16+
17+
In this tutorial, you will learn how to run serverless script on the web by creating a Worker using Cloudflare's CLI tools C3 and Wrangler.
18+
19+
## Prerequisites
20+
21+
(List out any required prerequisites before the reader can begin following this tutorial. If your tutorial requires Workers, you can load pre-written Workers prerequisites by including the render below))
22+
23+
<Render file="prereqs" product="workers" />
24+
25+
(Additional prerequisites will need to be manually added like below)
26+
27+
- Prerequisite 3
28+
- Prerequisite 4
29+
- Prerequisite 5
30+
31+
## 1. Create a Worker. (The step title should describe what is being achieved within the step. If a step is becoming too large, see if it can be broken down into smaller steps.)
32+
33+
(To include a CLI command with tabs to select between npm, yarn or pnpm, use the example below.)
34+
35+
First, use the `c3` CLI to create a new Cloudflare Workers project.
36+
37+
<PackageManagers type="create" pkg="cloudflare@latest" args={"<WORKER_NAME>"} />
38+
39+
Replace `<WORKER_NAME>` with your desired Worker name.
40+
41+
## 2. Tets run your Worker on a local server
42+
43+
(To include a shell command, use the examples below [For code block guidelines read our style guide](/style-guide/formatting/code-block-guidelines/).)
44+
45+
Next, change into the newly created Worker's directory.
46+
47+
```sh title="Change directory into worker"
48+
cd <WORKER_NAME>
49+
```
50+
51+
Now we can run our Worker locally to test that it works.
52+
53+
```sh title="Run Worker on a local development server"
54+
npx wrangler dev
55+
```
56+
57+
(To include a number list such as for following numbered steps, use the example below.)
58+
59+
1. Step 1
60+
2. Step 2
61+
62+
## 3. (Additional tutorial tips)
63+
64+
(JavaScript example.)
65+
66+
```js
67+
---
68+
filename: src/index.js
69+
---
70+
export default {
71+
async fetch(request, env, ctx) {
72+
return new Response("Hello World!");
73+
},
74+
};
75+
```
76+
77+
(Wrangler toml file example.)
78+
79+
```toml title="wrangler.toml"
80+
#:schema node_modules/wrangler/config-schema.json
81+
name = "<WORKER_NAME>"
82+
main = "src/index.ts"
83+
compatibility_date = "YYYY-MM-DD"
84+
compatibility_flags = ["nodejs_compat"]
85+
86+
[ai]
87+
binding = "AI"
88+
```
89+
90+
(Aside examples. For more details read our [style guide documentation on Notes/tips/warnings](/style-guide/documentation-content-strategy/component-attributes/notes-tips-warnings/#recommendations).)
91+
92+
:::note[Aside example]
93+
An aside is a colored info box or aside with content (text, images, lists, code blocks) that adds relevant notes that do not fit the main text
94+
:::
95+
96+
:::caution[Aside example]
97+
A caution warns users of specific behavior that can break functionality or impact security.
98+
:::
99+
100+
(At the end of the tutorial's steps, summarize what has been successfully achieved by the reader through completing this tutorial)
101+
102+
You have successfully created, tested and deployed a Worker.
103+
104+
## Related resources
105+
106+
(Cloudflare docs link example)
107+
108+
To build more with Workers, refer to [Tutorials](/workers/tutorials/).
109+
110+
(External link example)
111+
112+
If you have any questions, need assistance, or would like to share your project, join the Cloudflare Developer community on [Discord](https://discord.cloudflare.com) to connect with other developers and the Cloudflare team.

0 commit comments

Comments
 (0)