History

Merge pull request #2142 from freeCodeCamp/playwright

Add playwright documentation

Simon Legner committed 2 years ago

Commit 02c48712 parents 6d62e69 d774d067 files · +82 −-2Browse files

Unified · Split

7 files
  1. assets/javascripts/news.json +4 −0
  2. lib/docs/filters/playwright/clean_html.rb +29 −0
  3. lib/docs/filters/playwright/entries.rb +23 −0
  4. lib/docs/scrapers/playwright.rb +27 −0
  5. public/icons/docs/playwright/16.png +0 −0
  6. public/icons/docs/playwright/16@2x.png +0 −0
  7. public/icons/docs/playwright/SOURCE +1 −0
assets/javascripts/news.json+4−0
@@ -1,4 +1,8 @@
11 [
2+ [
3+ "2024-01-24",
4+ "New documentation: <a href=\"/playwright/\">Playwright</a>"
5+ ],
26 [
37 "2024-01-20",
48 "New documentation: <a href=\"/htmx/\">htmx</a>"
lib/docs/filters/playwright/clean_html.rb+29−0
@@ -0,0 +1,29 @@
1+module Docs
2+ class Playwright
3+ class CleanHtmlFilter < Filter
4+ def call
5+ @doc = at_css('.markdown')
6+
7+ css('x-search').remove
8+ css('hr').remove
9+ css('font:contains("Added in")').remove
10+ css('.list-anchor').remove
11+
12+ css('.alert').each do |node|
13+ node.name = 'blockquote'
14+ end
15+
16+ css('pre').each do |node|
17+ node.content = node.css('.token-line').map(&:content).join("\n")
18+ node.remove_attribute('style')
19+ node['data-language'] = node.content =~ /\A\s*</ ? 'html' : 'javascript'
20+ node.ancestors('.theme-code-block').first.replace(node)
21+ end
22+
23+ css('*[class]').remove_attribute('class')
24+
25+ doc
26+ end
27+ end
28+ end
29+end
lib/docs/filters/playwright/entries.rb+23−0
@@ -0,0 +1,23 @@
1+module Docs
2+ class Playwright
3+ class EntriesFilter < Docs::EntriesFilter
4+ def get_name
5+ at_css('h1').children.select(&:text?).map(&:content).join.strip
6+ end
7+
8+ def type
9+ type = at_css('.menu__link--active').content
10+ return "#{type}: #{name}" if slug.starts_with?('api/')
11+ type
12+ end
13+
14+ def additional_entries
15+ css('x-search').each_with_object [] do |node, entries|
16+ prev = node.previous_element
17+ prev = prev.previous_element until prev['id']
18+ entries << [node.text, prev['id']]
19+ end
20+ end
21+ end
22+ end
23+end
lib/docs/scrapers/playwright.rb+27−0
@@ -0,0 +1,27 @@
1+module Docs
2+ class Playwright < UrlScraper
3+ self.name = 'Playwright'
4+ self.type = 'simple'
5+ self.release = '1.41.1'
6+ self.base_url = 'https://playwright.dev/docs/'
7+ self.root_path = 'intro'
8+ self.links = {
9+ home: 'https://playwright.dev/',
10+ code: 'https://github.com/microsoft/playwright'
11+ }
12+
13+ # Docusaurus like react_native
14+ html_filters.push 'playwright/entries', 'playwright/clean_html'
15+ options[:download_images] = false
16+
17+ # https://github.com/microsoft/playwright/blob/main/LICENSE
18+ options[:attribution] = <<-HTML
19+ &copy; 2024 Microsoft<br>
20+ Licensed under the Apache License, Version 2.0.
21+ HTML
22+
23+ def get_latest_version(opts)
24+ get_npm_version('@playwright/test', opts)
25+ end
26+ end
27+end
public/icons/docs/playwright/16.png+0−0

Binary file not shown.

public/icons/docs/playwright/16@2x.png+0−0

Binary file not shown.

public/icons/docs/playwright/SOURCE+1−0
@@ -0,0 +1 @@
1+https://playwright.dev/img/playwright-logo.svg