treat properly callouts

pull/2375/head
Gergely Gombos 1 month ago
parent 94a7aa3c34
commit afd18f66af

@ -109,6 +109,7 @@
'pages/qt', 'pages/qt',
'pages/ramda', 'pages/ramda',
'pages/rdoc', 'pages/rdoc',
'pages/react',
'pages/react_native', 'pages/react_native',
'pages/reactivex', 'pages/reactivex',
'pages/redis', 'pages/redis',

@ -0,0 +1,20 @@
._react {
@extend %simple;
.note {
@extend %note;
}
.note-orange {
@extend %note-orange;
}
.note-blue {
@extend %note-blue;
}
.note-green {
@extend %note-green;
}
}

@ -13,7 +13,7 @@ Adding a documentation may look like a daunting task but once you get the hang o
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). 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).
7. Start the server, open the app, enable the documentation, and see how everything plays out. 7. Start the server, open the app, enable the documentation, and see how everything plays out.
8. Tweak the scraper/filters and repeat 5) and 6) until the pages and metadata are ok. 8. Tweak the scraper/filters and repeat 5) and 6) until the pages and metadata are ok.
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. 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.
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). 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).
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. 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.
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. 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.

@ -30,9 +30,30 @@ module Docs
node.parent.parent.parent.remove node.parent.parent.parent.remove
end end
# Transform callout blocks
class_transform = {
'.expandable-callout[class*=yellow]' => 'note note-orange', # pitfalls, experimental
'.expandable-callout[class*=green]' => 'note note-green', # note
'.bg-card' => 'note', # you will learn
'details' => 'note note-blue' # deep dive
}
class_transform.each do |old_class, new_class|
css(old_class).each do |node|
node.set_attribute('class', new_class)
end
end
# Transform h3 to h4 inside callouts
css('.note h3').each do |node|
new_node = Nokogiri::XML::Node.new('h4', @doc)
new_node.content = node.content
node.replace(new_node)
end
# Remove styling divs while lifting children # Remove styling divs while lifting children
styling_prefixes = %w[ps- mx- my- px- py- mb- sp- rounded-] styling_prefixes = %w[ps- mx- my- px- py- mb- sp- rounded-]
selectors = styling_prefixes.map { |prefix| "div[class*=\"#{prefix}\"]" } selectors = styling_prefixes.map { |prefix| "div[class*=\"#{prefix}\"]:not(.note)" }
css(*selectors, 'div[class=""]', 'div.cm-line').each do |node| css(*selectors, 'div[class=""]', 'div.cm-line').each do |node|
node.before(node.children).remove node.before(node.children).remove
end end
@ -45,8 +66,8 @@ module Docs
node['data-language'] = 'jsx' node['data-language'] = 'jsx'
end end
# Remove styling # Remove styling except for callouts and images
css('*').remove_attr('class').remove_attr('style') css('*:not([class*=image]):not(.note)').remove_attr('class').remove_attr('style')
doc doc
end end

@ -16,7 +16,7 @@ module Docs
&.sub(/^./, &:upcase) # capitalize first letter &.sub(/^./, &:upcase) # capitalize first letter
&.concat(": ") &.concat(": ")
is_learn_page = path.start_with?('learn/') || slug == 'learn' is_learn_page = path.start_with?('learn/') || slug == 'learn'
prefix = is_learn_page ? 'Learn: ' : top_category prefix = is_learn_page ? 'Learn: ' : top_category || ''
return update_canary_copy(prefix + (category || 'Miscellaneous')) return update_canary_copy(prefix + (category || 'Miscellaneous'))
end end

@ -2,7 +2,7 @@ module Docs
class React < UrlScraper class React < UrlScraper
self.name = 'React' self.name = 'React'
self.type = 'simple' self.type = 'react'
self.links = { self.links = {
home: 'https://react.dev/', home: 'https://react.dev/',
code: 'https://github.com/facebook/react' code: 'https://github.com/facebook/react'

Loading…
Cancel
Save