-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move entire docgeneration into common tools #1219
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ca8dc64
Move entire docgeneration into common tools
sima-zhu 2612ead
Move docindex to common
sima-zhu 377df5a
Added the package replacement logic
sima-zhu ba986dc
Fixed on parameters
sima-zhu f519716
Fixed param
sima-zhu ec7c708
Change function to dash
sima-zhu e77f1c4
Added regex on function
sima-zhu 9711ed8
Added display name.
sima-zhu 9c4c0ba
Update eng/common/docgeneration/Generate-DocIndex.ps1
sima-zhu d39fcf2
Deal with js
sima-zhu 4a6eed5
Merge branch 'docgeneration' of https://github.com/sima-zhu/azure-sdk…
sima-zhu 5e704e3
Add no new line args
sima-zhu 9dfb29c
revert some test changes
sima-zhu 37c590c
Need to default to the double quotes for JS regex
sima-zhu 313e010
Update Generate-DocIndex.ps1
sima-zhu d167a4f
Added the appTitle
sima-zhu 0046a62
type
sima-zhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
# Generates an index page for cataloging different versions of the Docs | ||
[CmdletBinding()] | ||
Param ( | ||
$DocFx, | ||
$RepoRoot, | ||
$DocGenDir, | ||
$DocOutDir = "${RepoRoot}/docfx_project", | ||
$DocfxJsonPath = "${PSScriptRoot}\docfx.json", | ||
$MainJsPath = "${PSScriptRoot}\templates\matthews\styles\main.js" | ||
) | ||
. "${PSScriptRoot}\..\scripts\common.ps1" | ||
$GetGithubIoDocIndexFn = "Get-${Language}-GithubIoDocIndex" | ||
|
||
# Given the metadata url under https://github.com/Azure/azure-sdk/tree/master/_data/releases/latest, | ||
# the function will return the csv metadata back as part of response. | ||
function Get-CSVMetadata ([string]$MetadataUri) { | ||
$metadataResponse = Invoke-RestMethod -Uri $MetadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv | ||
return $metadataResponse | ||
} | ||
|
||
# Given the github io blob storage url and language regex, | ||
# the helper function will return a list of artifact names. | ||
function Get-BlobStorage-Artifacts($blobStorageUrl, $blobDirectoryRegex, $blobArtifactsReplacement) { | ||
LogDebug "Reading artifact from storage blob ..." | ||
$returnedArtifacts = @() | ||
$pageToken = "" | ||
Do { | ||
$resp = "" | ||
if (!$pageToken) { | ||
# First page call. | ||
$resp = Invoke-RestMethod -Method Get -Uri $blobStorageUrl | ||
} | ||
else { | ||
# Next page call | ||
$blobStorageUrlPageToken = $blobStorageUrl + "&marker=$pageToken" | ||
$resp = Invoke-RestMethod -Method Get -Uri $blobStorageUrlPageToken | ||
} | ||
# Convert to xml documents. | ||
$xmlDoc = [xml](removeBomFromString $resp) | ||
foreach ($elem in $xmlDoc.EnumerationResults.Blobs.BlobPrefix) { | ||
# What service return like "dotnet/Azure.AI.Anomalydetector/", needs to fetch out "Azure.AI.Anomalydetector" | ||
$artifact = $elem.Name -replace $blobDirectoryRegex, $blobArtifactsReplacement | ||
$returnedArtifacts += $artifact | ||
} | ||
# Fetch page token | ||
$pageToken = $xmlDoc.EnumerationResults.NextMarker | ||
} while ($pageToken) | ||
return $returnedArtifacts | ||
} | ||
|
||
# The sequence of Bom bytes differs by different encoding. | ||
# The helper function here is only to strip the utf-8 encoding system as it is used by blob storage list api. | ||
# Return the original string if not in BOM utf-8 sequence. | ||
function RemoveBomFromString([string]$bomAwareString) { | ||
if ($bomAwareString.length -le 3) { | ||
return $bomAwareString | ||
} | ||
$bomPatternByteArray = [byte[]] (0xef, 0xbb, 0xbf) | ||
# The default encoding for powershell is ISO-8859-1, so converting bytes with the encoding. | ||
$bomAwareBytes = [Text.Encoding]::GetEncoding(28591).GetBytes($bomAwareString.Substring(0, 3)) | ||
if (@(Compare-Object $bomPatternByteArray $bomAwareBytes -SyncWindow 0).Length -eq 0) { | ||
return $bomAwareString.Substring(3) | ||
} | ||
return $bomAwareString | ||
} | ||
|
||
function Get-TocMapping { | ||
Param ( | ||
[Parameter(Mandatory = $true)] [Object[]] $metadata, | ||
[Parameter(Mandatory = $true)] [String[]] $artifacts | ||
) | ||
# Used for sorting the toc display order | ||
$orderServiceMapping = @{} | ||
|
||
foreach ($artifact in $artifacts) { | ||
$packageInfo = $metadata | ? {$_.Package -eq $artifact} | ||
|
||
if ($packageInfo -and $packageInfo[0].Hide -eq 'true') { | ||
LogDebug "The artifact $artifact set 'Hide' to 'true'." | ||
continue | ||
} | ||
$serviceName = "" | ||
$displayName = "" | ||
if (!$packageInfo) { | ||
LogWarning "There is no artifact $artifact. Please check csv of Azure/azure-sdk/_data/release/latest repo if this is intended. " | ||
# If no service name retrieved, print out warning message, and put it into Other page. | ||
$serviceName = "Other" | ||
} | ||
elseif (!$packageInfo[0].ServiceName) { | ||
LogWarning "There is no service name for artifact $artifact. Please check csv of Azure/azure-sdk/_data/release/latest repo if this is intended. " | ||
# If no service name retrieved, print out warning message, and put it into Other page. | ||
$serviceName = "Other" | ||
$displayName = $packageInfo[0].DisplayName.Trim() | ||
} | ||
else { | ||
if ($packageInfo.Length -gt 1) { | ||
LogWarning "There are more than 1 packages fetched out for artifact $artifact. Please check csv of Azure/azure-sdk/_data/release/latest repo if this is intended. " | ||
} | ||
$serviceName = $packageInfo[0].ServiceName.Trim() | ||
$displayName = $packageInfo[0].DisplayName.Trim() | ||
} | ||
$orderServiceMapping[$artifact] = @($serviceName, $displayName) | ||
} | ||
return $orderServiceMapping | ||
} | ||
|
||
function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang) { | ||
LogDebug "Start generating the docfx toc and build docfx site..." | ||
|
||
LogDebug "Initializing Default DocFx Site..." | ||
& $($DocFx) init -q -o "${DocOutDir}" | ||
# The line below is used for testing in local | ||
#docfx init -q -o "${DocOutDir}" | ||
LogDebug "Copying template and configuration..." | ||
New-Item -Path "${DocOutDir}" -Name "templates" -ItemType "directory" -Force | ||
Copy-Item "${DocGenDir}/templates/*" -Destination "${DocOutDir}/templates" -Force -Recurse | ||
Copy-Item "${DocGenDir}/docfx.json" -Destination "${DocOutDir}/" -Force | ||
$YmlPath = "${DocOutDir}/api" | ||
New-Item -Path $YmlPath -Name "toc.yml" -Force | ||
$visitedService = @{} | ||
# Sort and display toc service name by alphabetical order, and then sort artifact by order. | ||
foreach ($serviceMapping in ($tocContent.GetEnumerator() | Sort-Object Value[0], Key)) { | ||
$artifact = $serviceMapping.Key | ||
$serviceName = $serviceMapping.Value[0] | ||
$displayName = $serviceMapping.Value[1] | ||
|
||
$fileName = ($serviceName -replace '\s', '').ToLower().Trim() | ||
if ($visitedService.ContainsKey($serviceName)) { | ||
if ($displayName) { | ||
Add-Content -Path "$($YmlPath)/${fileName}.md" -Value "#### $artifact`n##### ($displayName)" | ||
} | ||
else { | ||
Add-Content -Path "$($YmlPath)/${fileName}.md" -Value "#### $artifact" | ||
} | ||
} | ||
else { | ||
Add-Content -Path "$($YmlPath)/toc.yml" -Value "- name: ${serviceName}`r`n href: ${fileName}.md" | ||
New-Item -Path $YmlPath -Name "${fileName}.md" -Force | ||
if ($displayName) { | ||
Add-Content -Path "$($YmlPath)/${fileName}.md" -Value "#### $artifact`n##### ($displayName)" | ||
} | ||
else { | ||
Add-Content -Path "$($YmlPath)/${fileName}.md" -Value "#### $artifact" | ||
} | ||
$visitedService[$serviceName] = $true | ||
} | ||
} | ||
|
||
# Generate toc homepage. | ||
LogDebug "Creating Site Title and Navigation..." | ||
New-Item -Path "${DocOutDir}" -Name "toc.yml" -Force | ||
Add-Content -Path "${DocOutDir}/toc.yml" -Value "- name: Azure SDK for $lang APIs`r`n href: api/`r`n homepage: api/index.md" | ||
|
||
LogDebug "Copying root markdowns" | ||
Copy-Item "$($RepoRoot)/README.md" -Destination "${DocOutDir}/api/index.md" -Force | ||
Copy-Item "$($RepoRoot)/CONTRIBUTING.md" -Destination "${DocOutDir}/api/CONTRIBUTING.md" -Force | ||
|
||
LogDebug "Building site..." | ||
& $($DocFx) build "${DocOutDir}/docfx.json" | ||
# The line below is used for testing in local | ||
#docfx build "${DocOutDir}/docfx.json" | ||
Copy-Item "${DocGenDir}/assets/logo.svg" -Destination "${DocOutDir}/_site/" -Force | ||
} | ||
|
||
function Mutate-Files { | ||
Param ( | ||
[Parameter(Mandatory=$true)] [String]$appTitle, | ||
[Parameter(Mandatory=$true)] [String]$lang, | ||
[Parameter(Mandatory=$true)] [String]$indexhtmlloc, | ||
[Parameter(Mandatory=$false)] [String]$packageRegex = "`"`"", | ||
[Parameter(Mandatory=$false)] [String]$regexReplacement = "" | ||
) | ||
# Update docfx.json | ||
$docfxContent = Get-Content -Path $DocfxJsonPath -Raw | ||
$docfxContent = $docfxContent -replace "`"_appTitle`": `"`"", "`"_appTitle`": `"$appTitle`"" | ||
$docfxContent = $docfxContent -replace "`"_appFooter`": `"`"", "`"_appFooter`": `"$appTitle`"" | ||
Set-Content -Path $DocfxJsonPath -Value $docfxContent | ||
# Update main.js var lang | ||
$mainJsContent = Get-Content -Path $MainJsPath -Raw | ||
$mainJsContent = $mainJsContent -replace "var SELECTED_LANGUAGE = ''", "var SELECTED_LANGUAGE = '$lang'" | ||
# Update main.js var index html | ||
$mainJsContent = $mainJsContent -replace "var INDEX_HTML = ''", "var INDEX_HTML = '$indexhtmlloc'" | ||
# Update main.js package regex and replacement | ||
$mainJsContent = $mainJsContent -replace "var PACKAGE_REGEX = ''", "var PACKAGE_REGEX = $packageRegex" | ||
$mainJsContent = $mainJsContent -replace "var PACKAGE_REPLACEMENT = ''", "var PACKAGE_REPLACEMENT = `"$regexReplacement`"" | ||
Set-Content -Path $MainJsPath -Value $mainJsContent -NoNewline | ||
} | ||
|
||
if ($GetGithubIoDocIndexFn -and (Test-Path "function:$GetGithubIoDocIndexFn")) | ||
{ | ||
&$GetGithubIoDocIndexFn | ||
} | ||
else | ||
{ | ||
LogWarning "The function '$GetGithubIoDocIndexFn' was not found." | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"metadata": [ | ||
{ | ||
"src": [ | ||
{ | ||
"files": [ | ||
"src/**.csproj" | ||
] | ||
} | ||
], | ||
"dest": "api", | ||
"disableGitFeatures": false, | ||
"disableDefaultFilter": false | ||
} | ||
], | ||
"build": { | ||
"content": [ | ||
{ | ||
"files": [ | ||
"api/**.yml", | ||
"api/**.md", | ||
"api/index.md" | ||
] | ||
}, | ||
{ | ||
"files": [ | ||
"toc.yml", | ||
"*.md" | ||
] | ||
} | ||
], | ||
"resource": [ | ||
{ | ||
"files": [ | ||
"images/**" | ||
] | ||
} | ||
], | ||
"overwrite": [ | ||
{ | ||
"files": [ | ||
"apidoc/**.md" | ||
], | ||
"exclude": [ | ||
"obj/**", | ||
"_site/**" | ||
] | ||
} | ||
], | ||
"dest": "_site", | ||
"globalMetadataFiles": [], | ||
"fileMetadataFiles": [], | ||
"template": [ | ||
"default", | ||
"templates/matthews" | ||
], | ||
"postProcessors": [], | ||
"markdownEngineName": "markdig", | ||
"noLangKeyword": false, | ||
"keepFileLink": false, | ||
"cleanupCacheHistory": false, | ||
"disableGitFeatures": false, | ||
"globalMetadata": { | ||
"_appTitle": "", | ||
"_appFooter": "", | ||
"_enableSearch": false, | ||
"_enableNewTab": true, | ||
"_appFaviconPath": "https://c.s-microsoft.com/favicon.ico?v2", | ||
"_disableContribution": true | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
17 changes: 17 additions & 0 deletions
17
eng/common/docgeneration/templates/matthews/partials/affix.tmpl.partial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{^_disableContribution}} | ||
<div class="contribution-panel mobile-hide"> | ||
{{#docurl}} | ||
<a href="{{docurl}}" title="{{__global.improveThisDoc}}" class="fab btn-warning pull-right"><i class="glyphicon glyphicon-pencil"></i></a> | ||
{{/docurl}} | ||
{{#sourceurl}} | ||
<a href="{{sourceurl}}" title="{{__global.viewSource}}" class="fab btn-info pull-right"><i class="fa fa-code"></i></a> | ||
{{/sourceurl}} | ||
</div> | ||
{{/_disableContribution}} | ||
|
||
<div class="hidden-sm col-md-2" role="complementary"> | ||
<div class="sideaffix"> | ||
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix"> | ||
</nav> | ||
</div> | ||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
$packageRegex
have quotes around it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS actually read regex as only surrounded
/.../
without quotesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in JS, will test the rest repo as well