pagelet 0.3.1 → 0.3.2

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: bf94b55e95f3a82e9881062290de64f1c9127133a42d7b1d61c9fcddb1920c7b
4
- data.tar.gz: ea93676c77356f8bb724b0b12128b075f889c67c67c0f7e2b94b81b00fdc7599
3
+ metadata.gz: 6b24445c01c1bc889ce68225c48b303acc16e65dfe7d34456a4fb4f9e422ec5d
4
+ data.tar.gz: 86ed741b1c1d002e3c676e8fec1a7bd2081f2dec1357a42c4ac4e573834e4767
5
5
  SHA512:
6
- metadata.gz: 41bb248a705841c72ba3d42b03b50ce7fed7b94b5b545718d12c6533f503010fdf03ff9e23ce7d8152890949d361f20fae283a904761c828861be91f08994b78
7
- data.tar.gz: 0da9ec0fd1b4d7a7d721dfabcef5db92eedcc0020cb76f25181bf6600c5af6dd05fc7e2d79835a38ddfaee7327f366db71e9323604b32db56beb45c6ed1f6905
6
+ metadata.gz: 48c0afe5bbebb784cf792929ed8f752ea264e0d01d33f6c222a6e13ae3158507931da2afff87b80decf5cb33fe6aaa874ee63cfe90faf541171a9d9e6d5851b5
7
+ data.tar.gz: ecadc74a98431b7820304eb2db5b4c4d5f8a334c76539b48b26faec338b707597e6047c326ed5ade7cb1020d2685924029dd511d4b037df57eb5b54a5b96d044
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.2 (2026-11-15)
4
+
5
+ - **Page description.** A "Description (search results)" setting on every
6
+ page, beside "Page title (browser tab)".
7
+ - **`Pagelet::PageSeo.for(owner, path)`** returns a published page's
8
+ `{ "title", "description" }` for search results and the browser tab. A
9
+ blank description falls back to the start of the page's first text
10
+ (headings skipped), trimmed to about 160 characters. nil for a sub-path a
11
+ page answers for, which is a different page to a search engine.
12
+ - **`pageSettings(document)`** (npm) returns `description` too, for apps that
13
+ set the title and meta description in the browser.
14
+ - Dev: puma 8.1 (bundler-audit advisories against 8.0.2).
15
+
3
16
  ## 0.3.1 (2026-11-13)
4
17
 
5
18
  - **Unpublished changes.** Page summaries (the page list, the AI tools) include
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pagelet
4
+ # A published page's title and description, for search results and the
5
+ # browser tab -- read from the page itself, so a page an admin adds or renames
6
+ # needs no hand-kept list.
7
+ #
8
+ # Pagelet::PageSeo.for(owner, "/mission")
9
+ # # => { "title" => "Mission", "description" => "Our mission at ..." }
10
+ #
11
+ # The title is the page's "Page title (browser tab)" setting. The description
12
+ # is its "Description (search results)" setting, or, left blank, the start of
13
+ # the first text on the page. nil when no page is published at exactly this
14
+ # path: a sub-path a page answers for (a sermon under /messages) is a
15
+ # different page to a search engine and must not borrow this one's title.
16
+ module PageSeo
17
+ DESCRIPTION_LENGTH = 160
18
+ # Block props that hold a page's prose, in the order a reader meets them.
19
+ TEXT_PROPS = %w[text subheading body answer].freeze
20
+ # A heading names the page; it is not a description of it.
21
+ NOT_PROSE = %w[Heading].freeze
22
+
23
+ def self.for(owner, path)
24
+ match = Page.published_match(owner, path)
25
+ return nil unless match && match.rest.to_s.empty?
26
+
27
+ seo = { "title" => setting(match.document, "title"),
28
+ "description" => setting(match.document, "description") || excerpt(match.document) }
29
+ seo.compact.presence
30
+ end
31
+
32
+ def self.setting(document, key)
33
+ document.dig("data", "root", "props", key).to_s.strip.presence
34
+ end
35
+
36
+ def self.excerpt(document)
37
+ text = first_text(document.dig("data", "content"))
38
+ text && truncate(text.gsub(/\s+/, " ").strip)
39
+ end
40
+
41
+ # Depth first through blocks and their slots (Columns, Section), so the
42
+ # first text is the first a reader sees.
43
+ def self.first_text(items)
44
+ Array(items).each do |item|
45
+ found = own_text(item) || first_text(slots(item))
46
+ return found if found
47
+ end
48
+ nil
49
+ end
50
+
51
+ def self.own_text(item)
52
+ return nil if !item.is_a?(Hash) || NOT_PROSE.include?(item["type"])
53
+
54
+ props = item["props"].is_a?(Hash) ? item["props"] : {}
55
+ TEXT_PROPS.map { |key| props[key] }.find { |value| value.is_a?(String) && value.strip.present? }
56
+ end
57
+
58
+ # A block's slots hold its child blocks: every array of blocks in its props.
59
+ def self.slots(item)
60
+ props = item.is_a?(Hash) && item["props"].is_a?(Hash) ? item["props"] : {}
61
+ props.values.grep(Array).flatten(1)
62
+ end
63
+
64
+ def self.truncate(text)
65
+ return text if text.length <= DESCRIPTION_LENGTH
66
+
67
+ cut = text[0, DESCRIPTION_LENGTH - 1]
68
+ cut = cut[0, cut.rindex(" ")] if cut.include?(" ")
69
+ "#{cut.rstrip}…"
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagelet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Gibson
@@ -45,6 +45,7 @@ files:
45
45
  - app/models/pagelet/catalog/field_checks.rb
46
46
  - app/models/pagelet/document_check.rb
47
47
  - app/models/pagelet/page.rb
48
+ - app/models/pagelet/page_seo.rb
48
49
  - app/models/pagelet/page_version.rb
49
50
  - app/models/pagelet/site.rb
50
51
  - app/models/pagelet/site_check.rb