| @@ -2,26 +2,38 @@ module Docs · 1 unmodified line |
| 2 | class Tailwindcss | 2 | class Tailwindcss |
| 3 | class CleanHtmlFilter < Filter | 3 | class CleanHtmlFilter < Filter |
| 4 | def call | 4 | def call |
| | 5 | # Move h1 out of wrapper. |
| | 6 | css('h1').each do |node| |
| | 7 | doc.prepend_child(node) |
| | 8 | end |
| | 9 | |
| 5 | # Remove main page headers (top level sticky) | 10 | # Remove main page headers (top level sticky) |
| 6 | css('#__next > .sticky').remove | 11 | css('#__next > .sticky', 'div.fixed.inset-x-0.top-0').remove |
| 7 | # And anything absolutely positioned (fancy floating navigation elements we don't care about) | 12 | # And anything absolutely positioned (fancy floating navigation elements we don't care about) |
| 8 | css('#__next .absolute').remove | 13 | css('#__next .absolute', '.fixed').remove |
| 9 | # Remove the left-navigation we scraped | 14 | # Remove the left-navigation we scraped |
| 10 | css('nav').remove | 15 | css('nav').remove |
| 11 | | 16 | |
| 12 | css('svg').remove if root_page? | 17 | css('svg').remove if root_page? |
| 13 | | 18 | |
| 14 | # Remove the duplicate category name at the top of the page - redundant | | |
| 15 | at_css('header#header > div:first-child > p:first-child').remove | | |
| 16 | | | |
| 17 | # Remove the right navigation sidebar | 19 | # Remove the right navigation sidebar |
| 18 | at_css('header#header').parent.css('> div:has(h5:contains("On this page"))').remove | 20 | css('header#header', 'p[data-section]').each do |node| |
| | 21 | node.parent.css('> div:has(h5:contains("On this page"))').remove # v3 |
| | 22 | |
| | 23 | node.parent.parent.css('div.max-xl\\:hidden').remove # v4 |
| | 24 | end |
| | 25 | |
| | 26 | # Remove the duplicate category name at the top of the page - redundant |
| | 27 | css( |
| | 28 | 'header#header > div:first-child > p:first-child', # v3 |
| | 29 | 'p[data-section]' # v4 |
| | 30 | ).remove |
| 19 | | 31 | |
| 20 | # Remove footer + prev/next navigation | 32 | # Remove footer + prev/next navigation |
| 21 | at_css('footer').remove | 33 | css('footer', '.row-start-5').remove |
| 22 | | 34 | |
| 23 | # Handle long lists of class reference that otherwise span several scrolled pages | 35 | # Handle long lists of class reference that otherwise span several scrolled pages |
| 24 | if class_reference = at_css('#class-reference') | 36 | if class_reference = at_css('#class-reference', '#quick-reference') |
| 25 | reference_container = class_reference.parent | 37 | reference_container = class_reference.parent |
| 26 | classes_container = reference_container.children.reject{ |child| child == class_reference }.first | 38 | classes_container = reference_container.children.reject{ |child| child == class_reference }.first |
| 27 | | 39 | |
| @@ -33,7 +45,7 @@ module Docs · 5 unmodified lines |
| 33 | end | 45 | end |
| 34 | | 46 | |
| 35 | # Remove border color preview column as it isn't displayed anyway | 47 | # Remove border color preview column as it isn't displayed anyway |
| 36 | if result[:path] == "border-color" and class_reference = at_css('#class-reference') | 48 | if result[:path] == "border-color" and class_reference = at_css('#class-reference', '#quick-reference') |
| 37 | class_reference.parent.css("thead th:nth-child(3)").remove | 49 | class_reference.parent.css("thead th:nth-child(3)").remove |
| 38 | class_reference.parent.css("tbody td:nth-child(3)").remove | 50 | class_reference.parent.css("tbody td:nth-child(3)").remove |
| 39 | end | 51 | end |
| @@ -59,29 +71,48 @@ module Docs · 19 unmodified lines |
| 59 | end | 71 | end |
| 60 | | 72 | |
| 61 | # Remove buttons to expand lists - those are already expanded and the button is useless | 73 | # Remove buttons to expand lists - those are already expanded and the button is useless |
| 62 | css('div > button:contains("Show all classes")').each do |node| | 74 | css( |
| | 75 | 'div > button:contains("Show all classes")', |
| | 76 | 'div > button:contains("Show more")' |
| | 77 | ).each do |node| |
| 63 | node.parent.remove | 78 | node.parent.remove |
| 64 | end | 79 | end |
| 65 | | 80 | |
| 66 | # Remove class examples - not part of devdocs styleguide? (similar to bootstrap) | 81 | # Remove class examples - not part of devdocs styleguide? (similar to bootstrap) |
| 67 | # Refer to https://github.com/freeCodeCamp/devdocs/pull/1534#pullrequestreview-649818936 | 82 | # Refer to https://github.com/freeCodeCamp/devdocs/pull/1534#pullrequestreview-649818936 |
| 68 | css('.not-prose').each do |node| | 83 | css('.mt-4.-mb-3', 'figure', 'svg', '.flex.space-x-2').remove |
| 69 | if node.parent.children.length == 1 | | |
| 70 | node.parent.remove | | |
| 71 | else | | |
| 72 | node.remove | | |
| 73 | end | | |
| 74 | end | | |
| 75 | | 84 | |
| 76 | # Properly format code examples | 85 | # Properly format code examples. |
| 77 | css('pre > code:first-child').each do |node| | 86 | css('pre > code:first-child').each do |node| |
| 78 | node.parent['data-language'] = node['class'][/language-(\w+)/, 1] if node['class'] and node['class'][/language-(\w+)/] | 87 | # v4 doesn't provide language context, so it must be inferred imperfectly. |
| 79 | node.parent.content = node.parent.content | 88 | node.parent['data-language'] = |
| | 89 | if node.content.include?('function') |
| | 90 | 'jsx' |
| | 91 | elsif node.content.include?("</") |
| | 92 | 'html' |
| | 93 | else |
| | 94 | 'css' |
| | 95 | end |
| | 96 | |
| | 97 | node.parent.content = |
| | 98 | if version == '3' |
| | 99 | node.parent.content |
| | 100 | else |
| | 101 | node.css('.line').map(&:content).join("\n") |
| | 102 | end |
| | 103 | end |
| | 104 | |
| | 105 | # Remove headers some code examples have. |
| | 106 | css('.flex.text-slate-400.text-xs.leading-6', '.px-3.pt-0\\.5.pb-1\\.5').remove |
| | 107 | |
| | 108 | # Strip anchor from headers |
| | 109 | css('h2', 'h3').each do |node| |
| | 110 | node.content = node.inner_text |
| 80 | end | 111 | end |
| 81 | | 112 | |
| 82 | @doc.traverse { |node| cleanup_tailwind_classes(node) } | 113 | @doc.traverse { |node| cleanup_tailwind_classes(node) } |
| 83 | | 114 | |
| 84 | #remove weird <hr> (https://github.com/damms005/devdocs/commit/8c9fbd859b71a2525b94a35ea994393ce2b6fedb#commitcomment-50091018) | 115 | # Remove weird <hr> (https://github.com/damms005/devdocs/commit/8c9fbd859b71a2525b94a35ea994393ce2b6fedb#commitcomment-50091018) |
| 85 | css('hr').remove | 116 | css('hr').remove |
| 86 | | 117 | |
| 87 | doc | 118 | doc |