Skip to content

Commit 5e55425

Browse files
authored
Added support for naming document by parent path using conventions #43 (#58)
* Added support for naming document by parent path using conventions #43 * Added updates based on feedback
1 parent 3f8c56f commit 5e55425

6 files changed

Lines changed: 134 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
## Unreleased
44

5+
What's changed since v0.2.0:
6+
7+
- New Features:
8+
- Added support for naming document by parent path using conventions. [#43](https://github.com/Azure/PSDocs.Azure/issues/43)
9+
- Add the `-Convention` parameter with `Azure.NameByParentPath` to use.
10+
- See [about_PSDocs_Azure_Conventions] for details.
11+
512
## v0.2.0
13+
614
What's changed since v0.1.0:
715

816
- New Features:
@@ -16,20 +24,21 @@ What's changed since v0.1.0:
1624
- Set the `.ps-docs/azure-template-badges.md` file to include badge content.
1725
- See [about_PSDocs_Azure_Badges] for details.
1826
- Template outputs are added to generated document. [#28](https://github.com/Azure/PSDocs.Azure/issues/28)
19-
27+
- General Improvements
28+
- Minor update to the documentation to include OutputPath to generate README.md [#50](https://github.com/Azure/PSDocs.Azure/issues/50)
29+
- Engineering:
30+
- Bump PSDocs dependency to v0.8.0. [#42](https://github.com/Azure/PSDocs.Azure/issues/42)
2031
- Bug fixes:
2132
- Fixed snippet with short relative template causes exception. [#26](https://github.com/Azure/PSDocs.Azure/issues/26)
2233
- Fixed cannot bind argument when metadata name is not set. [#35](https://github.com/Azure/PSDocs.Azure/issues/35)
2334

24-
- Engineering:
25-
- Bump PSDocs dependency to v0.8.0. [#42](https://github.com/Azure/PSDocs.Azure/issues/42)
35+
What's changed since pre-release v0.2.0-B2102012:
2636

27-
- General Improvements
28-
- Minor update to the documentation to include OutputPath to generate README.md [#50](https://github.com/Azure/PSDocs.Azure/issues/50)
37+
- No additional changes.
2938

3039
## v0.2.0-B2102012 (pre-release)
3140

32-
What's changed since pre-release v0.2.0-B2102012:
41+
What's changed since pre-release v0.2.0-B2102005:
3342

3443
- New features:
3544
- Added the ability to enable manual command line snippet. [#40](https://github.com/Azure/PSDocs.Azure/issues/40)
@@ -79,3 +88,4 @@ What's changed since pre-release v0.1.0-B2012006:
7988

8089
[about_PSDocs_Azure_Configuration]: docs/concepts/en-US/about_PSDocs_Azure_Configuration.md
8190
[about_PSDocs_Azure_Badges]: docs/concepts/en-US/about_PSDocs_Azure_Badges.md
91+
[about_PSDocs_Azure_Conventions]: docs/concepts/en-US/about_PSDocs_Azure_Conventions.md

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ The following conceptual topics exist in the `PSDocs.Azure` module:
291291
- [Configuration](docs/concepts/en-US/about_PSDocs_Azure_Configuration.md)
292292
- [AZURE_USE_PARAMETER_FILE_SNIPPET](docs/concepts/en-US/about_PSDocs_Azure_Configuration.md#azure_use_parameter_file_snippet)
293293
- [AZURE_USE_COMMAND_LINE_SNIPPET](docs/concepts/en-US/about_PSDocs_Azure_Configuration.md#azure_use_command_line_snippet)
294+
- [Conventions](docs/concepts/en-US/about_PSDocs_Azure_Conventions.md)
295+
- [Azure.NameByParentPath](docs/concepts/en-US/about_PSDocs_Azure_Conventions.md#azurenamebyparentpath)
294296

295297
## Changes and versioning
296298

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# PSDocs_Azure_Conventions
2+
3+
## about_PSDocs_Azure_Conventions
4+
5+
## SHORT DESCRIPTION
6+
7+
Describes how to use conventions included in `PSDocs.Azure`.
8+
9+
## LONG DESCRIPTION
10+
11+
PSDocs for Azure includes conventions that can be included when generating documentation.
12+
Conventions alter the default pipeline to customize it for a specific situation.
13+
14+
When running `Invoke-PSDocument` add the `-Convention` parameter to specify one or more conventions.
15+
For example:
16+
17+
```powershell
18+
Invoke-PSDocument -Convention 'Azure.NameByParentPath';
19+
```
20+
21+
### Azure.NameByParentPath
22+
23+
This convention can be used to change the default naming for documents.
24+
By default new documents are generated with the `README.md` file name.
25+
26+
When the template file is stored under a well-known path `<name>/<version>/template.json` or `<name>/template.json`.
27+
i.e. `templates/storage/v1/template.json` or `templates/storage/template.json`
28+
29+
The `name` and `version` can be used to name the output file.
30+
The resulting file name is updated to `<name>_<version>.md`.
31+
i.e. `storage_v1.md`
32+
33+
For `version` to be detected, the version sub-directory must start with `v` and be followed by a number.
34+
When the version sub-directory a not detected the resulting file name is updated to `<name>.md`.
35+
i.e. `storage.md`
36+
37+
## NOTE
38+
39+
An online version of this document is available at https://github.com/Azure/PSDocs.Azure/blob/main/docs/concepts/en-US/about_PSDocs_Azure_Conventions.md.
40+
41+
## KEYWORDS
42+
43+
- Convention
44+
- NameByParentPath

pipeline.build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ task BuildHelp BuildModule, PlatyPS, {
234234
&$pwshPath -Command {
235235
# Generate MAML and about topics
236236
Import-Module -Name PlatyPS -Verbose:$False;
237-
$Null = New-ExternalHelp -OutputPath 'out/docs/PSDocs.Azure' -Path '.\docs\commands\en-US' -Force;
237+
$Null = New-ExternalHelp -OutputPath 'out/docs/PSDocs.Azure' -Path '.\docs\commands\en-US', '.\docs\concepts\en-US' -Force;
238238
}
239239
}
240240

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
# Synopsis: Name documents by parent path.
5+
Export-PSDocumentConvention 'Azure.NameByParentPath' {
6+
$template = Get-Item -Path $PSDocs.TargetObject;
7+
8+
# Get parent directory paths where <name>/v<version>/template.json
9+
$version = $template.Directory.Name;
10+
$name = $template.Directory.Parent.Name;
11+
12+
# Name the document <name>_<version>.md
13+
$docName = $version;
14+
if ($version -like 'v[0-9]*') {
15+
$docName = [String]::Concat($name, '_', $version);
16+
}
17+
$PSDocs.Document.InstanceName = $docName;
18+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
#
5+
# Unit tests for PSDocs.Azure document conventions
6+
#
7+
8+
[CmdletBinding()]
9+
param ()
10+
11+
# Setup error handling
12+
$ErrorActionPreference = 'Stop';
13+
Set-StrictMode -Version latest;
14+
15+
# Setup tests paths
16+
$rootPath = $PWD;
17+
$here = $PSScriptRoot;
18+
19+
Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs.Azure) -Force;
20+
21+
$outputPath = Join-Path -Path $rootPath -ChildPath out/tests/PSDocs.Azure.Tests/Conventions;
22+
Remove-Item -Path $outputPath -Force -Recurse -Confirm:$False -ErrorAction Ignore;
23+
$Null = New-Item -Path $outputPath -ItemType Directory -Force;
24+
25+
Describe 'Conventions' -Tag 'Conventions' {
26+
Context 'Azure.NameByParentPath' {
27+
It 'Uses naming convention' {
28+
$invokeParams = @{
29+
Module = 'PSDocs.Azure'
30+
}
31+
32+
# Generates templates
33+
$templatePath = Join-Path -Path $rootPath -ChildPath 'templates/';
34+
$result = Get-AzDocTemplateFile -Path $templatePath | ForEach-Object {
35+
$template = Get-Item -Path $_.TemplateFile;
36+
Invoke-PSDocument @invokeParams -OutputPath $outputPath -InputObject $template.FullName -Convention 'Azure.NameByParentPath'
37+
}
38+
$result | Should -Not -BeNullOrEmpty;
39+
$result[0].Name | Should -BeLike 'storage_v1.md';
40+
$result;
41+
42+
# Generates templates without version path
43+
$templatePath = Join-Path -Path $here -ChildPath 'template-test/';
44+
$result = Get-AzDocTemplateFile -Path $templatePath | ForEach-Object {
45+
$template = Get-Item -Path $_.TemplateFile;
46+
Invoke-PSDocument @invokeParams -OutputPath $outputPath -InputObject $template.FullName -Convention 'Azure.NameByParentPath'
47+
}
48+
$result | Should -Not -BeNullOrEmpty;
49+
$result[0].Name | Should -BeLike 'template-test.md';
50+
$result;
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)