History

wordpress: finish scraper and filters

Jasper van Merle committed 7 years ago

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

Showing the changes to lib/docs (3 of 6 files). Show all

Unified · Split

3 files
  1. lib/docs/filters/wordpress/clean_html.rb +8 −1
  2. lib/docs/filters/wordpress/entries.rb +1 −11
  3. lib/docs/scrapers/wordpress.rb +5 −5
lib/docs/filters/wordpress/clean_html.rb+8−1
@@ -7,12 +7,19 @@ module Docs · 6 unmodified lines
77 return doc
88 end
99
10+ article = at_css('article[id^="post-"]')
11+ @doc = at_css('article[id^="post-"]') unless article.nil?
12+
1013 css('hr', '.screen-reader-text', '.table-of-contents',
1114 '.anchor', '.toc-jump', '.source-code-links', '.user-notes',
1215 '.show-more', '.hide-more').remove
1316
1417 br = /<br\s?\/?>/i
1518
19+ header = at_css('h1')
20+ header.content = header.content.strip
21+ doc.prepend_child header
22+
1623 # Add PHP code highlighting
1724 css('pre').each do |node|
1825 node['data-language'] = 'php'
@@ -29,4 +36,4 @@ module Docs · 10 unmodified lines
2936 end
3037 end
3138 end
32−end
39+end
lib/docs/filters/wordpress/entries.rb+1−11
@@ -1,12 +1,6 @@
11 module Docs
22 class Wordpress
33 class EntriesFilter < Docs::EntriesFilter
4− def breadcrumbs
5− @breadcrumbs ||= css('.breadcrumbs .trail-inner a')
6− .map(&:content)
7− .map(&:strip)
8− end
9−
104 def get_name
115 at_css('.breadcrumbs .trail-end').content
126 end
@@ -18,12 +12,8 @@ module Docs · 5 unmodified lines
1812 'Hooks'
1913 elsif subpath.starts_with?('functions')
2014 'Functions'
21− elsif breadcrumbs.size > 1
22− breadcrumbs.drop(1).join(': ')
23− else
24− at_css('.breadcrumbs .trail-end').content
2515 end
2616 end
2717 end
2818 end
29−end
19+end
lib/docs/scrapers/wordpress.rb+5−5
@@ -2,7 +2,7 @@ module Docs · 1 unmodified line
22 class Wordpress < UrlScraper
33 self.name = 'WordPress'
44 self.type = 'wordpress'
5− self.release = '4.9.4'
5+ self.release = '5.2.2'
66 self.base_url = 'https://developer.wordpress.org/reference/'
77 self.initial_paths = %w(
88 functions/
@@ -15,10 +15,10 @@ module Docs · 6 unmodified lines
1515 code: 'https://github.com/WordPress/WordPress'
1616 }
1717
18− html_filters.push 'wordpress/clean_html', 'wordpress/entries'
18+ html_filters.push 'wordpress/entries', 'wordpress/clean_html'
1919
2020 options[:container] = '#content-area'
21− options[:trailing_slash] = true
21+ options[:trailing_slash] = false
2222 options[:only_patterns] = [
2323 /\Afunctions\//,
2424 /\Ahooks\//,
@@ -32,8 +32,8 @@ module Docs · 7 unmodified lines
3232 ]
3333
3434 options[:attribution] = <<-HTML
35− &copy; 2003&ndash;2018 WordPress Foundation<br>
35+ &copy; 2003&ndash;2019 WordPress Foundation<br>
3636 Licensed under the GNU GPLv2+ License.
3737 HTML
3838 end
39−end
39+end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t