card-mod-social 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +35 -0
  3. data/set/all/social_meta.rb +92 -0
  4. metadata +61 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3312df5902b40340dc9e170e7d5d48e5b34997bce87231921af24fba4a8748e7
4
+ data.tar.gz: 9400b86935eea5b5f162422dc053aeca9710116bc618a66db0c5b6faffed0fa8
5
+ SHA512:
6
+ metadata.gz: 5a0f309b75cb71ef75227df2dacb3bdb7e2c8eaa1d6fdf78509e6780ca9b75bbae853d541b4538b291b497c0f8b6a0bab106c6bd99c19f0b703afb1ef16d26b6
7
+ data.tar.gz: 3e5731468e345276b37faa7b847b6b29778949c3cb397ecc4ec2018e5eb2252e456b96127da48a82150fc24e0925423d8f40238ba2413ed97dadafa3238e1e43
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ <!--
2
+ # @title README - mod: social
3
+ -->
4
+
5
+ # Social mod
6
+
7
+ This mod adds Twitter and OpenGraph meta tags to decko cards.
8
+
9
+ ## Tags shared by both
10
+
11
+ Both OpenGraph and Twitter support `description` and `image` fields.
12
+
13
+ - The __description__ is handled by the `#social_description` method, which can be
14
+ overwritten in any set. By default it renders the `:text_without_nests` view (in the
15
+ Text format) of the `+:description` card (which itself can be overwrtten using
16
+ the `#social_description_card` method.
17
+ - The __image__ is handled by the `#social_image` method, which can be overwritten in any
18
+ set. By default it renders the `:source` view of the `+:image` card (which itself can be
19
+ overwrtten using the `#social_image_card` method.
20
+
21
+ If you want different content for the two, you can override `#og_description`,
22
+ `#og_image`, `#twitter_description`, and/or `#twitter_image`.
23
+
24
+ ## Open Graph tags
25
+
26
+ The following additional OpenGraph meta tags are also generated (and overridable):
27
+
28
+ - __#og_url__: by default the card's url with no extension
29
+ - __#og_site_name__: by default the content of the `:title` card
30
+ - __#og_type__: defaults to "article"
31
+ - __#og_title__: defaults to the card name
32
+
33
+ ## Twitter tags
34
+
35
+ This mod also adds an overridable __#twitter_card__ meta tag that defaults to "summary".
@@ -0,0 +1,92 @@
1
+ format :text do
2
+ def text_description
3
+ truncate render_text_without_nests.strip, length: 200, separator: " "
4
+ end
5
+ end
6
+
7
+ format :html do
8
+ def views_in_head
9
+ super << :social_meta_tags
10
+ end
11
+
12
+ view :social_meta_tags do
13
+ return unless card.known?
14
+
15
+ shared = %w[title description image]
16
+ meta_tags_for(:og, shared + %w[url site_name type]) +
17
+ meta_tags_for(:twitter, shared + %w[card site creator])
18
+ end
19
+
20
+ # OPEN GRAPH
21
+
22
+ def og_url
23
+ card_url card.name.url_key
24
+ end
25
+
26
+ def og_site_name
27
+ Card[:title]&.content
28
+ end
29
+
30
+ def og_type
31
+ "article"
32
+ end
33
+
34
+ def og_title
35
+ card.name
36
+ end
37
+
38
+ def og_description
39
+ social_description
40
+ end
41
+
42
+ def og_image
43
+ social_image
44
+ end
45
+
46
+ # TWITTER CARDS
47
+
48
+ def twitter_card
49
+ "summary"
50
+ end
51
+
52
+ def twitter_description
53
+ social_description
54
+ end
55
+
56
+ def twitter_image
57
+ social_image
58
+ end
59
+
60
+ # SHARED
61
+
62
+ # NOTE: not cache safe
63
+ def social_description
64
+ @social_description ||= social_description_card&.format(:text)&.text_description
65
+ end
66
+
67
+ # NOTE: not cache safe
68
+ def social_image
69
+ @social_image ||= social_image_card&.format(:text)&.render_source
70
+ end
71
+
72
+ def social_image_card
73
+ try(:image_card) || card.fetch(:image) || Card[:logo]
74
+ end
75
+
76
+ def social_description_card
77
+ card.fetch(:description) || card
78
+ end
79
+
80
+ private
81
+
82
+ def meta_tags_for prefix, properties
83
+ properties.map do |property|
84
+ next unless (content = try "#{prefix}_#{property}")
85
+ meta_tag "#{prefix}:#{property}", content
86
+ end.compact
87
+ end
88
+
89
+ def meta_tag property, content
90
+ %{<meta name="#{property}" content="#{content}">}
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: card-mod-social
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Philipp Kühl
8
+ - Ethan McCutchen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-10-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: card
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: ''
29
+ email:
30
+ - info@decko.org
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - set/all/social_meta.rb
37
+ homepage: http://decko.org
38
+ licenses:
39
+ - GPL-3.0
40
+ metadata:
41
+ card-mod: social
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '2.5'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.2.28
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Social media markup for decko
61
+ test_files: []