Browse Source

Merge pull request #2308 from freeCodeCamp/man

Add Linux man pages documentation
Simon Legner 1 year ago
parent
commit
5c82069d89

+ 4 - 0
assets/javascripts/news.json

@@ -1,4 +1,8 @@
 [
+  [
+    "2024-08-20",
+    "New documentation: <a href=\"/man/\">Linux man pages</a>"
+  ],
   [
     "2024-07-28",
     "New documentation: <a href=\"/opengl/\">OpenGL</a>"

+ 7 - 0
docs/file-scrapers.md

@@ -142,6 +142,13 @@ $GS = '/usr/local/opt/ghostscript/bin/gs';	# GhostScript
 ```
 </details>
 
+## Man
+
+```sh
+wget --recursive --no-parent https://man7.org/linux/man-pages/
+mv man7.org/linux/man-pages/ docs/man/
+```
+
 ## NumPy
 
 ```sh

+ 20 - 0
lib/docs/filters/man/clean_html.rb

@@ -0,0 +1,20 @@
+module Docs
+  class Man
+    class CleanHtmlFilter < Filter
+      def call
+        css('.page-top').remove
+        css('.nav-bar').remove
+        css('.nav-end').remove
+        css('.sec-table').remove
+        css('a[href="#top_of_page"]').remove
+        css('.end-man-text').remove
+        css('.start-footer').remove
+        css('.footer').remove
+        css('.end-footer').remove
+        css('.statcounter').remove
+        css('form[action="https://www.google.com/search"]').remove
+        doc
+      end
+    end
+  end
+end

+ 32 - 0
lib/docs/filters/man/entries.rb

@@ -0,0 +1,32 @@
+module Docs
+  class Man
+    class EntriesFilter < Docs::EntriesFilter
+
+      @@TYPES = {}
+
+      def get_name
+        return slug.split('/').last.sub(/\.(\d[^.]*)\z/, ' (\1)') if slug.start_with?('man')
+        at_css('h1').content.sub(' — Linux manual page', '')
+      end
+
+      def get_type
+        build_types if slug == 'dir_by_project'
+        @@TYPES[slug] or 'Linux manual page'
+      end
+
+      def build_types
+        type0 = nil
+        css('*').each do |node|
+          if node.name == 'h2'
+            type0 = node.content
+          elsif node.name == 'a' and node['href'] and node['href'].start_with?('man') and type0
+            # name = node.content + node.next_sibling.content
+            slug0 = node['href'].remove(/\.html\z/)
+            @@TYPES[slug0] = type0
+          end
+        end
+      end
+
+    end
+  end
+end

+ 16 - 0
lib/docs/scrapers/man.rb

@@ -0,0 +1,16 @@
+module Docs
+  class Man < FileScraper
+    self.name = 'Linux man pages'
+    self.type = 'simple'
+    self.slug = 'man'
+	  self.base_url = "https://man7.org/linux/man-pages/"
+	  self.initial_paths = %w(dir_by_project.html)
+    self.links = {
+      home: 'https://man7.org/linux/man-pages/',
+    }
+    html_filters.push 'man/entries', 'man/clean_html'
+    options[:attribution] = <<-HTML
+	  ...
+    HTML
+  end
+end

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


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


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

@@ -0,0 +1,2 @@
+https://mirrors.edge.kernel.org/images/favicon.ico
+https://commons.wikimedia.org/wiki/File:Tux.svg CC0