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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf505ffa08cc845661d677e1b4e5175ed12151719a68bf6e36e74899aca6c735
4
- data.tar.gz: 11c57b10cf54268f70bec8eab14c4daf2ffb3abc3b10183cbe90e6e3a9bb15a5
3
+ metadata.gz: 1e49c84bdd83870e36e7d68b218fd211dcae477a6b5b7afca0649785651f7bc2
4
+ data.tar.gz: c0f1f731273d36f8bc9626c5f5f7b3f596b34ca647187140b20afea957c88e42
5
5
  SHA512:
6
- metadata.gz: 2d6eabb97a9acb6ee7c3f61f7ccc676d7db740b7b2516583218a0902ca8fc5b4950eeb4143b1315e9adce799193f48c72bcfa9d3e625c91130bee6c3df814186
7
- data.tar.gz: 194d199f07c81ef3f6d385179e79222a5dac4b0984a2a470ff5f5ac52f0097992b013f264e443fec601ad1dc37e62ff9566a2bb68bccd82d15a2defc11a5f820
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
  ![Alt text](photo.jpg)
213
+ ![Alt text](my photo.jpg "A caption")
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
 
@@ -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
- `![alt](photo.jpg)` are uploaded.
68
+ `![alt](photo.jpg "Caption")` 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(2)
24
- local_path?(path) ? attachment_tag_for(path) : match
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
- Digest::SHA256.file(path).hexdigest[0, 16]
91
+ @checksums ||= {}
92
+ @checksums[path] ||= Digest::SHA256.file(path).hexdigest[0, 16]
78
93
  end
79
94
 
80
95
  def filename(path)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PagecordCLI
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagecord-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olly Headey