Skip to content

Commit 5e9823a

Browse files
authored
Merge pull request freeCodeCamp#2597 from spamguy/angular-18
Add v18/v19/v20 to Angular docs
2 parents 8b8d5a0 + ba0aa60 commit 5e9823a

File tree

4 files changed

+183
-18
lines changed

4 files changed

+183
-18
lines changed

assets/stylesheets/pages/_angular.scss

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,40 @@
2121
}
2222

2323
td h3 { margin: 0 !important; }
24+
25+
.docs-reference-member-card .docs-reference-card-item {
26+
&:has(~ .docs-reference-card-item),
27+
&:last-child:not(:first-of-type) {
28+
margin: .25rem 0 1.5rem 1.5rem;
29+
padding: .625rem 1rem;
30+
@extend %box;
31+
}
32+
span {
33+
display: inline-block;
34+
}
35+
.docs-param-group {
36+
margin-block-start: 1rem;
37+
&:not(:has(~ .docs-param-group)) {
38+
margin-block: 1rem;
39+
}
40+
.docs-param-name {
41+
@extend %code;
42+
margin-inline-end: 0.25rem;
43+
}
44+
.docs-param-name:after {
45+
content: ":";
46+
}
47+
.docs-parameter-description p:first-child {
48+
margin-block-start: 0;
49+
}
50+
}
51+
.docs-param-keyword {
52+
color: var(--focusText);
53+
@extend %code;
54+
margin-inline-end: 0.5rem;
55+
}
56+
.docs-return-type {
57+
padding-block: 1rem;
58+
}
59+
}
2460
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module Docs
2+
class Angular
3+
class CleanHtmlV18Filter < Filter
4+
def call
5+
@doc = at_css('.docs-viewer') if at_css('.docs-viewer')
6+
7+
# Extract <h1> from decorative header.
8+
@doc.prepend_child(at_css('h1'))
9+
css('h1[class]').remove_attr('class')
10+
11+
css(
12+
'.docs-breadcrumb',
13+
'.docs-github-links',
14+
'docs-table-of-contents',
15+
'.docs-reference-category',
16+
'.docs-reference-title',
17+
'#jump-msg'
18+
).remove
19+
20+
# Strip anchor links from headers.
21+
css('h2', 'h3', 'h4').each do |node|
22+
node.content = node.inner_text
23+
end
24+
25+
# Make every <code> block a <pre>.
26+
css('.docs-code > pre > code').each do |code|
27+
code.name = 'pre'
28+
code['data-language'] = 'ts'
29+
code.content = code.css('.line').map(&:content).join("\n")
30+
code.parent.parent.replace(code)
31+
end
32+
33+
# Better format content in CLI reference.
34+
css('.docs-ref-content').each do |ref|
35+
option = ref.at_css('.docs-reference-option code')
36+
option.name = 'h3'
37+
option.parent.replace(option)
38+
end
39+
40+
css('.docs-reference-type-and-default', '.docs-reference-option-aliases').each do |node|
41+
labels = node.css('span')
42+
values = node.css('code')
43+
labels.each do |l|
44+
l.name = 'h4'
45+
end
46+
end
47+
48+
css('footer').remove
49+
50+
doc
51+
end
52+
end
53+
end
54+
end

lib/docs/filters/angular/entries.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def get_name
1010
def get_type
1111
if slug.start_with?('guide')
1212
'Guide'
13+
elsif slug.start_with?('cli')
14+
'CLI'
1315
elsif slug.start_with?('tutorial')
1416
'Tutorial'
1517
elsif slug.start_with?('api/platform-browser-dynamic')

lib/docs/scrapers/angular.rb

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,30 @@ module Docs
44
class Angular < UrlScraper
55
self.type = 'angular'
66
self.links = {
7-
home: 'https://angular.io/',
7+
home: 'https://angular.dev/',
88
code: 'https://github.com/angular/angular'
99
}
1010
self.base_url = 'https://angular.io/'
1111
self.root_path = 'docs'
1212

13-
html_filters.push 'angular/clean_html', 'angular/entries'
14-
1513
options[:max_image_size] = 256_000
1614

1715
options[:attribution] = <<-HTML
18-
&copy; 2010&ndash;2023 Google, Inc.<br>
19-
Licensed under the Creative Commons Attribution License 4.0.
16+
Super-powered by Google &copy;2010&ndash;2025.<br />
17+
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
2018
HTML
2119

2220
options[:follow_links] = false
23-
options[:only_patterns] = [/\Aguide/, /\Atutorial/, /\Aapi/]
21+
options[:only_patterns] = [/\Aguide/, /\Aapi/, /\Acli/]
2422
options[:fix_urls_before_parse] = ->(url) do
2523
url.sub! %r{\Aguide/}, '/guide/'
26-
url.sub! %r{\Atutorial/}, '/tutorial/'
2724
url.sub! %r{\Aapi/}, '/api/'
25+
url.sub! %r{\cli/}, '/cli/'
2826
url.sub! %r{\Agenerated/}, '/generated/'
2927
url
3028
end
3129

32-
module Common
30+
module JsonNavigation
3331
private
3432

3533
def initial_urls
@@ -79,91 +77,166 @@ def url_for(path)
7977
path = path.gsub(/[A-Z_]/) {|s| s.downcase + '_'}
8078
super
8179
end
82-
include Docs::Angular::Common
80+
include Docs::Angular::JsonNavigation
81+
end
82+
83+
module Since18
84+
def self.handle_redirects(version)
85+
lambda do |url|
86+
url.sub! '/guide/templates/reference-variables', '/guide/templates/variables#template-reference-variables'
87+
url.sub! '/guide/signals/inputs', '/guide/components/inputs'
88+
url.sub! '/guide/defer', '/guide/templates/defer'
89+
url.sub! '/guide/templates/class-binding', '/guide/templates/binding#css-class-and-style-property-bindings'
90+
url.sub! %r{/guide/components$}, '/guide/components/anatomy-of-components'
91+
url.sub! '/guide/templates/property-binding', '/guide/templates/binding#binding-dynamic-properties-and-attributes'
92+
url.sub! %r{/guide/ngmodules$}, '/guide/ngmodules/overview'
93+
url.sub! '/guide/components/importing', '/guide/components/anatomy-of-components#using-components'
94+
95+
url.sub! '/guide/components/anatomy-of-components', '/guide/components' if version == '20'
96+
97+
url
98+
end
99+
end
83100
end
84101

85102
version do
103+
self.release = '20.3.4'
104+
self.base_url = 'https://angular.dev/'
105+
self.root_path = 'overview'
106+
107+
options[:follow_links] = true
108+
options[:container] = '.docs-app-main-content'
109+
options[:fix_urls] = Since18.handle_redirects(self.version)
110+
111+
html_filters.push 'angular/entries', 'angular/clean_html_v18'
112+
113+
include Docs::Angular::Since18
114+
end
115+
116+
version '19' do
117+
self.release = '19.2.15'
118+
self.base_url = 'https://v19.angular.dev/'
119+
self.root_path = 'overview'
120+
121+
options[:follow_links] = true
122+
options[:container] = '.docs-app-main-content'
123+
options[:fix_urls] = Since18.handle_redirects(self.version)
124+
125+
html_filters.push 'angular/entries', 'angular/clean_html_v18'
126+
127+
include Docs::Angular::Since18
128+
end
129+
130+
version '18' do
131+
self.release = '18.2.14'
132+
self.base_url = 'https://v18.angular.dev/'
133+
self.root_path = 'overview'
134+
135+
options[:follow_links] = true
136+
options[:container] = '.docs-app-main-content'
137+
options[:fix_urls] = Since18.handle_redirects(self.version)
138+
139+
html_filters.push 'angular/entries', 'angular/clean_html_v18'
140+
141+
include Docs::Angular::Since18
142+
end
143+
144+
version '17' do
86145
self.release = '17.0.8'
87-
self.base_url = 'https://angular.io/'
146+
self.base_url = 'https://v17.angular.io/'
147+
html_filters.push 'angular/clean_html', 'angular/entries'
88148
include Docs::Angular::Since12
89149
end
90150

91151
version '16' do
92152
self.release = '16.2.12'
93153
self.base_url = 'https://v16.angular.io/'
154+
html_filters.push 'angular/clean_html', 'angular/entries'
94155
include Docs::Angular::Since12
95156
end
96157

97158
version '15' do
98159
self.release = '15.2.9'
99160
self.base_url = 'https://v15.angular.io/'
161+
html_filters.push 'angular/clean_html', 'angular/entries'
100162
include Docs::Angular::Since12
101163
end
102164

103165
version '14' do
104166
self.release = '14.2.12'
105167
self.base_url = 'https://v14.angular.io/'
168+
html_filters.push 'angular/clean_html', 'angular/entries'
106169
include Docs::Angular::Since12
107170
end
108171

109172
version '13' do
110173
self.release = '13.3.8'
111174
self.base_url = 'https://v13.angular.io/'
175+
html_filters.push 'angular/clean_html', 'angular/entries'
112176
include Docs::Angular::Since12
113177
end
114178

115179
version '12' do
116180
self.release = '12.2.13'
117181
self.base_url = 'https://v12.angular.io/'
182+
html_filters.push 'angular/clean_html', 'angular/entries'
118183
include Docs::Angular::Since12
119184
end
120185

121186
version '11' do
122187
self.release = '11.2.14'
123188
self.base_url = 'https://v11.angular.io/'
124-
include Docs::Angular::Common
189+
html_filters.push 'angular/clean_html', 'angular/entries'
190+
include Docs::Angular::JsonNavigation
125191
end
126192

127193
version '10' do
128194
self.release = '10.2.3'
129195
self.base_url = 'https://v10.angular.io/'
130-
include Docs::Angular::Common
196+
html_filters.push 'angular/clean_html', 'angular/entries'
197+
include Docs::Angular::JsonNavigation
131198
end
132199

133200
version '9' do
134201
self.release = '9.1.12'
135202
self.base_url = 'https://v9.angular.io/'
136-
include Docs::Angular::Common
203+
html_filters.push 'angular/clean_html', 'angular/entries'
204+
include Docs::Angular::JsonNavigation
137205
end
138206

139207
version '8' do
140208
self.release = '8.2.14'
141209
self.base_url = 'https://v8.angular.io/'
142-
include Docs::Angular::Common
210+
html_filters.push 'angular/clean_html', 'angular/entries'
211+
include Docs::Angular::JsonNavigation
143212
end
144213

145214
version '7' do
146215
self.release = '7.2.15'
147216
self.base_url = 'https://v7.angular.io/'
148-
include Docs::Angular::Common
217+
html_filters.push 'angular/clean_html', 'angular/entries'
218+
include Docs::Angular::JsonNavigation
149219
end
150220

151221
version '6' do
152222
self.release = '6.1.10'
153223
self.base_url = 'https://v6.angular.io/'
154-
include Docs::Angular::Common
224+
html_filters.push 'angular/clean_html', 'angular/entries'
225+
include Docs::Angular::JsonNavigation
155226
end
156227

157228
version '5' do
158229
self.release = '5.2.11'
159230
self.base_url = 'https://v5.angular.io/'
160-
include Docs::Angular::Common
231+
html_filters.push 'angular/clean_html', 'angular/entries'
232+
include Docs::Angular::JsonNavigation
161233
end
162234

163235
version '4' do
164236
self.release = '4.4.6'
165237
self.base_url = 'https://v4.angular.io/'
166-
include Docs::Angular::Common
238+
html_filters.push 'angular/clean_html', 'angular/entries'
239+
include Docs::Angular::JsonNavigation
167240
end
168241

169242
version '2' do

0 commit comments

Comments
 (0)