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