-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2375 from gombosg/master
feat: React.dev docs
- Loading branch information
Showing
9 changed files
with
180 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
._react { | ||
@extend %simple; | ||
|
||
.note { | ||
@extend %note; | ||
h4 { | ||
margin-top: .25rem; | ||
margin-bottom: .5rem; | ||
} | ||
} | ||
|
||
.note-orange { | ||
@extend %note-orange; | ||
} | ||
|
||
.note-blue { | ||
@extend %note-blue; | ||
} | ||
|
||
.note-green { | ||
@extend %note-green; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
module Docs | ||
class React | ||
class CleanHtmlReactDevFilter < Filter | ||
def call | ||
@doc = at_css('article') | ||
|
||
# Remove breadcrumbs before h1 | ||
css('h1').each do |node| | ||
if node.previous | ||
node.previous.remove | ||
end | ||
end | ||
|
||
remove_selectors = [ | ||
'div.grid > a', # prev-next links | ||
'button', # "show more" etc. buttons | ||
'div.order-last', # code iframe containers | ||
'div.dark-image', # dark images | ||
'a[title="Open in CodeSandbox"]', # codesandbox links | ||
] | ||
css(*remove_selectors).each do |node| | ||
node.remove | ||
end | ||
|
||
# Fix images not loading | ||
css('img').remove_attr('srcset') | ||
|
||
# Remove recipe blocks - TODO transform to outgoing link to docs | ||
css('h4[id^="examples-"]').each do |node| | ||
node.parent.parent.parent.remove | ||
end | ||
|
||
# Transform callout blocks | ||
class_transform = { | ||
'.expandable-callout[class*=yellow]' => 'note note-orange', # pitfalls, experimental | ||
'.expandable-callout[class*=green]' => 'note note-green', # note | ||
'.expandable-callout[class*=gray]' => 'note', # canary | ||
'.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', '.note h2').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 | ||
styling_prefixes = %w[ps- mx- my- px- py- mb- sp- rounded-] | ||
selectors = styling_prefixes.map { |prefix| "div[class*=\"#{prefix}\"]:not(.note)" } | ||
css(*selectors, 'div[class=""]', 'div.cm-line').each do |node| | ||
node.before(node.children).remove | ||
end | ||
|
||
# Syntax highlighting | ||
css('pre br').each do |node| | ||
node.replace("\n") | ||
end | ||
css('pre').each do |node| | ||
node['data-language'] = 'jsx' | ||
end | ||
|
||
# Remove styling except for callouts and images | ||
css('*:not([class*=image]):not(.note)').remove_attr('class').remove_attr('style') | ||
|
||
doc | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Docs | ||
class React | ||
class EntriesReactDevFilter < Docs::EntriesFilter | ||
def get_name | ||
name = at_css('article h1')&.content | ||
|
||
update_canary_copy(name) | ||
end | ||
|
||
def get_type | ||
# Category is the opened category in the sidebar | ||
category = css('a:has(> span.text-link) > div').first&.content | ||
# The grey category in the sidebar | ||
top_category = css('h3:has(~ li a.text-link)') | ||
.last&.content | ||
&.sub(/@.*$/, '') # remove version tag | ||
&.sub(/^./, &:upcase) # capitalize first letter | ||
&.concat(": ") | ||
is_learn_page = path.start_with?('learn/') || slug == 'learn' | ||
prefix = is_learn_page ? 'Learn: ' : top_category || '' | ||
|
||
update_canary_copy(prefix + (category || 'Miscellaneous')) | ||
end | ||
|
||
def update_canary_copy(string) | ||
canary_copy = '- This feature is available in the latest Canary' | ||
|
||
string.sub(canary_copy, ' (Canary)') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
https://es.m.wikipedia.org/wiki/React#/media/Archivo%3AReact.svg | ||
https://github.com/facebook/react/blob/master/docs/img/logo.svg | ||
https://github.com/reactjs/react.dev/blob/master/public/favicon-16x16.png | ||
https://github.com/reactjs/react.dev/blob/master/public/favicon-32x32.png |