Skip to content

Commit 9014b0d

Browse files
committed
First Attempt to add PowerShell Docs
1 parent f8cb33e commit 9014b0d

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

docs/file-scrapers.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,56 @@ mv three.js-r${VERSION}/docs/* docs/threejs~${VERSION}/
321321
rm -rf three.js-r${VERSION}/
322322
rm threejs.tar.gz
323323
```
324+
325+
## PowerShell
326+
327+
```sh
328+
curl -o PowerShell-Docs-main.zip 'https://github.com/MicrosoftDocs/PowerShell-Docs/archive/refs/heads/main.zip'
329+
unzip PowerShell-Docs-main.zip
330+
cd PowerShell-Docs-main
331+
332+
## Has missing documentation, claims it can't find files from toc.yml (get-help.md etc.)
333+
# pacman -S dotnet-host aspnet-runtime
334+
# yay -S dotnet-runtime-8.0-bin # for DocFxTocGenerator
335+
# dotnet --list-runtimes
336+
# dotnet tool update -g docfx
337+
# dotnet tool install DocFxTocGenerator -g
338+
# cd PowerShell-Docs-main/reference
339+
# DocFxTocGenerator -d reference -sr --indexing NoDefault
340+
# docfx reference/docfx.json -o ../docs/powershell
341+
342+
343+
# strip all front matter in all Markdown files
344+
find reference -name "*.md" -type f -exec sed -i '/^---$/,/^---$/d' {} +
345+
## create a simpified template
346+
# cat > reference/template.html << 'EOF'
347+
# <!doctype html>
348+
# <html>
349+
# <head>
350+
# <meta name="viewport" content="width=device-width, initial-scale=1.0" />
351+
# <meta charset="utf-8" />
352+
# </head>
353+
354+
# <body>
355+
# <nav id="menu">
356+
# <!--NAV-->
357+
# </nav>
358+
# <div id="layout">
359+
# <article id="main" class="content">
360+
# <!--CONTENT-->
361+
# </article>
362+
# </div>
363+
# </body>
364+
# </html>
365+
# EOF
366+
367+
npx markdown-folder-to-html reference
368+
cp -r _reference ../docs/powershell
369+
cd ..
370+
371+
# process whent on indefinatly
372+
bundle exec thor docs:generate powershell --debug
373+
374+
rm -rdf PowerShell-Docs-main/
375+
rm PowerShell-Docs-main.zip
376+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Docs
2+
class Powershell
3+
class CleanHtmlFilter < Filter
4+
def call
5+
# web
6+
css('header').remove
7+
css('#ms--content-header').remove
8+
css('#article-header').remove
9+
css('.left-container').remove
10+
css('.layout-body-aside').remove
11+
css('#site-user-feedback-footer').remove
12+
css('footer').remove
13+
# docfx
14+
css('.sideaffix').remove
15+
# markdown-folder-to-html
16+
css('#menuLink').remove
17+
css('#menu').remove
18+
css('script').remove
19+
css('style').remove
20+
doc
21+
end
22+
end
23+
end
24+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Docs
2+
class Powershell
3+
class EntriesFilter < Docs::EntriesFilter
4+
def get_name
5+
at_css('h1')&.content || "PowerShell"
6+
end
7+
8+
def get_type
9+
case slug
10+
when /^docs-conceptual/
11+
'Scripting'
12+
when /^5\.1/
13+
'5.1'
14+
when /^7\.4/
15+
'7.4'
16+
when /^7\.5/
17+
'7.5'
18+
when /^7\.6/
19+
'7.6'
20+
else
21+
'Module'
22+
end
23+
end
24+
end
25+
end
26+
end

lib/docs/scrapers/powershell.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Docs
2+
class Powershell < FileScraper
3+
# class Powershell < UrlScraper
4+
self.name = 'PowerShell'
5+
self.type = 'simple'
6+
self.release = '7.5'
7+
self.base_url = 'https://learn.microsoft.com/en-us/powershell'
8+
# self.root_path = 'scripting/overview.html'
9+
self.root_path = 'docs-conceptual/overview.html'
10+
self.initial_paths = [
11+
# 'scripting/toc.html',
12+
'module/index.html',
13+
# 'module/Microsoft.WSMan.Management/About/about_WS-Management_Cmdlets.html',
14+
# 'module/PSWorkflow/About/about_ActivityCommonParameters.html',
15+
# 'module/Microsoft.PowerShell.Core/About/About.html',
16+
# 'module/PSReadLine/About/about_PSReadLine.html',
17+
# 'module/Microsoft.PowerShell.Security/About/about_Certificate_Provider.html',
18+
# 'module/PSScheduledJob/About/about_Scheduled_Jobs.html'
19+
]
20+
self.links = {
21+
home: 'https://learn.microsoft.com/powershell',
22+
code: 'https://github.com/MicrosoftDocs/PowerShell-Docs'
23+
}
24+
html_filters.push 'powershell/clean_html', 'powershell/entries'
25+
26+
# options[:rate_limit] = 100 # micososft docs online are ratelimited
27+
options[:skip_patterns] = [/\/\//] # otherwise infinately adding the same pages
28+
options[:attribution] = <<-HTML
29+
The MIT License (MIT) Copyright (c) Microsoft Corporation
30+
HTML
31+
end
32+
end

0 commit comments

Comments
 (0)