History

Merge pull request #1838 from freeCodeCamp/astro

Add Astro documentation (1.4.7)

Simon Legner committed 4 years ago

Commit ffde3932 parents d9f2f33 03d3f208 files · +100 −-2Browse files

Unified · Split

8 files
  1. assets/javascripts/news.json +4 −0
  2. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  3. lib/docs/filters/astro/clean_html.rb +28 −0
  4. lib/docs/filters/astro/entries.rb +25 −0
  5. lib/docs/scrapers/astro.rb +38 −0
  6. public/icons/docs/astro/16.png +0 −0
  7. public/icons/docs/astro/16@2x.png +0 −0
  8. public/icons/docs/astro/SOURCE +2 −0
assets/javascripts/news.json+4−0
@@ -1,4 +1,8 @@
11 [
2+ [
3+ "2022-10-10",
4+ "New documentation: <a href=\"/astro/\">Astro</a>"
5+ ],
26 [
37 "2022-10-09",
48 "New documentations: <a href=\"/fastapi/\">FastAPI</a>, <a href=\"/vitest/\">Vitest</a>"
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -101,6 +101,11 @@ credits = [ · 100 unmodified lines
101101 '2018 The Apache Software Foundation<br>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.',
102102 'Apache',
103103 'https://www.apache.org/licenses/LICENSE-2.0'
104+ ], [
105+ 'Astro',
106+ '2022 withastro',
107+ 'MIT',
108+ 'https://github.com/withastro/docs/blob/main/LICENSE'
104109 ], [
105110 'Async',
106111 '2010-2018 Caolan McMahon',
lib/docs/filters/astro/clean_html.rb+28−0
@@ -0,0 +1,28 @@
1+module Docs
2+ class Astro
3+ class CleanHtmlFilter < Filter
4+ def call
5+ @doc = at_css('article > section')
6+
7+ css('.anchor-link').remove
8+
9+ css('pre').each do |node|
10+ node.content = node.css('.line').map(&:content).join("\n")
11+ node['data-language'] = node.ancestors('figure').first['class'][/lang-(\w+)/, 1]
12+ node.remove_attribute('style')
13+ end
14+
15+ css('figcaption').each do |node|
16+ node.name = 'div'
17+ node['class'] = '_pre-heading'
18+ end
19+
20+ css('figure').each do |node|
21+ node.before(node.children).remove
22+ end
23+
24+ doc
25+ end
26+ end
27+ end
28+end
lib/docs/filters/astro/entries.rb+25−0
@@ -0,0 +1,25 @@
1+module Docs
2+ class Astro
3+ class EntriesFilter < Docs::EntriesFilter
4+ def get_name
5+ name = at_css('h1').content
6+ name.sub! %r{\s*#\s*}, ''
7+ name
8+ end
9+
10+ def get_type
11+ aside = at_css('aside')
12+ a = aside.at_css('a[aria-current="page"]', 'a[data-current-parent="true"]')
13+ a.ancestors('details').at_css('summary').content
14+ end
15+
16+ def additional_entries
17+ at_css('article').css('h2, h3').each_with_object [] do |node, entries|
18+ type = node.content.strip
19+ type.sub! %r{\s*#\s*}, ''
20+ entries << ["#{name}: #{type}", node['id']]
21+ end
22+ end
23+ end
24+ end
25+end
lib/docs/scrapers/astro.rb+38−0
@@ -0,0 +1,38 @@
1+module Docs
2+ class Astro < UrlScraper
3+ self.name = 'Astro'
4+ self.slug = 'astro'
5+ self.type = 'simple'
6+ self.links = {
7+ home: 'https://docs.astro.build/',
8+ code: 'https://github.com/withastro/astro'
9+ }
10+
11+ # https://github.com/withastro/astro/blob/main/LICENSE
12+ options[:attribution] = <<-HTML
13+ &copy; 2021 Fred K. Schott<br>
14+ Licensed under the MIT License.
15+ HTML
16+
17+ self.release = '1.4.7'
18+ self.base_url = 'https://docs.astro.build/en/'
19+ self.initial_paths = %w(getting-started/)
20+
21+ html_filters.push 'astro/entries', 'astro/clean_html'
22+
23+ def get_latest_version(opts)
24+ get_npm_version('astro', opts)
25+ end
26+
27+ private
28+
29+ def parse(response)
30+ if response.url == self.base_url
31+ # root_page is a redirect
32+ 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>'
33+ end
34+ super
35+ end
36+
37+ end
38+end
public/icons/docs/astro/16.png+0−0

Binary file not shown.

public/icons/docs/astro/16@2x.png+0−0

Binary file not shown.

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