microsoft / PSDocs

Generate documentation from Infrastructure as Code (IaC).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for dynamically naming output files

BernieWhite opened this issue · comments

Currently there is no real ability to dynamically change the name of the generated output file based on content within PSDocs. It needs to be decided before Invoke-PSDocument is called and passed as a parameter.

In the absence of -InstanceName the output file uses the name of the document definition.

This approach is inflexible at large scale because it generally requires a PowerShell wrapper block to be used.

For example:

# Scan for Azure template file recursively in the templates/ directory
Get-AzDocTemplateFile -Path templates/ | ForEach-Object {
    # Generate a standard name of the markdown file. i.e. <name>_<version>.md
    $template = Get-Item -Path $_.TemplateFile;
    $templateName = $template.Directory.Parent.Name;
    $version = $template.Directory.Name;
    $docName = "$($templateName)_$version";

    # Generate markdown
    Invoke-PSDocument -Module PSDocs.Azure -OutputPath out/docs/ -InputObject $template.FullName -InstanceName $docName;
}