From 0ac54123585e40bab507cdf213bd36c214677702 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Mon, 9 Oct 2023 21:55:03 +0200 Subject: [PATCH] Update Svelte documentation (4.2.1) --- lib/docs/filters/svelte/clean_html.rb | 8 ++++++-- lib/docs/filters/svelte/entries.rb | 12 ++++++++---- lib/docs/scrapers/svelte.rb | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/docs/filters/svelte/clean_html.rb b/lib/docs/filters/svelte/clean_html.rb index 579b27b7..693825f7 100644 --- a/lib/docs/filters/svelte/clean_html.rb +++ b/lib/docs/filters/svelte/clean_html.rb @@ -2,8 +2,12 @@ module Docs class Svelte class CleanHtmlFilter < Filter def call - @doc = at_css('main > .content') - at_css('h1').content = 'Svelte' + @doc = at_css('main .page.content') + at_css('h1').content = 'Svelte' if root_page? + css('pre').each do |node| + node.content = node.css('.line').map(&:content).join("\n") + node['data-language'] = 'javascript' + end doc end end diff --git a/lib/docs/filters/svelte/entries.rb b/lib/docs/filters/svelte/entries.rb index ab7236ff..dcd66cc2 100644 --- a/lib/docs/filters/svelte/entries.rb +++ b/lib/docs/filters/svelte/entries.rb @@ -2,15 +2,18 @@ module Docs class Svelte class EntriesFilter < Docs::EntriesFilter def get_type - 'Svelte' + at_css('ul.sidebar > li:has(.active) > span.section').content end def additional_entries - type = 'Svelte' subtype = nil + css('aside').remove + css('.category').remove + css('.controls').remove + css('.edit').remove + css('.permalink').remove css('h2, h3, h4').each_with_object [] do |node, entries| if node.name == 'h2' - type = node.content.strip subtype = nil elsif node.name == 'h3' subtype = node.content.strip @@ -19,7 +22,8 @@ module Docs next if type == 'Before we begin' name = node.content.strip name.concat " (#{subtype})" if subtype && node.name == 'h4' - entries << [name, node['id'], subtype || type] + next if name.starts_with?('Example') + entries << [name, node['id'], get_type] end end end diff --git a/lib/docs/scrapers/svelte.rb b/lib/docs/scrapers/svelte.rb index 2dc90ac0..c5900a0b 100644 --- a/lib/docs/scrapers/svelte.rb +++ b/lib/docs/scrapers/svelte.rb @@ -8,18 +8,27 @@ module Docs code: 'https://github.com/sveltejs/svelte' } + self.root_path = 'introduction' options[:root_title] = 'Svelte' + # https://github.com/sveltejs/svelte/blob/master/LICENSE.md options[:attribution] = <<-HTML - © 2016–2022 Rich Harris and contributors
+ © 2016–2023 Rich Harris and contributors
Licensed under the MIT License. HTML options[:skip] = %w(team.html plugins/) - self.release = '3.55.0' - self.base_url = 'https://svelte.dev/docs' + self.base_url = 'https://svelte.dev/docs/' html_filters.push 'svelte/entries', 'svelte/clean_html' + + version do + self.release = '4.2.1' + end + + version '3' do + self.release = '3.55.0' + end def get_latest_version(opts) get_npm_version('svelte', opts)