pagecord-cli 0.3.2 → 0.3.3
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/README.md +4 -0
- data/lib/pagecord_cli/SKILL.md +2 -1
- data/lib/pagecord_cli/image_uploads.rb +21 -6
- data/lib/pagecord_cli/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: 1e49c84bdd83870e36e7d68b218fd211dcae477a6b5b7afca0649785651f7bc2
|
|
4
|
+
data.tar.gz: c0f1f731273d36f8bc9626c5f5f7b3f596b34ca647187140b20afea957c88e42
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97a1e5baf19415337cf2a8d0a97bb888394f3550d2b6ce85f29e7039d1aae9ad58b30a5883f1ce63bcae691211c847eb5a84c6a074f4555cb4cf4f57e35fe812
|
|
7
|
+
data.tar.gz: 54bc9279534fe8ce1210cfa4fb3ce962b273c23ae60654d9e96065372b16bf7211e89868d16fb5cb6a63a07e75563259fe5d9d41acb9ffc1b490528712098c64
|
data/README.md
CHANGED
|
@@ -210,9 +210,13 @@ Action Text attachments:
|
|
|
210
210
|
|
|
211
211
|
```markdown
|
|
212
212
|

|
|
213
|
+

|
|
213
214
|
![[photo.jpg]]
|
|
214
215
|
```
|
|
215
216
|
|
|
217
|
+
The alt text and an optional quoted caption go onto the image. Filenames can
|
|
218
|
+
contain spaces.
|
|
219
|
+
|
|
216
220
|
Supported local image types are JPEG, PNG, GIF, and WebP. External image URLs
|
|
217
221
|
and HTML `<img>` tags are left alone.
|
|
218
222
|
|
data/lib/pagecord_cli/SKILL.md
CHANGED
|
@@ -65,7 +65,8 @@ pagecord draft notes/idea.md # save as a draft
|
|
|
65
65
|
The first run writes a `pagecord_token` into the file's front matter, and later
|
|
66
66
|
runs update that same post. Front matter can set `title`, `slug`, `tags`,
|
|
67
67
|
`published_at`, `canonical_url`, `hidden` and `locale`. Local images written as
|
|
68
|
-
`` are uploaded
|
|
68
|
+
`` are uploaded with their alt text and
|
|
69
|
+
optional caption.
|
|
69
70
|
|
|
70
71
|
## Restyling a blog
|
|
71
72
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "digest"
|
|
4
|
+
require "cgi/escape"
|
|
5
|
+
require "uri"
|
|
4
6
|
|
|
5
7
|
module PagecordCLI
|
|
6
8
|
class ImageUploads
|
|
7
|
-
MARKDOWN_IMAGE = /!\[([^\]]*)\]\(([^)]+)
|
|
9
|
+
MARKDOWN_IMAGE = /!\[([^\]]*)\]\(([^)"]+?)(?:\s+"([^"]*)")?\)/
|
|
8
10
|
OBSIDIAN_IMAGE = /!\[\[([^\]]+)\]\]/
|
|
9
11
|
IMAGE_EXTENSIONS = /\.(jpe?g|png|gif|webp)\z/i
|
|
10
12
|
|
|
@@ -20,8 +22,9 @@ module PagecordCLI
|
|
|
20
22
|
|
|
21
23
|
def process
|
|
22
24
|
with_markdown_images = content.gsub(MARKDOWN_IMAGE) do |match|
|
|
23
|
-
path = Regexp.last_match
|
|
24
|
-
|
|
25
|
+
alt, path, caption = Regexp.last_match.captures
|
|
26
|
+
path = decode_path(path)
|
|
27
|
+
local_path?(path) ? attachment_tag_for(path, alt: alt, caption: caption) : match
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
with_markdown_images.gsub(OBSIDIAN_IMAGE) do |match|
|
|
@@ -32,9 +35,20 @@ module PagecordCLI
|
|
|
32
35
|
|
|
33
36
|
private
|
|
34
37
|
|
|
35
|
-
def attachment_tag_for(path)
|
|
38
|
+
def attachment_tag_for(path, alt: nil, caption: nil)
|
|
36
39
|
sgid = cached_sgid(path) || upload(path)
|
|
37
|
-
%(<action-text-attachment sgid="#{sgid}"></action-text-attachment>)
|
|
40
|
+
%(<action-text-attachment sgid="#{sgid}"#{attribute("alt", alt)}#{attribute("caption", caption)}></action-text-attachment>)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def attribute(name, value)
|
|
44
|
+
%( #{name}="#{CGI.escapeHTML(value)}") unless value.to_s.empty?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# A filename can contain a literal "%", as in 100%.jpg.
|
|
48
|
+
def decode_path(path)
|
|
49
|
+
URI.decode_uri_component(path)
|
|
50
|
+
rescue ArgumentError
|
|
51
|
+
path
|
|
38
52
|
end
|
|
39
53
|
|
|
40
54
|
def cached_sgid(path)
|
|
@@ -74,7 +88,8 @@ module PagecordCLI
|
|
|
74
88
|
end
|
|
75
89
|
|
|
76
90
|
def checksum(path)
|
|
77
|
-
|
|
91
|
+
@checksums ||= {}
|
|
92
|
+
@checksums[path] ||= Digest::SHA256.file(path).hexdigest[0, 16]
|
|
78
93
|
end
|
|
79
94
|
|
|
80
95
|
def filename(path)
|
data/lib/pagecord_cli/version.rb
CHANGED