Skip to content

Commit afd18f6

Browse files
committed
treat properly callouts
1 parent 94a7aa3 commit afd18f6

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

assets/stylesheets/application.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
'pages/qt',
110110
'pages/ramda',
111111
'pages/rdoc',
112+
'pages/react',
112113
'pages/react_native',
113114
'pages/reactivex',
114115
'pages/redis',

assets/stylesheets/pages/_react.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
._react {
2+
@extend %simple;
3+
4+
.note {
5+
@extend %note;
6+
}
7+
8+
.note-orange {
9+
@extend %note-orange;
10+
}
11+
12+
.note-blue {
13+
@extend %note-blue;
14+
}
15+
16+
.note-green {
17+
@extend %note-green;
18+
}
19+
20+
}

docs/adding-docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Adding a documentation may look like a daunting task but once you get the hang o
1313
6. Generate the full documentation using the `thor docs:generate [my_doc] --force` command. Additionally, you can use the `--verbose` option to see which files are being created/updated/deleted (useful to see what changed since the last run), and the `--debug` option to see which URLs are being requested and added to the queue (useful to pin down which page adds unwanted URLs to the queue).
1414
7. Start the server, open the app, enable the documentation, and see how everything plays out.
1515
8. Tweak the scraper/filters and repeat 5) and 6) until the pages and metadata are ok.
16-
9. To customize the pages' styling, create an SCSS file in the `assets/stylesheets/pages/` directory and import it in both `application.css.scss` AND `application-dark.css.scss`. Both the file and CSS class should be named `_[type]` where [type] is equal to the scraper's `type` attribute (documentations with the same type share the same custom CSS and JS). Setting the type to `simple` will apply the general styling rules in `assets/stylesheets/pages/_simple.scss`, which can be used for documentations where little to no CSS changes are needed.
16+
9. To customize the pages' styling, create an SCSS file in the `assets/stylesheets/pages/` directory and import it in `application.css.scss`. Both the file and CSS class should be named `_[type]` where [type] is equal to the scraper's `type` attribute (documentations with the same type share the same custom CSS and JS). Setting the type to `simple` will apply the general styling rules in `assets/stylesheets/pages/_simple.scss`, which can be used for documentations where little to no CSS changes are needed.
1717
10. To add syntax highlighting or execute custom JavaScript on the pages, create a file in the `assets/javascripts/views/pages/` directory (take a look at the other files to see how it works).
1818
11. Add the documentation's icon in the `public/icons/docs/[my_doc]/` directory, in both 16x16 and 32x32-pixels formats. The icon spritesheet is automatically generated when you (re)start your local DevDocs instance.
1919
12. Add the documentation's copyright details to `options[:attribution]`. This is the data shown in the table on the [about](https://devdocs.io/about) page, and is ordered alphabetically. Please see an existing scraper for the typesetting.

lib/docs/filters/react/clean_html_react_dev.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,30 @@ def call
3030
node.parent.parent.parent.remove
3131
end
3232

33+
# Transform callout blocks
34+
class_transform = {
35+
'.expandable-callout[class*=yellow]' => 'note note-orange', # pitfalls, experimental
36+
'.expandable-callout[class*=green]' => 'note note-green', # note
37+
'.bg-card' => 'note', # you will learn
38+
'details' => 'note note-blue' # deep dive
39+
}
40+
41+
class_transform.each do |old_class, new_class|
42+
css(old_class).each do |node|
43+
node.set_attribute('class', new_class)
44+
end
45+
end
46+
47+
# Transform h3 to h4 inside callouts
48+
css('.note h3').each do |node|
49+
new_node = Nokogiri::XML::Node.new('h4', @doc)
50+
new_node.content = node.content
51+
node.replace(new_node)
52+
end
53+
3354
# Remove styling divs while lifting children
3455
styling_prefixes = %w[ps- mx- my- px- py- mb- sp- rounded-]
35-
selectors = styling_prefixes.map { |prefix| "div[class*=\"#{prefix}\"]" }
56+
selectors = styling_prefixes.map { |prefix| "div[class*=\"#{prefix}\"]:not(.note)" }
3657
css(*selectors, 'div[class=""]', 'div.cm-line').each do |node|
3758
node.before(node.children).remove
3859
end
@@ -45,8 +66,8 @@ def call
4566
node['data-language'] = 'jsx'
4667
end
4768

48-
# Remove styling
49-
css('*').remove_attr('class').remove_attr('style')
69+
# Remove styling except for callouts and images
70+
css('*:not([class*=image]):not(.note)').remove_attr('class').remove_attr('style')
5071

5172
doc
5273
end

lib/docs/filters/react/entries_react_dev.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_type
1616
&.sub(/^./, &:upcase) # capitalize first letter
1717
&.concat(": ")
1818
is_learn_page = path.start_with?('learn/') || slug == 'learn'
19-
prefix = is_learn_page ? 'Learn: ' : top_category
19+
prefix = is_learn_page ? 'Learn: ' : top_category || ''
2020
return update_canary_copy(prefix + (category || 'Miscellaneous'))
2121
end
2222

lib/docs/scrapers/react.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Docs
22
class React < UrlScraper
33

44
self.name = 'React'
5-
self.type = 'simple'
5+
self.type = 'react'
66
self.links = {
77
home: 'https://react.dev/',
88
code: 'https://github.com/facebook/react'

0 commit comments

Comments
 (0)