diff --git a/lib/docs/filters/deno/clean_html.rb b/lib/docs/filters/deno/clean_html.rb index c2b1befd..46fc16e4 100644 --- a/lib/docs/filters/deno/clean_html.rb +++ b/lib/docs/filters/deno/clean_html.rb @@ -2,26 +2,22 @@ module Docs class Deno class CleanHtmlFilter < Filter def call - if root_page? - @doc = at_css('h2[id]').parent.parent + if result[:path].start_with?('api/deno/') + @doc = at_css('main') else - @doc = at_css('article') + @doc = at_css('main article .markdown-body') end - css('*[aria-label="Anchor"]').remove - css('pre', '.tw-1nkr705').each do |node| - node['data-language'] = 'typescript' - node.name = 'pre' + css('code').each do |node| + if node['class'] + lang = node['class'][/language-(\w+)/, 1] + end + node['data-language'] = lang || 'ts' + node.remove_attribute('class') end - css('.tw-8ej7ai').each do |node| - code = node.at_css('.font-mono') - next unless code - code.parent.name = 'blockquote' - code.name = 'code' - end - css('*[class]').remove_attribute('class') - xpath('//a[text()="[src]"]').remove - + + css('a.header-anchor').remove() + doc end end diff --git a/lib/docs/filters/deno/entries.rb b/lib/docs/filters/deno/entries.rb index f088a838..279086f3 100644 --- a/lib/docs/filters/deno/entries.rb +++ b/lib/docs/filters/deno/entries.rb @@ -3,11 +3,21 @@ module Docs class EntriesFilter < Docs::EntriesFilter def get_name - at_css('h1').content + if result[:path].start_with?('api/deno/') + at_css('main')['id'][/\Asymbol_([.\w]+)/, 1] + else + at_css('main article h1').content + end end def get_type - 'Deno CLI APIs' + if result[:path].start_with?('api/deno/') + 'API' + elsif result[:path].start_with?('runtime/reference/cli') + 'CLI' + else + at_css('main article nav ul :first span').content + end end end diff --git a/lib/docs/scrapers/deno.rb b/lib/docs/scrapers/deno.rb index 1b00b705..3d76eada 100644 --- a/lib/docs/scrapers/deno.rb +++ b/lib/docs/scrapers/deno.rb @@ -2,22 +2,40 @@ module Docs class Deno < UrlScraper self.name = 'Deno' self.type = 'simple' - self.release = '1.27.0' - self.base_url = 'https://doc.deno.land/deno/stable/' self.links = { - home: 'https://deno.land/', + home: 'https://deno.com/', code: 'https://github.com/denoland/deno' } - html_filters.push 'deno/entries', 'deno/clean_html' - # https://github.com/denoland/manual/blob/main/LICENSE options[:attribution] = <<-HTML - © 2018–2022 the Deno authors + © 2018–2024 the Deno authors
+ Licensed under the MIT License. HTML + + html_filters.push 'deno/entries', 'deno/clean_html' + + version '2' do + self.release = '2.1.1' + self.base_url = 'https://docs.deno.com/' + self.root_path = 'runtime' + options[:only_patterns] = [/\Aruntime/, /\Aapi\/deno\/~/, /\Adeploy/, /\Asubhosting/] + options[:skip_patterns] = [ + /\Aruntime\/manual/, + /\Aapi\/deno\/.+\.prototype\z/, # all prototype pages get redirected to the main page + /\Aapi\/deno\/~\/Deno\.jupyter\.MediaBundle.+/, # docs unavailable + /\Aapi\/deno\/~\/Deno\.OpMetrics/, # deprecated in deno 2 + ] + options[:trailing_slash] = false + end + + version '1' do + self.release = '1.27.0' + end + def get_latest_version(opts) get_latest_github_release('denoland', 'deno', opts) - end + end end end