Skip to content

Commit 4b9256a

Browse files
committed
Merge pull request freeCodeCamp#170 from TrangPham/master
Adding Official Url for url scrapped documentations
2 parents 05e18b2 + ab85da3 commit 4b9256a

6 files changed

Lines changed: 57 additions & 3 deletions

File tree

‎assets/stylesheets/components/_page.scss‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@
2222
}
2323
}
2424

25+
//
26+
// Official Website box
27+
//
28+
29+
._official {
30+
clear: both;
31+
margin: 2rem 0 1.5rem;
32+
font-size: .75rem;
33+
color: $textColorLight;
34+
text-align: center;
35+
-webkit-font-smoothing: subpixel-antialiased;
36+
37+
& + & { margin-top: 1.5rem; }
38+
}
39+
40+
._official-link { @extend %external-link; }
41+
2542
//
2643
// Attribution box
2744
//

‎lib/docs/core/doc.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Doc
44
DB_FILENAME = 'db.json'
55

66
class << self
7-
attr_accessor :name, :slug, :type, :version, :abstract
7+
attr_accessor :name, :slug, :type, :version, :abstract, :home_url
88

99
def inherited(subclass)
1010
subclass.type = type

‎lib/docs/core/filter.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def base_url
2020
context[:base_url]
2121
end
2222

23+
def home_url
24+
context[:home_url]
25+
end
26+
2327
def current_url
2428
context[:url]
2529
end

‎lib/docs/core/scraper.rb‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def filters
3434
self.text_filters = FilterStack.new
3535

3636
html_filters.push 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths'
37-
text_filters.push 'inner_html', 'clean_text', 'attribution'
37+
text_filters.push 'inner_html', 'clean_text', 'home_url', 'attribution'
3838

3939
def build_page(path)
4040
response = request_one url_for(path)
@@ -65,6 +65,10 @@ def root_url
6565
@root_url ||= root_path? ? URL.parse(File.join(base_url.to_s, root_path)) : base_url.normalize
6666
end
6767

68+
def home_url
69+
@home_url ||= self.class.home_url
70+
end
71+
6872
def root_path
6973
self.class.root_path
7074
end
@@ -89,7 +93,7 @@ def pipeline
8993

9094
def options
9195
@options ||= self.class.options.deep_dup.tap do |options|
92-
options.merge! base_url: base_url, root_url: root_url,
96+
options.merge! base_url: base_url, root_url: root_url, home_url: home_url,
9397
root_path: root_path, initial_paths: initial_paths
9498

9599
if root_path?

‎lib/docs/filters/core/home_url.rb‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Docs
2+
class HomeUrlFilter < Filter
3+
def call
4+
html.prepend(home_url_html) if home_url
5+
html
6+
end
7+
8+
def home_url_html
9+
<<-HTML.strip_heredoc
10+
<div class="_official">
11+
Official Documentation: <a href="#{home_url}" class="_official-link">#{home_url}</a>
12+
</div>
13+
HTML
14+
end
15+
end
16+
end

‎test/lib/docs/core/doc_test.rb‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ class DocsDocTest < MiniTest::Spec
6060
end
6161
end
6262

63+
describe ".home_url" do
64+
it "returns nil" do
65+
assert_nil doc.home_url
66+
end
67+
end
68+
69+
describe ".home_url=" do
70+
it "stores .home_url" do
71+
doc.home_url = 'http://www.url.com/doc'
72+
assert_equal 'http://www.url.com/doc', doc.home_url
73+
end
74+
end
75+
6376
describe ".abstract" do
6477
it "returns nil" do
6578
assert_nil doc.abstract

0 commit comments

Comments
 (0)