mddir 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +20 -3
- data/lib/mddir/fetcher.rb +16 -1
- data/lib/mddir/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e6aac0b080aaf3ec9e7b1c912cfabed017b5379610be25ba5ccf865925b061f7
|
|
4
|
+
data.tar.gz: 7a80416b4d19a80e6de0448877b5f6d9b8ab650ed967ae231579fe808c7cbd69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fcade5ae9ef5dbc11091d817efcdf82bb4a848a9540dac5f9e919afc95b8ccd46b0b96106872af66d0490f9180fa9e4c699ba51cbe5fbe100d1e59689774f78e
|
|
7
|
+
data.tar.gz: ae7f69a7861fb375b45aa7abf64ae781429121cc49053c37cc5d943be02af1765118ed7f4043292b40f813fe34bc18af203370336ee83ffcf6fba2dd1dbf9b9a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -17,15 +17,32 @@ mddir fetches web pages, converts them to clean markdown, and organizes them int
|
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
### Homebrew (macOS)
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
|
|
23
|
+
brew install AliOsm/tap/mddir
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Standalone Binary (macOS & Linux)
|
|
27
|
+
|
|
28
|
+
Download the latest binary for your platform from the [GitHub releases page](https://github.com/AliOsm/mddir/releases), then:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# macOS: remove the quarantine flag
|
|
32
|
+
xattr -d com.apple.quarantine mddir
|
|
33
|
+
|
|
34
|
+
chmod +x mddir
|
|
35
|
+
sudo mv mddir /usr/local/bin/
|
|
24
36
|
```
|
|
25
37
|
|
|
26
|
-
|
|
38
|
+
On Linux, skip the `xattr` step.
|
|
39
|
+
|
|
40
|
+
### RubyGems
|
|
41
|
+
|
|
42
|
+
Requires Ruby >= 3.2.0. If you don't have Ruby installed, [mise](https://mise.jdx.dev) is the easiest way to get it:
|
|
27
43
|
|
|
28
44
|
```bash
|
|
45
|
+
mise use --global ruby@3
|
|
29
46
|
gem install mddir
|
|
30
47
|
```
|
|
31
48
|
|
data/lib/mddir/fetcher.rb
CHANGED
|
@@ -128,7 +128,8 @@ module Mddir
|
|
|
128
128
|
def process_html_response(url, response)
|
|
129
129
|
html = normalize_encoding(response.body.to_s, response.headers["content-type"])
|
|
130
130
|
document = Nokogiri::HTML(html)
|
|
131
|
-
|
|
131
|
+
simplify_image_markup(document)
|
|
132
|
+
title, article_html = extract_readable_content(document.to_html, document)
|
|
132
133
|
markdown = html_to_markdown(article_html)
|
|
133
134
|
|
|
134
135
|
Entry.new(
|
|
@@ -142,6 +143,20 @@ module Mddir
|
|
|
142
143
|
)
|
|
143
144
|
end
|
|
144
145
|
|
|
146
|
+
def simplify_image_markup(document)
|
|
147
|
+
document.css("picture").each do |picture|
|
|
148
|
+
img = picture.at("img")
|
|
149
|
+
img ? picture.replace(img) : picture.remove
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
document.css("a").each do |a|
|
|
153
|
+
img = a.at("img")
|
|
154
|
+
next unless img
|
|
155
|
+
|
|
156
|
+
a.replace(img) if a.text.strip.empty?
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
145
160
|
def extract_readable_content(html, document)
|
|
146
161
|
title, article_html = run_readability(html)
|
|
147
162
|
|
data/lib/mddir/version.rb
CHANGED