Browse Source

Update Next.js documentation (14.2.4)

Simon Legner 1 year ago
parent
commit
524e2e1482

+ 1 - 1
assets/javascripts/news.json

@@ -1,7 +1,7 @@
 [
   [
     "2024-02-20",
-    "New documentation: <a href=\"/nextjs/\">Nextjs</a>"
+    "New documentation: <a href=\"/nextjs/\">Next.js</a>"
   ],
   [
     "2024-01-24",

+ 11 - 0
lib/docs/filters/nextjs/clean_html.rb

@@ -2,6 +2,8 @@ module Docs
     class Nextjs
         class CleanHtmlFilter < Filter
             def call
+                @doc = at_css('.prose')
+
                 css('.zola-anchor').remove
                 doc.prepend_child("<h1>NextJS2</h1>") if root_page?
                 css('div:contains("NEWS:")').remove
@@ -12,6 +14,15 @@ module Docs
                 css('div.feedback_inlineTriggerWrapper__o7yUx').remove
                 css('header').remove #remove links from the top of the page
                 css('nav').remove
+
+                css('h1, h2, h3, h4').each { |node| node.content = node.content }
+
+                css('pre > code').each do |node|
+                  node.parent['data-language'] = 'typescript'
+                  node.parent.content = node.parent.content
+                end
+                css('div[class^="code-block_header"]').remove
+
                 doc
             end
         end

+ 10 - 10
lib/docs/filters/nextjs/entries.rb

@@ -14,25 +14,25 @@ module Docs
       end
 
       def get_type
-        if subpath.include?('/architecture')
+        if slug.start_with?('architecture')
           'Architecture'
-        elsif subpath.include?('/community')
+        elsif slug.start_with?('community')
           'Community'
-        elsif subpath.include?('/getting-started')
+        elsif slug.start_with?('getting-started')
           'Getting Started'
-        elsif subpath.include?('/messages')
+        elsif slug.start_with?('messages')
           'Messages'
-        elsif subpath.include?('/app/building-your-application')
+        elsif slug.start_with?('app/building-your-application')
           'Using App Router: Building your application'
-        elsif subpath.include?('/app/api-reference')
+        elsif slug.start_with?('app/api-reference')
           'Using App Router: api-reference'
-        elsif subpath.include?('/app')
+        elsif slug.start_with?('app')
           'Using App Router'
-        elsif subpath.include?('/pages/building-your-application')
+        elsif slug.start_with?('pages/building-your-application')
           'Using Pages Router: Building your application'
-        elsif subpath.include?('/pages/api-reference')
+        elsif slug.start_with?('pages/api-reference')
           'Using Pages Router: api-reference'
-        elsif subpath.include?('/pages')
+        elsif slug.start_with?('pages')
           'Using Pages Router'
         else
           get_name

+ 9 - 3
lib/docs/scrapers/nextjs.rb

@@ -1,8 +1,9 @@
 module Docs
     class Nextjs < UrlScraper
-        self.name = 'NextJS'
+        self.name = 'Next.js'
+        self.slug = 'nextjs'
         self.type = 'simple'
-        self.release = 'v14.1.0'
+        self.release = '14.2.4'
         self.base_url = 'https://nextjs.org/docs'
         self.initial_paths = %w(reference/)
         self.links = {
@@ -11,10 +12,15 @@ module Docs
         }
 
         html_filters.push 'nextjs/entries', 'nextjs/clean_html'
+        options[:download_images] = false
 
         options[:attribution] = <<-HTML
-          &copy; 2024 Vercel, Inc.
+          &copy; 2024 Vercel, Inc.<br>
           Licensed under the MIT License.
         HTML
+
+      def get_latest_version(opts)
+          get_npm_version('next', opts)
+      end
     end
 end