Skip to content

Commit def0778

Browse files
authored
Merge pull request #2641 from publicarray/main
Add PowerShell docs
2 parents 87b48be + 2618273 commit def0778

10 files changed

Lines changed: 152 additions & 0 deletions

File tree

assets/javascripts/news.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[
2+
[
3+
"2026-06-02",
4+
"New documentation: <a href=\"/powershell/\">PowerShell</a>"
5+
],
26
[
37
"2026-05-26",
48
"New documentations: <a href=\"/opentofu/\">OpenTofu</a>, <a href=\"/cyclejs/\">Cycle.js</a>, <a href=\"/polars/\">Polars</a>"

docs/file-scrapers.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,9 @@ mv three.js-r${VERSION}/docs/* docs/threejs~${VERSION}/
320320
rm -rf three.js-r${VERSION}/
321321
rm threejs.tar.gz
322322
```
323+
324+
## PowerShell
325+
326+
```sh
327+
curl -L 'https://github.com/MicrosoftDocs/PowerShell-Docs/archive/refs/heads/main.zip' | bsdtar --extract --file - --directory=docs/powershell/ --strip-components=2
328+
```

lib/docs/filters/core/normalize_paths.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def normalize_path(path)
5151
"#{path}index"
5252
elsif path.end_with? '.html'
5353
path[0..-6]
54+
elsif path.end_with? '.md'
55+
path[0..-4]
5456
else
5557
path
5658
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module Docs
4+
class Powershell
5+
class AttributionFilter < Docs::AttributionFilter
6+
def attribution_link
7+
url = current_url.to_s.downcase
8+
base = self.version == 'Scripting' ? 'scripting' : 'module'
9+
url.sub! 'http://localhost/', "https://learn.microsoft.com/en-us/powershell/#{base}/"
10+
url.remove! %r{\.md$}
11+
url << "?view=powershell-" + self.version
12+
%(<a href="#{url}" class="_attribution-link">#{url}</a>)
13+
end
14+
end
15+
end
16+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
# markdown-folder-to-html
14+
css('#menuLink').remove
15+
css('#menu').remove
16+
css('script').remove
17+
css('style').remove
18+
css('.heading-anchor-permalink').remove
19+
doc
20+
end
21+
end
22+
end
23+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Docs
2+
class Powershell
3+
class EntriesFilter < Docs::EntriesFilter
4+
def get_name
5+
at_css('h1').content.strip
6+
end
7+
8+
def get_type
9+
parts = slug.split('/')
10+
parts.length > 1 ? parts.first : 'Overview'
11+
end
12+
end
13+
end
14+
end

lib/docs/scrapers/powershell.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
module Docs
2+
class Powershell < FileScraper
3+
self.name = 'PowerShell'
4+
self.type = 'simple'
5+
self.root_path = 'Microsoft.PowerShell.Core/Get-Help.html'
6+
self.links = {
7+
home: 'https://learn.microsoft.com/powershell',
8+
code: 'https://github.com/MicrosoftDocs/PowerShell-Docs'
9+
}
10+
html_filters.push 'powershell/clean_html', 'powershell/entries'
11+
text_filters.replace 'attribution', 'powershell/attribution'
12+
13+
# https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/LICENSE-CODE.md
14+
# https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/LICENSE.md
15+
options[:attribution] = <<-HTML
16+
&copy; Microsoft Corporation
17+
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
18+
HTML
19+
20+
version '7.7' do
21+
self.release = '7.7'
22+
end
23+
24+
version '7.6' do
25+
self.release = '7.6'
26+
end
27+
28+
version '7.5' do
29+
self.release = '7.5'
30+
end
31+
32+
version '7.4' do
33+
self.release = '7.4'
34+
end
35+
36+
version '5.1' do
37+
self.release = '5.1'
38+
end
39+
40+
version 'Scripting' do
41+
self.root_path = 'discover-powershell.html'
42+
43+
def source_directory
44+
@source_directory ||= File.join(Docs::FileScraper::SOURCE_DIRECTORY, 'powershell', 'docs-conceptual')
45+
end
46+
end
47+
48+
def source_directory
49+
@source_directory ||= File.join(Docs::FileScraper::SOURCE_DIRECTORY, 'powershell', self.class.version)
50+
end
51+
52+
def get_latest_version(opts)
53+
# Stable PowerShell releases are tagged like "v7.5.2"; the docs are
54+
# versioned by major.minor (e.g. "7.5"), so drop the patch component.
55+
get_latest_github_release('PowerShell', 'PowerShell', opts).split('.')[0..1].join('.')
56+
end
57+
58+
# No index page, enumerate all HTML files
59+
def request_all(urls)
60+
assert_source_directory_exists
61+
Dir.glob(File.join(source_directory, '**', '*.md')).sort.each do |path|
62+
url = File.join(base_url.to_s, path.sub("#{source_directory}/", ''))
63+
yield request_one(url)
64+
end
65+
end
66+
67+
private
68+
69+
def parse(response)
70+
body = response.body.sub(/\A---\s*\n.*?\n---\s*\n/m, '')
71+
html = markdown_renderer.render(body)
72+
[Parser.new("<html></head><body>#{html}</body></html>").html, ""]
73+
end
74+
75+
def markdown_renderer
76+
require 'redcarpet'
77+
@markdown_renderer ||= Redcarpet::Markdown.new(
78+
Redcarpet::Render::HTML.new(with_toc_data: true),
79+
autolink: true,
80+
fenced_code_blocks: true,
81+
no_intra_emphasis: true,
82+
tables: true
83+
)
84+
end
85+
end
86+
end
1.55 KB
Loading
2.99 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://learn.microsoft.com/en-us/powershell/media/index/ps_black_128.svg

0 commit comments

Comments
 (0)