From 1378b3878edb917f5e6ca992e8ea30433cd7b9c6 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Thu, 18 Nov 2021 04:01:43 +0100 Subject: [PATCH] Update Kotlin documentation (1.6.0) --- lib/docs/filters/kotlin/clean_html.rb | 8 +++++- lib/docs/filters/kotlin/entries.rb | 15 ++++++----- lib/docs/scrapers/kotlin.rb | 37 +++++++++++++++++---------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/lib/docs/filters/kotlin/clean_html.rb b/lib/docs/filters/kotlin/clean_html.rb index 0d14c058..e65216d5 100644 --- a/lib/docs/filters/kotlin/clean_html.rb +++ b/lib/docs/filters/kotlin/clean_html.rb @@ -2,7 +2,6 @@ module Docs class Kotlin class CleanHtmlFilter < Filter def call - @doc = at_css('.page-content') subpath.start_with?('api') ? api_page : doc_page doc end @@ -14,6 +13,13 @@ module Docs node.parent.before(node.parent.content).remove end + css('div.code-block').each do |node| + node.name = 'pre' + node['data-language'] = node['data-lang'] + node.content = node.content + # FIXME: newlines in code-block are lost because of
? (on https://kotlinlang.org/docs/typecasts.html for instance) + end + css('pre').each do |node| node['data-language'] = 'kotlin' if node.at_css('code.language-kotlin') node['data-language'] = 'groovy' if node.at_css('code.language-groovy') diff --git a/lib/docs/filters/kotlin/entries.rb b/lib/docs/filters/kotlin/entries.rb index 2afb1e86..96578e50 100644 --- a/lib/docs/filters/kotlin/entries.rb +++ b/lib/docs/filters/kotlin/entries.rb @@ -6,25 +6,26 @@ module Docs breadcrumbs[1..-1].join('.') else node = (at_css('h1') || at_css('h2')) - return node.content unless node.nil? - subpath[/\/([a-z0-9_-]+)\./][1..-2].titleize.sub('Faq', 'FAQ') + return [breadcrumbs[1..], [node.content]].flatten.join(': ') unless node.nil? end end def get_type if subpath.start_with?('api') breadcrumbs[1] - elsif subpath.start_with?('docs/tutorials') - 'Tutorials' - elsif subpath.start_with?('docs/reference') - 'Reference' + else + breadcrumbs[0] end end private def breadcrumbs - @breadcrumbs ||= css('.api-docs-breadcrumbs a').map(&:content).map(&:strip) + if subpath.start_with?('api') + @breadcrumbs ||= css('.api-docs-breadcrumbs a').map(&:content).map(&:strip) + else + @breadcrumbs ||= doc.document.at_css('body')['data-breadcrumbs'].split('///') + end end end end diff --git a/lib/docs/scrapers/kotlin.rb b/lib/docs/scrapers/kotlin.rb index 91ca19ff..c9291a89 100644 --- a/lib/docs/scrapers/kotlin.rb +++ b/lib/docs/scrapers/kotlin.rb @@ -1,7 +1,6 @@ module Docs class Kotlin < UrlScraper self.type = 'kotlin' - self.release = '1.4.10' self.base_url = 'https://kotlinlang.org/' self.root_path = 'api/latest/jvm/stdlib/index.html' self.links = { @@ -11,9 +10,8 @@ module Docs html_filters.push 'kotlin/entries', 'kotlin/clean_html' - options[:container] = '.global-content' - - options[:only_patterns] = [/\Adocs\/tutorials\//, /\Adocs\/reference\//, /\Aapi\/latest\/jvm\/stdlib\//] + options[:container] = 'article' + options[:only_patterns] = [/\Adocs\//, /\Aapi\/latest\/jvm\/stdlib\//] options[:skip_patterns] = [/stdlib\/org\./] options[:skip] = %w( api/latest/jvm/stdlib/alltypes/index.html @@ -22,23 +20,34 @@ module Docs docs/events.html docs/resources.html docs/reference/grammar.html) - options[:replace_paths] = { - 'api/latest/jvm/stdlib/' => 'api/latest/jvm/stdlib/index.html', - 'docs/reference/coroutines.html' => 'docs/reference/coroutines-overview.html', - 'api/latest/jvm/stdlib/kotlin/fold.html' => 'api/latest/jvm/stdlib/kotlin.collections/fold.html', - 'api/latest/jvm/stdlib/kotlin/get-or-else.html' => 'api/latest/jvm/stdlib/kotlin.collections/get-or-else.html', - 'api/latest/jvm/stdlib/kotlin/map.html' => 'api/latest/jvm/stdlib/kotlin.collections/map.html', - 'docs/tutorials/native/targeting-multiple-platforms.html' => 'docs/tutorials/native/basic-kotlin-native-app.html', - 'api/latest/jvm/stdlib/kotlin/-throwable/print-stack-trace.html' => 'api/latest/jvm/stdlib/kotlin/print-stack-trace.html', - } + + options[:fix_urls] = ->(url) do + url.sub! %r{/docs/reference/}, '/docs/' + url + end options[:attribution] = <<-HTML - © 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
+ © 2010–2021 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0. HTML + version '1.6' do + self.release = '1.6.0' + end + + version '1.4' do + self.release = '1.4.10' + end + def get_latest_version(opts) get_latest_github_release('JetBrains', 'kotlin', opts) end + + private + + def process_response?(response) + return false unless super + response.body !~ /http-equiv="refresh"/i + end end end