History

wordpress: finish scraper and filters

Jasper van Merle committed 7 years ago

Commit 78168361 parent a7a38646 files · +18 −15Browse files

Unified · Split

6 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +6 −0
  2. lib/docs/filters/wordpress/clean_html.rb +8 −1
  3. lib/docs/filters/wordpress/entries.rb +1 −11
  4. lib/docs/scrapers/wordpress.rb +5 −5
  5. public/icons/docs/wordpress/16.png +0 −0
  6. public/icons/docs/wordpress/16@2x.png +0 −0
assets/javascripts/templates/pages/about_tmpl.coffee+6−0
@@ -728,6 +728,12 @@ credits = [ · 727 unmodified lines
728 'CC BY',728 'CC BY',
729 'https://creativecommons.org/licenses/by/4.0/'729 'https://creativecommons.org/licenses/by/4.0/'
730 ], [730 ], [
731 'Wordpress',
732 '2003-2019 WordPress Foundation',
733 'GPLv2+',
734 'https://wordpress.org/about/license/'
735 ],
736 [
731 'Yarn',737 'Yarn',
732 '2016-present Yarn Contributors',738 '2016-present Yarn Contributors',
733 'BSD',739 'BSD',
lib/docs/filters/wordpress/clean_html.rb+8−1
@@ -7,12 +7,19 @@ module Docs · 6 unmodified lines
7 return doc7 return doc
8 end8 end
9 9
10 article = at_css('article[id^="post-"]')
11 @doc = at_css('article[id^="post-"]') unless article.nil?
12
10 css('hr', '.screen-reader-text', '.table-of-contents',13 css('hr', '.screen-reader-text', '.table-of-contents',
11 '.anchor', '.toc-jump', '.source-code-links', '.user-notes',14 '.anchor', '.toc-jump', '.source-code-links', '.user-notes',
12 '.show-more', '.hide-more').remove15 '.show-more', '.hide-more').remove
13 16
14 br = /<br\s?\/?>/i17 br = /<br\s?\/?>/i
15 18
19 header = at_css('h1')
20 header.content = header.content.strip
21 doc.prepend_child header
22
16 # Add PHP code highlighting23 # Add PHP code highlighting
17 css('pre').each do |node|24 css('pre').each do |node|
18 node['data-language'] = 'php'25 node['data-language'] = 'php'
@@ -29,4 +36,4 @@ module Docs · 10 unmodified lines
29 end36 end
30 end37 end
31 end38 end
32end39end
lib/docs/filters/wordpress/entries.rb+1−11
@@ -1,12 +1,6 @@
1module Docs1module Docs
2 class Wordpress2 class Wordpress
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 def breadcrumbs
5 @breadcrumbs ||= css('.breadcrumbs .trail-inner a')
6 .map(&:content)
7 .map(&:strip)
8 end
9
10 def get_name4 def get_name
11 at_css('.breadcrumbs .trail-end').content5 at_css('.breadcrumbs .trail-end').content
12 end6 end
@@ -18,12 +12,8 @@ module Docs · 5 unmodified lines
18 'Hooks'12 'Hooks'
19 elsif subpath.starts_with?('functions')13 elsif subpath.starts_with?('functions')
20 'Functions'14 'Functions'
21 elsif breadcrumbs.size > 1
22 breadcrumbs.drop(1).join(': ')
23 else
24 at_css('.breadcrumbs .trail-end').content
25 end15 end
26 end16 end
27 end17 end
28 end18 end
29end19end
lib/docs/scrapers/wordpress.rb+5−5
@@ -2,7 +2,7 @@ module Docs · 1 unmodified line
2 class Wordpress < UrlScraper2 class Wordpress < UrlScraper
3 self.name = 'WordPress'3 self.name = 'WordPress'
4 self.type = 'wordpress'4 self.type = 'wordpress'
5 self.release = '4.9.4'5 self.release = '5.2.2'
6 self.base_url = 'https://developer.wordpress.org/reference/'6 self.base_url = 'https://developer.wordpress.org/reference/'
7 self.initial_paths = %w(7 self.initial_paths = %w(
8 functions/8 functions/
@@ -15,10 +15,10 @@ module Docs · 6 unmodified lines
15 code: 'https://github.com/WordPress/WordPress'15 code: 'https://github.com/WordPress/WordPress'
16 }16 }
17 17
18 html_filters.push 'wordpress/clean_html', 'wordpress/entries'18 html_filters.push 'wordpress/entries', 'wordpress/clean_html'
19 19
20 options[:container] = '#content-area'20 options[:container] = '#content-area'
21 options[:trailing_slash] = true21 options[:trailing_slash] = false
22 options[:only_patterns] = [22 options[:only_patterns] = [
23 /\Afunctions\//,23 /\Afunctions\//,
24 /\Ahooks\//,24 /\Ahooks\//,
@@ -32,8 +32,8 @@ module Docs · 7 unmodified lines
32 ]32 ]
33 33
34 options[:attribution] = <<-HTML34 options[:attribution] = <<-HTML
35 &copy; 2003&ndash;2018 WordPress Foundation<br>35 &copy; 2003&ndash;2019 WordPress Foundation<br>
36 Licensed under the GNU GPLv2+ License.36 Licensed under the GNU GPLv2+ License.
37 HTML37 HTML
38 end38 end
39end39end
public/icons/docs/wordpress/16.png+0−0

Binary file not shown.

public/icons/docs/wordpress/16@2x.png+0−0

Binary file not shown.