Skip to content

Commit f12f451

Browse files
authored
Added support for reading template metadata from metadata.json #32 (#59)
* Added support for reading template metadata from metadata.json #32 * Updates to improve quickstart support #60
1 parent 5e55425 commit f12f451

9 files changed

Lines changed: 120 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ What's changed since v0.2.0:
88
- Added support for naming document by parent path using conventions. [#43](https://github.com/Azure/PSDocs.Azure/issues/43)
99
- Add the `-Convention` parameter with `Azure.NameByParentPath` to use.
1010
- See [about_PSDocs_Azure_Conventions] for details.
11+
- General improvements:
12+
- Added support for reading template metadata from `metadata.json`. [#32](https://github.com/Azure/PSDocs.Azure/issues/32)
13+
- This adds additional compatibility for the Azure Quickstart templates repository.
14+
- Additional metadata from `metadata.json` will be read when it exists.
15+
- Template metadata take priority over `metadata.json`.
16+
- Added support for the `summary` template metadata property. [#60](https://github.com/Azure/PSDocs.Azure/issues/60)
17+
- The `summary` template metadata property is intended to provide a short description of the template.
18+
- Use the `description` template metadata property to provide a detailed description of the template.
1119

1220
## v0.2.0
1321

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ The source template and generated output are provided below.
4141
- [Azure template][source-template]
4242
- [Output markdown][output-template]
4343

44+
For frequently asked questions, see the [FAQ].
45+
4446
### Annotate templates file
4547

4648
In its simplest structure, an Azure template has the following elements:
@@ -120,7 +122,8 @@ PSDocs supports the following metadata:
120122
Field | Scope | Type | Description
121123
----- | ----- | ---- | -----------
122124
`name` | Template | `string` | Used for markdown page title.
123-
`description` | Template | `string` | Used as the top description for the markdown page.
125+
`summary` | Template | `string` | Used as a short description for the markdown page.
126+
`description` | Template | `string` | Used as a detailed description for the markdown page.
124127
`description` | Parameter | `string` | Used as the description for the parameter.
125128
`example` | Parameter | `string`, `boolean`, `object`, or `array` | An example use of the parameter. The example is included in the JSON snippet. If an example is not included the default value is used instead.
126129
`ignore` | Parameter | `boolean` | When `true` the parameter is not included in the JSON snippet.
@@ -333,3 +336,4 @@ This project is [licensed under the MIT License](LICENSE).
333336
[create-workflow]: https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file
334337
[source-template]: templates/storage/v1/template.json
335338
[output-template]: templates/storage/v1/README.md
339+
[FAQ]: docs/features.md#frequently-asked-questions-faq

docs/features.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,56 @@ PSDocs runs on MacOS, Linux and Windows.
3535
PowerShell makes it easy to integrate PSDocs into popular CI systems.
3636
To install, use the `Install-Module` cmdlet within PowerShell.
3737
For installation options see [install instructions](install-instructions.md).
38+
39+
## Frequently Asked Questions (FAQ)
40+
41+
### Can PSDocs read from metadata.json?
42+
43+
The Azure Quickstart Templates repository uses an additional `metadata.json` to store template metadata.
44+
PSDocs doesn't require a `metadata.json` file to exist but will fallback to this file if it exists.
45+
For details on `metadata.json` see [Azure Resource Manager QuickStart Templates contributing guide].
46+
47+
PSDocs reads `metadata.json` using the following logic:
48+
49+
1. Metadata is loaded from the template `metadata` property.
50+
2. When `metadata.json` exists, properties are merged with the template metadata.
51+
- Properties included in template metadata override properties included from `metadata.json`.
52+
- The `$schema` property from `metadata.json` is ignored.
53+
- For PSDocs to discover `metadata.json` it must exist in the same directory as the template file.
54+
When creating `metadata.json` use only lowercase in the file name.
55+
56+
The schema of `metadata.json` differs from template metadata.
57+
To maintain compatibility, PSDocs automatically maps the metadata as described in the following table.
58+
59+
metadata.json | | Template metadata | Description
60+
------------- | ------- | ----------------- | ------
61+
`itemDisplayName` | Maps to | `name` | Used for markdown page title.
62+
`summary` | Maps to | `summary` | Used as a short description for the markdown page.
63+
`description` | Maps to | `description` | Used as a detailed description for the markdown page.
64+
65+
For example:
66+
67+
- If `name` exists in template metadata, this will take priority over `itemDisplayName` from `metadata.json`.
68+
- If `name` does not exist in template metadata, `itemDisplayName` from `metadata.json` will be used.
69+
70+
### How do I include a badge image?
71+
72+
To include a badge image, create the `.ps-docs/azure-template-badges.md` file.
73+
Within this file add markdown links to your badge image.
74+
75+
Use the following placeholders to reference unique images per template.
76+
77+
- `{{ template_path }}` - The relative path of the template directory.
78+
- `{{ template_path_encoded }}` - The relative path of the template directory URL encoded.
79+
80+
See [about_PSDocs_Azure_Badges] for additional details.
81+
82+
### Can PSDocs generate badges for documentation?
83+
84+
No.
85+
PSDocs can not generate badge images for you.
86+
87+
Once you have generated a badge, PSDocs can include a link to the badge for displaying directly in markdown.
88+
89+
[about_PSDocs_Azure_Badges]: concepts/en-US/about_PSDocs_Azure_Badges.md
90+
[Azure Resource Manager QuickStart Templates contributing guide]: https://github.com/Azure/azure-quickstart-templates/tree/master/1-CONTRIBUTION-GUIDE#metadatajson

src/PSDocs.Azure/docs/Azure.Template.Doc.ps1

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,43 @@ function global:GetTemplateRelativePath {
129129
# A function to import metadata
130130
function global:GetTemplateMetadata {
131131
[CmdletBinding()]
132+
[OutputType([Hashtable])]
132133
param (
133134
[Parameter(Mandatory = $True)]
134135
[String]$Path
135136
)
136137
process {
138+
$metadata = @{};
139+
140+
# Get metadata from template file
137141
$template = Get-Content -Path $Path -Raw | ConvertFrom-Json;
138142
if ([bool]$template.PSObject.Properties['metadata']) {
139-
return $template.metadata;
143+
foreach ($property in $template.metadata.PSObject.Properties.GetEnumerator()) {
144+
$metadata[$property.Name] = $property.Value;
145+
}
146+
}
147+
148+
# Get missing metadata from metadata.json
149+
$metadataFilePath = Join-Path -Path (Split-Path -Path $Path -Parent) -ChildPath 'metadata.json';
150+
if (Test-Path -Path $metadataFilePath) {
151+
$extraMetadata = Get-Content -Path $metadataFilePath -Raw | ConvertFrom-Json;
152+
foreach ($property in $extraMetadata.PSObject.Properties.GetEnumerator()) {
153+
154+
if ($property.Name -eq 'itemDisplayName' -and !$metadata.ContainsKey('name')) {
155+
$metadata['name'] = $property.Value;
156+
}
157+
elseif ($property.Name -eq 'summary' -and !$metadata.ContainsKey('summary')) {
158+
$metadata['summary'] = $property.Value;
159+
}
160+
elseif ($property.Name -eq 'description' -and !$metadata.ContainsKey('description')) {
161+
$metadata['description'] = $property.Value;
162+
}
163+
elseif (!$metadata.ContainsKey($property.Name) -and $property.Name -ne '$schema') {
164+
$metadata[$property.Name] = $property.Value;
165+
}
166+
}
140167
}
168+
return $metadata;
141169
}
142170
}
143171

@@ -174,13 +202,18 @@ Document 'README' {
174202
$outputs = GetTemplateOutput -Path $templatePath;
175203

176204
# Set document title
177-
if ($Null -ne $metadata -and [bool]$metadata.PSObject.Properties['name']) {
205+
if ($Null -ne $metadata -and $metadata.ContainsKey('name')) {
178206
Title $metadata.name
179207
}
180208
else {
181209
Title $LocalizedData.DefaultTitle
182210
}
183211

212+
# Add short description
213+
if ($Null -ne $metadata -and $metadata.ContainsKey('summary')) {
214+
$metadata.summary
215+
}
216+
184217
# Add badges
185218
$relativePath = (Split-Path (GetTemplateRelativePath -Path $templatePath) -Parent).Replace('\', '/').TrimStart('/');
186219
$relativePathEncoded = [System.Web.HttpUtility]::UrlEncode($relativePath);
@@ -192,8 +225,8 @@ Document 'README' {
192225
Write-Verbose $relativePath
193226
Write-Verbose $relativePathEncoded
194227

195-
# Write opening line
196-
if ($Null -ne $metadata -and [bool]$metadata.PSObject.Properties['description']) {
228+
# Add detailed description
229+
if ($Null -ne $metadata -and $metadata.ContainsKey('description')) {
197230
$metadata.description
198231
}
199232

templates/storage/v1/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Create or update a Storage Account.
44

5+
This template deploys a Storage Account including blob containers and files shares. Encryption in transit it enabled using a minimum of TLS 1.2.
6+
57
## Parameters
68

79
Parameter name | Description

templates/storage/v1/template.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"contentVersion": "1.0.0.0",
44
"metadata": {
55
"name": "Storage Account",
6-
"description": "Create or update a Storage Account."
6+
"summary": "Create or update a Storage Account.",
7+
"description": "This template deploys a Storage Account including blob containers and files shares. Encryption in transit it enabled using a minimum of TLS 1.2."
78
},
89
"parameters": {
910
"storageAccountName": {

tests/PSDocs.Azure.Tests/Azure.QuickStart.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Describe 'Templates' -Tag 'QuickStart' {
3838
$template = Get-Item -Path $_.TemplateFile;
3939
$actualContent = Invoke-PSDocument @invokeParams -OutputPath $outputPath -InputObject $template.FullName -PassThru;
4040
$actualContent | Should -BeLike '*!`[Azure Public Test Date`](https://azurequickstartsservice.blob.core.windows.net/badges/template-test/PublicLastTestDate.svg)*';
41+
$actualContent | Should -BeLike "`# Storage Account*";
42+
$actualContent | Should -BeLike "*Create an empty Storage Account.*";
43+
$actualContent | Should -BeLike "*This template deploys a Storage Account including blob containers and files shares. Encryption in transit it enabled using a minimum of TLS 1.2.*";
4144
$actualContent;
4245
}
4346
$result | Should -Not -BeNullOrEmpty;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://aka.ms/azure-quickstart-templates-metadata-schema#",
3+
"itemDisplayName": "Storage Account",
4+
"description": "This template deploys an creates a Storage Account in an Azure subscription.",
5+
"summary": "Create an empty Storage Account.",
6+
"githubUsername": "BernieWhite",
7+
"type": "QuickStart",
8+
"dateUpdated": "2021-03-11"
9+
}

tests/PSDocs.Azure.Tests/template-test/template.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
33
"contentVersion": "1.0.0.0",
44
"metadata": {
5-
"name": "Storage Account",
6-
"description": "Create or update a Storage Account."
5+
"description": "This template deploys a Storage Account including blob containers and files shares. Encryption in transit it enabled using a minimum of TLS 1.2."
76
},
87
"parameters": {
98
"storageAccountName": {

0 commit comments

Comments
 (0)