page_structured_data 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c876eb5e9c0b0038fdedc9c6d20830d93d329d6694ed708e7129743c530f1495
4
- data.tar.gz: eced8b242aa8c2459288de2896df762a40e4da7286bda30b524838c33f5c65f3
3
+ metadata.gz: 58a0137257224be05f4cd4812b8a95e02a52ef8024f9a32a7a35bfdf7d918175
4
+ data.tar.gz: fb4e545f1641f039264ee60e528ed358ca76ed54315580d5880fc9f3facca519
5
5
  SHA512:
6
- metadata.gz: c1e6fb70adc060f12755f37e1148203b6db346ae38d1fa114b6b39566fce0cfa29cd1d55740f650bcee56c33d36f7813aada5d1bc83f044cc85af4d2b6207257
7
- data.tar.gz: ed1c65bbbe73bad4e0e0cd6a1dcfdd09be615ad44eaed67ac6beb1f3f03dc953e34ee164cbe1f34452ec891b3c55f8bf0859a106f96df4cc5ece542a7f97279c
6
+ metadata.gz: 72d650e297af061d95bba42ef0760f03c1665897fe33f545cbbf3e29ff2b827d2c900216a4819217504ceb6b2e3b871be2ac670890cfb5f7fb4434e6d33c72ad
7
+ data.tar.gz: ae13d9256f20f5cc6b92e41633a404b226303215be1a459c360289f903f33d59ff22a4d20c4f4e73d52b4f52d79a4b1c9d875d0980216608a20cf8b774c031ca
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # PageStructuredData
2
- Short description and motivation.
3
-
4
- ## Usage
5
- How to use my plugin.
2
+ Use this gem to churn out meta tags for your rails webpages. This also renders meta tags for the following:
3
+ 1. Page `<title>` tag with proper hyphenation when used with breadcrumbs
4
+ 2. Basic `<meta>` tags
5
+ 2. Twitter meta tags
6
+ 3. Open graph meta tags
7
+ 4. Google Schema JSON-LD `<script>` tags
6
8
 
7
9
  ## Installation
8
10
  Add this line to your application's Gemfile:
@@ -21,8 +23,81 @@ Or install it yourself as:
21
23
  $ gem install page_structured_data
22
24
  ```
23
25
 
26
+ ## Usage
27
+
28
+ ### Layouts
29
+
30
+ Add the following in your layout to include the basic meta tags by default
31
+
32
+ ```erbruby
33
+ <%= render 'page_structured_data/meta_tags', page: @page_meta,
34
+ default_image_url: image_url('<path_to_default_image>') %>
35
+ ```
36
+
37
+ Note: This doesn't include csrf or any other security or viewport related meta tags.
38
+
39
+ ### Views
40
+
41
+ In your views, please define the `@page_meta` as follows
42
+
43
+ ```ruby
44
+ <% @page_meta = PageStructuredData::Page.new(title: 'Home', extra_title: "Official Page",
45
+ description: 'Welcome to my Page') %>
46
+ ```
47
+
48
+ The instance variable will be used in the layout to create proper meta tags. Most attributes are self explanatory. `extra_title` is used to append to the title.
49
+
50
+ ### Config
51
+
52
+ Configure the application wide settings as follows:
53
+
54
+ ```erbruby
55
+ # config/initializers/page_structured_data.rb
56
+ Rails.application.config.after_initialize do
57
+ PageStructuredData.config do |config|
58
+ config.base_app_name = 'AwesomestApp' # or use any application constant as this is called after_initialize
59
+ end
60
+ end
61
+ ```
62
+
63
+ ### Breadcrumbs
64
+
65
+ Create a list of breadcrumbs like this:
66
+
67
+ ```erbruby
68
+ <% breadcrumb = PageStructuredData::Breadcrumbs.new(hierarchy: [{ title: 'Resources', href: resources_url }, { title: 'Articles', href: resources_articles_url }]) %>
69
+ ```
70
+
71
+ And include it in the `Page.new` as:
72
+
73
+ ```erbruby
74
+ <% @page_meta = PageStructuredData::Page.new(title: 'Home', extra_title: "Official Page",
75
+ description: 'Welcome to my Page', breadcrumb: breadcrumb) %>
76
+ ```
77
+
78
+ This will create a JSON+LD breadcrumbs similar to [Breadcrumbs](https://developers.google.com/search/docs/appearance/structured-data/breadcrumb)
79
+
80
+ ### PageTypes
81
+
82
+ Currently this gem supports the following page types:
83
+
84
+ * [BlogPosting](https://schema.org/BlogPosting)
85
+ * [NewsArticle](https://schema.org/NewsArticle)
86
+
87
+ To use these, it is similar to breadcrumbs: include them in `Page.new` and it the json+ld will be automatically included.
88
+
89
+ ```erbruby
90
+ <% article_page_type = PageStructuredData::PageTypes::BlogPosting.new(headline: @article.title, published_at: @article.published_at,
91
+ updated_at: @article.updated_at, authors: [name: @article.authors.first.name, url: @article.authors.first.website],
92
+ images: [main_app.url_for(@article.cover_image.variant(:standard))]) %>
93
+ <% @page_meta = PageStructuredData::Page.new(title: 'Home', extra_title: "Official Page",
94
+ description: 'Welcome to my Page', page_type: article_page_type) %>
95
+ ```
96
+
97
+ Just replace BlogPosting class with the other type for other page types.
98
+
24
99
  ## Contributing
25
- Contribution directions go here.
100
+ Please raise a PR to be validated and merged.
26
101
 
27
102
  ## License
28
103
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -44,10 +44,6 @@ module PageStructuredData
44
44
  PageStructuredData.base_app_name
45
45
  end
46
46
 
47
- def default_image_url
48
- PageStructuredData.default_image_url
49
- end
50
-
51
47
  def separator
52
48
  ' - '
53
49
  end
@@ -1,10 +1,8 @@
1
+ - default_image_url = local_assigns[:default_image_url]
2
+
1
3
  - title = page&.page_title
2
4
  - description = page&.description
3
- - image = page&.image
4
- - if page&.image.present?
5
- - image = page.image
6
- - else
7
- - image = page.default_image_url
5
+ - image = page&.image || default_image_url || nil
8
6
 
9
7
  title = title
10
8
 
@@ -1,3 +1,3 @@
1
1
  module PageStructuredData
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -3,7 +3,7 @@ require "page_structured_data/engine"
3
3
 
4
4
  module PageStructuredData
5
5
  class << self
6
- attr_accessor :default_image_url, :base_app_name
6
+ attr_accessor :base_app_name
7
7
 
8
8
  def config
9
9
  yield self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_structured_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jey Geethan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-29 00:00:00.000000000 Z
11
+ date: 2023-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails