1
+ {{/* Returns HowTo entity for tutorials in @graph */}}
2
+
3
+ {{/* Get content for analysis */}}
4
+ {{ $content := .Content | plainify }}
5
+ {{ $wordCount := $content | countwords }}
6
+ {{ if not $wordCount }}
7
+ {{ $wordCount = 500 }}
8
+ {{ end }}
9
+
10
+ {{/* Build HowTo entity */}}
11
+ {{ $schema := dict
12
+ "@type" "HowTo"
13
+ "@id" "#main-content"
14
+ "name" .Title
15
+ "url" .Permalink
16
+ "inLanguage" "en-US"
17
+ }}
18
+
19
+ {{/* Add description */}}
20
+ {{ with (or .Params.meta_desc .Summary (printf "Learn how to %s with Pulumi" .Title)) }}
21
+ {{ $schema = merge $schema (dict "description" .) }}
22
+ {{ end }}
23
+
24
+ {{/* Generate generic steps for tutorials */}}
25
+ {{/* Since tutorials may not have explicit numbered steps, we create high-level steps */}}
26
+ {{ $steps := slice }}
27
+
28
+ {{/* Step 1: Prerequisites */}}
29
+ {{ $steps = $steps | append (dict
30
+ "@type" "HowToStep"
31
+ "name" "Prerequisites"
32
+ "text" "Install Pulumi CLI and configure your cloud provider credentials"
33
+ "position" 1
34
+ ) }}
35
+
36
+ {{/* Step 2: Create Project */}}
37
+ {{ if in $content "pulumi new" }}
38
+ {{ $steps = $steps | append (dict
39
+ "@type" "HowToStep"
40
+ "name" "Create Pulumi Project"
41
+ "text" "Initialize a new Pulumi project with the appropriate template"
42
+ "position" 2
43
+ ) }}
44
+ {{ end }}
45
+
46
+ {{/* Step 3: Write Infrastructure Code */}}
47
+ {{ $steps = $steps | append (dict
48
+ "@type" "HowToStep"
49
+ "name" "Define Infrastructure"
50
+ "text" "Write infrastructure as code using your preferred programming language"
51
+ "position" 3
52
+ ) }}
53
+
54
+ {{/* Step 4: Deploy */}}
55
+ {{ if in $content "pulumi up" }}
56
+ {{ $steps = $steps | append (dict
57
+ "@type" "HowToStep"
58
+ "name" "Deploy Infrastructure"
59
+ "text" "Deploy your infrastructure using pulumi up command"
60
+ "position" 4
61
+ ) }}
62
+ {{ end }}
63
+
64
+ {{/* Step 5: Verify */}}
65
+ {{ $steps = $steps | append (dict
66
+ "@type" "HowToStep"
67
+ "name" "Verify Deployment"
68
+ "text" "Verify your infrastructure was created successfully"
69
+ "position" 5
70
+ ) }}
71
+
72
+ {{ $schema = merge $schema (dict "step" $steps) }}
73
+
74
+ {{/* Calculate total time */}}
75
+ {{ $totalTime := "" }}
76
+ {{ with .Params.estimated_time }}
77
+ {{ $totalTime = printf "PT%dM" . }}
78
+ {{ else with .Params.duration }}
79
+ {{ $totalTime = . }}
80
+ {{ else }}
81
+ {{/* Estimate based on word count */}}
82
+ {{ $minutes := div $wordCount 200 }}
83
+ {{ if lt $minutes 10 }}{{ $minutes = 10 }}{{ end }}
84
+ {{ if gt $minutes 60 }}{{ $minutes = 60 }}{{ end }}
85
+ {{ $totalTime = printf "PT%dM" $minutes }}
86
+ {{ end }}
87
+ {{ $schema = merge $schema (dict "totalTime" $totalTime) }}
88
+
89
+ {{/* Add tools/prerequisites */}}
90
+ {{ $tools := slice }}
91
+
92
+ {{/* Auto-detect common tools */}}
93
+ {{ if or (in $content "Pulumi CLI") (in $content "pulumi new") }}
94
+ {{ $tools = $tools | append (dict
95
+ "@type" "HowToTool"
96
+ "name" "Pulumi CLI"
97
+ ) }}
98
+ {{ end }}
99
+
100
+ {{ if in $content "AWS account" }}
101
+ {{ $tools = $tools | append (dict
102
+ "@type" "HowToTool"
103
+ "name" "AWS Account"
104
+ ) }}
105
+ {{ end }}
106
+
107
+ {{ if in $content "Azure account" }}
108
+ {{ $tools = $tools | append (dict
109
+ "@type" "HowToTool"
110
+ "name" "Azure Account"
111
+ ) }}
112
+ {{ end }}
113
+
114
+ {{ if in $content "Google Cloud account" }}
115
+ {{ $tools = $tools | append (dict
116
+ "@type" "HowToTool"
117
+ "name" "Google Cloud Account"
118
+ ) }}
119
+ {{ end }}
120
+
121
+ {{ if or (in $content "Node.js") (in $content "npm") }}
122
+ {{ $tools = $tools | append (dict
123
+ "@type" "HowToTool"
124
+ "name" "Node.js"
125
+ ) }}
126
+ {{ end }}
127
+
128
+ {{ if in $content "Python" }}
129
+ {{ $tools = $tools | append (dict
130
+ "@type" "HowToTool"
131
+ "name" "Python"
132
+ ) }}
133
+ {{ end }}
134
+
135
+ {{ if $tools }}
136
+ {{ $schema = merge $schema (dict "tool" $tools) }}
137
+ {{ end }}
138
+
139
+ {{/* Add image */}}
140
+ {{ $image := "" }}
141
+ {{ if .Params.meta_image }}
142
+ {{/* Fix URL concatenation to avoid double slashes */}}
143
+ {{ $baseURL := .Permalink }}
144
+ {{ if not (strings.HasSuffix $baseURL "/") }}
145
+ {{ $baseURL = printf "%s/" $baseURL }}
146
+ {{ end }}
147
+ {{ $imagePath := .Params.meta_image }}
148
+ {{ if strings.HasPrefix $imagePath "/" }}
149
+ {{ $imagePath = strings.TrimPrefix "/" $imagePath }}
150
+ {{ end }}
151
+ {{ $image = printf "%s%s" $baseURL $imagePath }}
152
+ {{ else }}
153
+ {{ $image = "https://www.pulumi.com/images/docs/meta-images/docs-meta.png" }}
154
+ {{ end }}
155
+ {{ $schema = merge $schema (dict "image" $image) }}
156
+
157
+ {{/* Add dates */}}
158
+ {{ $publishDate := .PublishDate }}
159
+ {{ $modifiedDate := .Lastmod }}
160
+
161
+ {{/* Fix invalid dates */}}
162
+ {{ if or (not $publishDate) (eq ($publishDate.Format "2006-01-02") "0001-01-01") }}
163
+ {{ if and .GitInfo .GitInfo.AuthorDate }}
164
+ {{ $publishDate = .GitInfo.AuthorDate }}
165
+ {{ else }}
166
+ {{ $publishDate = now }}
167
+ {{ end }}
168
+ {{ end }}
169
+
170
+ {{ if or (not $modifiedDate) (eq ($modifiedDate.Format "2006-01-02") "0001-01-01") }}
171
+ {{ if and .GitInfo .GitInfo.AuthorDate }}
172
+ {{ $modifiedDate = .GitInfo.AuthorDate }}
173
+ {{ else }}
174
+ {{ $modifiedDate = $publishDate }}
175
+ {{ end }}
176
+ {{ end }}
177
+
178
+ {{ $schema = merge $schema (dict
179
+ "datePublished" ($publishDate.Format "2006-01-02T15:04:05Z07:00")
180
+ "dateModified" ($modifiedDate.Format "2006-01-02T15:04:05Z07:00")
181
+ ) }}
182
+
183
+ {{/* Add keywords */}}
184
+ {{ $keywords := "infrastructure as code, cloud, devops, tutorial, pulumi" }}
185
+ {{ with .Params.tags }}
186
+ {{ $keywords = delimit . ", " }}
187
+ {{ end }}
188
+ {{ $schema = merge $schema (dict "keywords" $keywords) }}
189
+
190
+ {{/* Add supply/yield (what the tutorial produces) */}}
191
+ {{ $titleLower := lower .Title }}
192
+ {{ if in $titleLower "creating resources" }}
193
+ {{ $schema = merge $schema (dict "yield" "Cloud infrastructure resources deployed and managed through code") }}
194
+ {{ else if in $titleLower "import" }}
195
+ {{ $schema = merge $schema (dict "yield" "Existing infrastructure imported into Pulumi management") }}
196
+ {{ else }}
197
+ {{ $schema = merge $schema (dict "yield" "Infrastructure deployed using Pulumi") }}
198
+ {{ end }}
199
+
200
+ {{ return $schema }}
0 commit comments