瀏覽代碼

Merge pull request #2266 from breunigs/ex-1.16-1.17

Update Elixir documentation (1.16 and 1.17)
Simon Legner 1 年之前
父節點
當前提交
15b8875a54
共有 3 個文件被更改,包括 52 次插入54 次删除
  1. 7 22
      lib/docs/filters/elixir/clean_html.rb
  2. 14 24
      lib/docs/filters/elixir/entries.rb
  3. 31 8
      lib/docs/scrapers/elixir.rb

+ 7 - 22
lib/docs/filters/elixir/clean_html.rb

@@ -2,32 +2,12 @@ module Docs
   class Elixir
     class CleanHtmlFilter < Filter
       def call
-        if current_url.path.start_with?('/getting-started')
-          guide
-        else
-          api
-        end
+        api
         doc
       end
 
-      def guide
-        @doc = at_css('#content article')
-
-        css('pre > code').each do |node|
-          node.parent.content = node.content
-        end
-
-        css('div > pre.highlight').each do |node|
-          node.content = node.content
-          node['data-language'] = node.parent['class'][/language-(\w+)/, 1]
-          node.parent.before(node).remove
-        end
-      end
-
       def api
-        css('.hover-link', 'footer', ':not(.detail-header) > .view-source').remove
-
-        css('h1 .settings').remove
+        css('.top-search').remove
 
         css('.summary').each do |node|
           node.name = 'dl'
@@ -65,6 +45,11 @@ module Docs
           end
         end
 
+        css('h1 a.icon-action[title="View Source"]').each do |node|
+          node['class'] = 'source'
+          node.content = "Source"
+        end
+
         css('pre').each do |node|
           node['data-language'] = 'elixir'
           node.content = node.content

+ 14 - 24
lib/docs/filters/elixir/entries.rb

@@ -3,25 +3,21 @@ module Docs
     class EntriesFilter < Docs::EntriesFilter
       def get_name
         css('h1 .app-vsn').remove
-        name = (at_css('h1 > span') or at_css('h1')).content.strip
-
-        if current_url.path.start_with?('/getting-started')
-          name.remove(/\.\z/)
-        else
-          name = name.split(' ').first unless name.start_with?('mix ') # ecto
-          name
-        end
+        (at_css('h1 > span') or at_css('h1')).content.strip
       end
 
       def get_type
-        if current_url.path.start_with?('/getting-started')
-          if subpath.start_with?('mix-otp')
-            'Guide: Mix & OTP'
-          elsif subpath.start_with?('meta')
-            'Guide: Metaprogramming'
-          else
-            'Guide'
-          end
+        section = at_css('h1 a.source').attr('href').match('elixir/pages/([^/]+)/')&.captures&.first
+        if section == "mix-and-otp"
+          return "Mix & OTP"
+        elsif section
+          return section.gsub("-", " ").capitalize
+        end
+
+        name = at_css('h1 span').text
+        case name.split(' ').first
+        when 'mix' then 'Mix Tasks'
+        when 'Changelog' then 'References'
         else
           case at_css('h1 small').try(:content)
           when 'exception'
@@ -29,19 +25,13 @@ module Docs
           when 'protocol'
             'Protocols'
           else
-            if name.start_with?('Phoenix')
-              name.split('.')[0..2].join('.')
-            elsif name.start_with?('mix ')
-              'Mix Tasks'
-            else
-              name.split('.').first
-            end
+            name
           end
         end
       end
 
       def additional_entries
-        return [] if type == 'Exceptions' || type == 'Guide' || root_page?
+        return [] if root_page?
 
         css('.detail-header').map do |node|
           id = node['id']

+ 31 - 8
lib/docs/scrapers/elixir.rb

@@ -4,7 +4,7 @@ module Docs
 
     self.name = 'Elixir'
     self.type = 'elixir'
-    self.root_path = 'api-reference.html'
+    self.root_path = 'introduction.html'
     self.links = {
       home: 'https://elixir-lang.org/',
       code: 'https://github.com/elixir-lang/elixir'
@@ -12,27 +12,50 @@ module Docs
 
     html_filters.push 'elixir/clean_html', 'elixir/entries', 'title'
 
-    options[:container] = ->(filter) {
-      filter.current_url.path.start_with?('/getting-started') ? '#main' : '#content'
-    }
+    options[:container] = '#content'
     options[:title] = false
     options[:root_title] = 'Elixir'
 
     options[:attribution] = <<-HTML
-      &copy; 2012 Plataformatec<br>
+      &copy; 2012-2024 The Elixir Team<br>
       Licensed under the Apache License, Version 2.0.
     HTML
 
     def initial_urls
-      [ "https://hexdocs.pm/elixir/#{self.class.release}/api-reference.html",
+      [ "https://hexdocs.pm/elixir/#{self.class.release}/introduction.html",
         "https://hexdocs.pm/eex/#{self.class.release}/EEx.html",
         "https://hexdocs.pm/ex_unit/#{self.class.release}/ExUnit.html",
         "https://hexdocs.pm/iex/#{self.class.release}/IEx.html",
         "https://hexdocs.pm/logger/#{self.class.release}/Logger.html",
-        "https://hexdocs.pm/mix/#{self.class.release}/Mix.html",
-        "https://elixir-lang.org/getting-started/introduction.html" ]
+        "https://hexdocs.pm/mix/#{self.class.release}/Mix.html" ]
+    end
+
+    version '1.17' do
+      self.release = '1.17.2'
+      self.base_urls = [
+        "https://hexdocs.pm/elixir/#{release}/",
+        "https://hexdocs.pm/eex/#{release}/",
+        "https://hexdocs.pm/ex_unit/#{release}/",
+        "https://hexdocs.pm/iex/#{release}/",
+        "https://hexdocs.pm/logger/#{release}/",
+        "https://hexdocs.pm/mix/#{release}/"
+      ]
     end
 
+    version '1.16' do
+      self.release = '1.16.3'
+      self.base_urls = [
+        "https://hexdocs.pm/elixir/#{release}/",
+        "https://hexdocs.pm/eex/#{release}/",
+        "https://hexdocs.pm/ex_unit/#{release}/",
+        "https://hexdocs.pm/iex/#{release}/",
+        "https://hexdocs.pm/logger/#{release}/",
+        "https://hexdocs.pm/mix/#{release}/"
+      ]
+    end
+
+    # scraping of older versions is no longer supported!
+
     version '1.15' do
       self.release = '1.15.4'
       self.base_urls = [