Skip to content

Commit 5c82069

Browse files
authored
Merge pull request #2308 from freeCodeCamp/man
Add Linux man pages documentation
2 parents bc530da + 99fc2d7 commit 5c82069

File tree

8 files changed

+81
-0
lines changed

8 files changed

+81
-0
lines changed

assets/javascripts/news.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[
2+
[
3+
"2024-08-20",
4+
"New documentation: <a href=\"/man/\">Linux man pages</a>"
5+
],
26
[
37
"2024-07-28",
48
"New documentation: <a href=\"/opengl/\">OpenGL</a>"

docs/file-scrapers.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ $GS = '/usr/local/opt/ghostscript/bin/gs'; # GhostScript
142142
```
143143
</details>
144144

145+
## Man
146+
147+
```sh
148+
wget --recursive --no-parent https://man7.org/linux/man-pages/
149+
mv man7.org/linux/man-pages/ docs/man/
150+
```
151+
145152
## NumPy
146153

147154
```sh

lib/docs/filters/man/clean_html.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Docs
2+
class Man
3+
class CleanHtmlFilter < Filter
4+
def call
5+
css('.page-top').remove
6+
css('.nav-bar').remove
7+
css('.nav-end').remove
8+
css('.sec-table').remove
9+
css('a[href="#top_of_page"]').remove
10+
css('.end-man-text').remove
11+
css('.start-footer').remove
12+
css('.footer').remove
13+
css('.end-footer').remove
14+
css('.statcounter').remove
15+
css('form[action="https://www.google.com/search"]').remove
16+
doc
17+
end
18+
end
19+
end
20+
end

lib/docs/filters/man/entries.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Docs
2+
class Man
3+
class EntriesFilter < Docs::EntriesFilter
4+
5+
@@TYPES = {}
6+
7+
def get_name
8+
return slug.split('/').last.sub(/\.(\d[^.]*)\z/, ' (\1)') if slug.start_with?('man')
9+
at_css('h1').content.sub(' — Linux manual page', '')
10+
end
11+
12+
def get_type
13+
build_types if slug == 'dir_by_project'
14+
@@TYPES[slug] or 'Linux manual page'
15+
end
16+
17+
def build_types
18+
type0 = nil
19+
css('*').each do |node|
20+
if node.name == 'h2'
21+
type0 = node.content
22+
elsif node.name == 'a' and node['href'] and node['href'].start_with?('man') and type0
23+
# name = node.content + node.next_sibling.content
24+
slug0 = node['href'].remove(/\.html\z/)
25+
@@TYPES[slug0] = type0
26+
end
27+
end
28+
end
29+
30+
end
31+
end
32+
end

lib/docs/scrapers/man.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Docs
2+
class Man < FileScraper
3+
self.name = 'Linux man pages'
4+
self.type = 'simple'
5+
self.slug = 'man'
6+
self.base_url = "https://man7.org/linux/man-pages/"
7+
self.initial_paths = %w(dir_by_project.html)
8+
self.links = {
9+
home: 'https://man7.org/linux/man-pages/',
10+
}
11+
html_filters.push 'man/entries', 'man/clean_html'
12+
options[:attribution] = <<-HTML
13+
...
14+
HTML
15+
end
16+
end

public/icons/docs/man/16.png

431 Bytes
Loading
1.22 KB
Loading

public/icons/docs/man/SOURCE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https://mirrors.edge.kernel.org/images/favicon.ico
2+
https://commons.wikimedia.org/wiki/File:Tux.svg CC0

0 commit comments

Comments
 (0)