Skip to content

Commit 8b3f552

Browse files
authored
Merge pull request #2533 from spamguy/tailwind-41
Tailwind CSS v4
2 parents 06ce9ee + c05928e commit 8b3f552

File tree

3 files changed

+114
-51
lines changed

3 files changed

+114
-51
lines changed

lib/docs/filters/tailwindcss/clean_html.rb

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,38 @@ module Docs
22
class Tailwindcss
33
class CleanHtmlFilter < Filter
44
def call
5+
# Move h1 out of wrapper.
6+
css('h1').each do |node|
7+
doc.prepend_child(node)
8+
end
9+
510
# Remove main page headers (top level sticky)
6-
css('#__next > .sticky').remove
11+
css('#__next > .sticky', 'div.fixed.inset-x-0.top-0').remove
712
# And anything absolutely positioned (fancy floating navigation elements we don't care about)
8-
css('#__next .absolute').remove
13+
css('#__next .absolute', '.fixed').remove
914
# Remove the left-navigation we scraped
1015
css('nav').remove
1116

1217
css('svg').remove if root_page?
1318

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-
1719
# 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
1931

2032
# Remove footer + prev/next navigation
21-
at_css('footer').remove
33+
css('footer', '.row-start-5').remove
2234

2335
# 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')
2537
reference_container = class_reference.parent
2638
classes_container = reference_container.children.reject{ |child| child == class_reference }.first
2739

@@ -33,7 +45,7 @@ def call
3345
end
3446

3547
# 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')
3749
class_reference.parent.css("thead th:nth-child(3)").remove
3850
class_reference.parent.css("tbody td:nth-child(3)").remove
3951
end
@@ -59,29 +71,48 @@ def call
5971
end
6072

6173
# 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|
6378
node.parent.remove
6479
end
6580

6681
# Remove class examples - not part of devdocs styleguide? (similar to bootstrap)
6782
# Refer to https://github.com/freeCodeCamp/devdocs/pull/1534#pullrequestreview-649818936
68-
css('.not-prose').each do |node|
69-
if node.parent.children.length == 1
70-
node.parent.remove
71-
else
72-
node.remove
73-
end
74-
end
83+
css('.mt-4.-mb-3', 'figure', 'svg', '.flex.space-x-2').remove
7584

76-
# Properly format code examples
85+
# Properly format code examples.
7786
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+)/]
79-
node.parent.content = node.parent.content
87+
# v4 doesn't provide language context, so it must be inferred imperfectly.
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
80111
end
81112

82113
@doc.traverse { |node| cleanup_tailwind_classes(node) }
83114

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)
85116
css('hr').remove
86117

87118
doc

lib/docs/filters/tailwindcss/entries.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,35 @@ class Tailwindcss
33
class EntriesFilter < Docs::EntriesFilter
44
def get_type
55
# We are only interested in children list items
6-
selector = "nav li li a[href='#{result[:path]}']"
6+
77

8-
anchor = at_css(selector)
9-
category_list = anchor.ancestors('li')[1]
10-
title = category_list.css('h5')
8+
anchor = at_css(get_selector)
9+
title =
10+
if version == '3'
11+
anchor.ancestors('li')[1].css('h5')
12+
else
13+
anchor.ancestors('ul').last.previous_element
14+
end
1115

1216
return title.inner_text
1317
end
1418

1519
def get_name
1620
# We are only interested in children list items
17-
selector = "nav li li a[href='#{result[:path]}']"
18-
item = at_css(selector)
21+
item = at_css(get_selector)
1922

2023
return item.inner_text
2124
end
25+
26+
private
27+
28+
def get_selector
29+
if version == '3'
30+
"nav li li a[href='#{result[:path]}']"
31+
else
32+
"nav li a[href*='#{result[:path]}']"
33+
end
34+
end
2235
end
2336
end
2437
end

lib/docs/scrapers/tailwindcss.rb

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ class Tailwindcss < UrlScraper
33
self.name = 'Tailwind CSS'
44
self.type = 'tailwindcss'
55
self.slug = 'tailwindcss'
6-
self.base_url = 'https://tailwindcss.com/docs'
76
self.root_path = '/'
8-
self.release = '3.3.2'
97
self.links = {
108
home: 'https://tailwindcss.com/',
119
code: 'https://github.com/tailwindlabs/tailwindcss'
@@ -16,27 +14,6 @@ class Tailwindcss < UrlScraper
1614
# Disable the clean text filter which removes empty nodes - we'll do it ourselves more selectively
1715
text_filters.replace("clean_text", "tailwindcss/noop")
1816

19-
# Fix redirects from older tailwind 2 docs
20-
options[:fix_urls] = lambda do |url|
21-
if url.include? "installation/"
22-
break "/docs/installation"
23-
end
24-
25-
if url.end_with? "/breakpoints"
26-
break "/docs/screens#{/#.*$/.match(url)}"
27-
end
28-
if url.end_with? "/adding-base-styles"
29-
break "/docs/adding-custom-styles#adding-base-styles"
30-
end
31-
if url.end_with? "/ring-opacity"
32-
break "/docs/ring-color#changing-the-opacity"
33-
end
34-
35-
if url.match(/\/colors#?/)
36-
break "/docs/customizing-colors#{/#.*$/.match(url)}"
37-
end
38-
end
39-
4017
options[:skip_patterns] = [
4118
# Skip setup instructions
4219
/\/browser-support$/,
@@ -49,9 +26,51 @@ class Tailwindcss < UrlScraper
4926

5027
#Obtainable from https://github.com/tailwindlabs/tailwindcss/blob/master/LICENSE
5128
options[:attribution] = <<-HTML
52-
&copy; 2022 Tailwind Labs Inc.
29+
&copy; Tailwind Labs Inc.
5330
HTML
5431

32+
version do
33+
self.release = '4.1.11'
34+
self.base_url = 'https://tailwindcss.com/docs'
35+
36+
# Fix redirects
37+
options[:fix_urls] = lambda do |url|
38+
if url.include? "installation/"
39+
break "/docs/installation"
40+
end
41+
42+
if url.end_with? "text-color"
43+
break "/docs/color"
44+
end
45+
end
46+
end
47+
48+
version '3' do
49+
self.release = '3.4.17'
50+
self.base_url = 'https://v3.tailwindcss.com/docs'
51+
52+
# Fix redirects from older tailwind 2 docs
53+
options[:fix_urls] = lambda do |url|
54+
if url.include? "installation/"
55+
break "/docs/installation"
56+
end
57+
58+
if url.end_with? "/breakpoints"
59+
break "/docs/screens#{/#.*$/.match(url)}"
60+
end
61+
if url.end_with? "/adding-base-styles"
62+
break "/docs/adding-custom-styles#adding-base-styles"
63+
end
64+
if url.end_with? "/ring-opacity"
65+
break "/docs/ring-color#changing-the-opacity"
66+
end
67+
68+
if url.match(/\/colors#?/)
69+
break "/docs/customizing-colors#{/#.*$/.match(url)}"
70+
end
71+
end
72+
end
73+
5574
def get_latest_version(opts)
5675
get_latest_github_release('tailwindlabs', 'tailwindcss', opts)
5776
end

0 commit comments

Comments
 (0)