page_structured_data 0.1.6 → 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: 1ae9b454e36210166cdf451555fe65a2ea3bb2f25b64e5cb37fd06c70c067981
4
- data.tar.gz: 84e43ef5f28b1a1d006b0eb1154de023fce87e6c861feba45f4fd765206d668f
3
+ metadata.gz: 58a0137257224be05f4cd4812b8a95e02a52ef8024f9a32a7a35bfdf7d918175
4
+ data.tar.gz: fb4e545f1641f039264ee60e528ed358ca76ed54315580d5880fc9f3facca519
5
5
  SHA512:
6
- metadata.gz: 67cc94556edb321670382bf6216634fc57651d230582ef6f7d5b8d5aa33e1a1940444d4667d25c69e444813a6c13e57ac1232a6f441db49defff84b7fa6d6751
7
- data.tar.gz: a41d5847de2b57430b87772c1e386ac16e20a8feecb7fb06180cc72de13e134d158856257984ae4f32201320c2f657bc5b05c2a1d0b60f4112ac563c7a62569e
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).
@@ -38,10 +38,6 @@ module PageStructuredData
38
38
  output.join
39
39
  end
40
40
 
41
- def default_image_url
42
- PageStructuredData.default_image_url
43
- end
44
-
45
41
  private
46
42
 
47
43
  def base_app_name
@@ -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.6"
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.6
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