소스 검색

Merge pull request #1838 from freeCodeCamp/astro

Add Astro documentation (1.4.7)
Simon Legner 3 년 전
부모
커밋
ffde393d75

+ 4 - 0
assets/javascripts/news.json

@@ -1,4 +1,8 @@
 [
+  [
+    "2022-10-10",
+    "New documentation: <a href=\"/astro/\">Astro</a>"
+  ],
   [
     "2022-10-09",
     "New documentations: <a href=\"/fastapi/\">FastAPI</a>, <a href=\"/vitest/\">Vitest</a>"

+ 5 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -101,6 +101,11 @@ credits = [
     '2018 The Apache Software Foundation<br>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.',
     'Apache',
     'https://www.apache.org/licenses/LICENSE-2.0'
+  ], [
+    'Astro',
+    '2022 withastro',
+    'MIT',
+    'https://github.com/withastro/docs/blob/main/LICENSE'
   ], [
     'Async',
     '2010-2018 Caolan McMahon',

+ 28 - 0
lib/docs/filters/astro/clean_html.rb

@@ -0,0 +1,28 @@
+module Docs
+  class Astro
+    class CleanHtmlFilter < Filter
+      def call
+        @doc = at_css('article > section')
+
+        css('.anchor-link').remove
+
+        css('pre').each do |node|
+          node.content = node.css('.line').map(&:content).join("\n")
+          node['data-language'] = node.ancestors('figure').first['class'][/lang-(\w+)/, 1]
+          node.remove_attribute('style')
+        end
+
+        css('figcaption').each do |node|
+          node.name = 'div'
+          node['class'] = '_pre-heading'
+        end
+
+        css('figure').each do |node|
+          node.before(node.children).remove
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 25 - 0
lib/docs/filters/astro/entries.rb

@@ -0,0 +1,25 @@
+module Docs
+  class Astro
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        name = at_css('h1').content
+        name.sub! %r{\s*#\s*}, ''
+        name
+      end
+
+      def get_type
+        aside = at_css('aside')
+        a = aside.at_css('a[aria-current="page"]', 'a[data-current-parent="true"]')
+        a.ancestors('details').at_css('summary').content
+      end
+
+      def additional_entries
+        at_css('article').css('h2, h3').each_with_object [] do |node, entries|
+          type = node.content.strip
+          type.sub! %r{\s*#\s*}, ''
+          entries << ["#{name}: #{type}", node['id']]
+        end
+      end
+    end
+  end
+end

+ 38 - 0
lib/docs/scrapers/astro.rb

@@ -0,0 +1,38 @@
+module Docs
+  class Astro < UrlScraper
+    self.name = 'Astro'
+    self.slug = 'astro'
+    self.type = 'simple'
+    self.links = {
+      home: 'https://docs.astro.build/',
+      code: 'https://github.com/withastro/astro'
+    }
+
+    # https://github.com/withastro/astro/blob/main/LICENSE
+    options[:attribution] = <<-HTML
+      &copy; 2021 Fred K. Schott<br>
+      Licensed under the MIT License.
+    HTML
+
+    self.release = '1.4.7'
+    self.base_url = 'https://docs.astro.build/en/'
+    self.initial_paths = %w(getting-started/)
+
+    html_filters.push 'astro/entries', 'astro/clean_html'
+
+    def get_latest_version(opts)
+      get_npm_version('astro', opts)
+    end
+
+    private
+
+    def parse(response)
+      if response.url == self.base_url
+        # root_page is a redirect
+        response.body.gsub! %r{.*}, '<body><article><section><h1>Astro</h1><p> Astro is a website build tool for the modern web — powerful developer experience meets lightweight output.</p></section></article></body>'
+      end
+      super
+    end
+
+  end
+end

BIN
public/icons/docs/astro/16.png


BIN
public/icons/docs/astro/16@2x.png


+ 2 - 0
public/icons/docs/astro/SOURCE

@@ -0,0 +1,2 @@
+https://docs.astro.build/favicon.ico
+https://docs.astro.build/favicon.svg