jekyll-metrics 1.0.0
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/lib/jekyll-metrics.rb +15 -0
- data/lib/jekyll-metrics/config.rb +68 -0
- data/lib/jekyll-metrics/hook.rb +46 -0
- data/lib/jekyll-metrics/includes/metrics.html.liquid +25 -0
- data/lib/jekyll-metrics/version.rb +5 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cca79edf5493463c41e66e3880cd3f10014c85a22bc6f9297bcca43c0b0553cc
|
4
|
+
data.tar.gz: e1700fae8cd2fbd2294d552e5a8327a3b90f97eaed5de354191e4c2c8b071015
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e64fa202273407eed86e0ad177dc6f38a60d02490bdc2dd6cc3eac8ef71c0e4c1eb9892c1470fb054a6a3267d72e886eddfd683ee6f4882db2ee4411a2b44a3
|
7
|
+
data.tar.gz: 93ca011990065383140c1ac3188af678627ca962e9c85de485972c50b3c9978cbd292d93375e326c5a5a689c1f8e22f4aa9a3b678834321c4cc70662725da8e8
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Ivan Zinovyev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# JekyllMetrics
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jekyll-metrics`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'jekyll-metrics'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install jekyll-metrics
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll-metrics. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/jekyll-metrics/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the JekyllMetrics project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/jekyll-metrics/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jekyll'
|
4
|
+
require File.expand_path('jekyll-metrics/version', __dir__)
|
5
|
+
require File.expand_path('jekyll-metrics/config', __dir__)
|
6
|
+
require File.expand_path('jekyll-metrics/hook', __dir__)
|
7
|
+
|
8
|
+
module JekyllMetrics
|
9
|
+
class ConfigurationError < StandardError; end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Register the hook
|
13
|
+
Jekyll::Hooks.register [:documents, :pages], :post_render do |page|
|
14
|
+
JekyllMetrics::Hook.new(page) { |_page, metrics| metrics.inject_scripts }
|
15
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module JekyllMetrics
|
2
|
+
# Hold the configuration needed for {JekyllMetrics::Hook} to work
|
3
|
+
class Config
|
4
|
+
CONFIG_NAME = 'jekyll_metrics'.freeze
|
5
|
+
DEFAULT_TEMPLATE_PATH = 'lib/jekyll-metrics/includes/metrics.html.liquid'.freeze
|
6
|
+
DEFAULT_CONFIG = {
|
7
|
+
'template' => DEFAULT_TEMPLATE_PATH,
|
8
|
+
'yandex_metrica_id' => 'XXXXXXXX',
|
9
|
+
'google_analytics_id' => 'XX-XXXXXXXXX-X'
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def instance(site)
|
14
|
+
@instance ||= Config.new(site)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_accessor :site
|
19
|
+
|
20
|
+
def initialize(site)
|
21
|
+
@site = site
|
22
|
+
end
|
23
|
+
|
24
|
+
def template_path
|
25
|
+
@template_path ||= build_template_path
|
26
|
+
end
|
27
|
+
|
28
|
+
def plugin_vars
|
29
|
+
@plugin_vars ||= DEFAULT_CONFIG.merge(plugin_config)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def build_template_path
|
35
|
+
custom_path = plugin_config['template']
|
36
|
+
|
37
|
+
return default_template_path if custom_path.nil?
|
38
|
+
|
39
|
+
if custom_path.match?(%r{^\/})
|
40
|
+
Pathname.new(custom_path)
|
41
|
+
else
|
42
|
+
site_root_path.join(custom_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def default_template_path
|
47
|
+
plugin_root_path.join(DEFAULT_TEMPLATE_PATH)
|
48
|
+
end
|
49
|
+
|
50
|
+
def plugin_root_path
|
51
|
+
Pathname.new(File.expand_path('../..', __dir__))
|
52
|
+
end
|
53
|
+
|
54
|
+
def site_root_path
|
55
|
+
raise ConfigurationError, 'Couldn\'t access site.source' unless site.source
|
56
|
+
|
57
|
+
Pathname.new(site.source)
|
58
|
+
end
|
59
|
+
|
60
|
+
def plugin_config
|
61
|
+
@plugin_config ||= site_config[CONFIG_NAME].to_h.transform_keys(&:to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def site_config
|
65
|
+
site.config
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module JekyllMetrics
|
2
|
+
# Compile metrics template and inject it into the page code
|
3
|
+
class Hook
|
4
|
+
attr_accessor :page
|
5
|
+
|
6
|
+
def initialize(page)
|
7
|
+
@page = page
|
8
|
+
yield(@page, self) if block_given? && injectable?
|
9
|
+
end
|
10
|
+
|
11
|
+
def injectable?
|
12
|
+
['Jekyll::Document', 'Jekyll::Page'].include?(page.class.name) || page.write? &&
|
13
|
+
(page.output_ext == '.html' || page.permalink&.end_with?('/'))
|
14
|
+
end
|
15
|
+
|
16
|
+
def inject_scripts
|
17
|
+
page.output.gsub!(%r{<\/head>}, load_scripts)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def prepare_scripts_for(closing_tag)
|
23
|
+
[load_scripts, "</#{closing_tag}>"].compact.join("\n")
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_scripts
|
27
|
+
verify_path!(config.template_path)
|
28
|
+
|
29
|
+
render_template(File.read(config.template_path))
|
30
|
+
end
|
31
|
+
|
32
|
+
def verify_path!(path)
|
33
|
+
return if path && File.exist?(path)
|
34
|
+
|
35
|
+
raise ConfigurationError, "Template not found in path \"#{path}\""
|
36
|
+
end
|
37
|
+
|
38
|
+
def render_template(file)
|
39
|
+
Liquid::Template.parse(file).render(config.plugin_vars)
|
40
|
+
end
|
41
|
+
|
42
|
+
def config
|
43
|
+
@config ||= Config.instance(page.site)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!-- Global site tag (gtag.js) - Google Analytics -->
|
2
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ google_analytics_id }}"></script>
|
3
|
+
<script>
|
4
|
+
window.dataLayer = window.dataLayer || [];
|
5
|
+
function gtag(){dataLayer.push(arguments);}
|
6
|
+
gtag('js', new Date());
|
7
|
+
|
8
|
+
gtag('config', '{{ google_analytics_id }}');
|
9
|
+
</script>
|
10
|
+
<!-- End Global site tag (gtag.js) - Google Analytics -->
|
11
|
+
|
12
|
+
<!-- Yandex.Metrika counter -->
|
13
|
+
<script type="text/javascript" >
|
14
|
+
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
15
|
+
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
|
16
|
+
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
|
17
|
+
|
18
|
+
ym({{ yandex_metrica_id }}, "init", {
|
19
|
+
clickmap:true,
|
20
|
+
trackLinks:true,
|
21
|
+
accurateTrackBounce:true
|
22
|
+
});
|
23
|
+
</script>
|
24
|
+
<noscript><div><img src="https://mc.yandex.ru/watch/{{ yandex_metrica_id }}" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
25
|
+
<!-- /Yandex.Metrika counter -->
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Zinovyev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.7'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.7'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: Metrics plugin for Jekyll. Supports Yandex Metrics and Google Analytics
|
76
|
+
out of the box.
|
77
|
+
email:
|
78
|
+
- ivan@zinovyev.net
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files:
|
82
|
+
- README.md
|
83
|
+
- LICENSE.txt
|
84
|
+
files:
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- lib/jekyll-metrics.rb
|
88
|
+
- lib/jekyll-metrics/config.rb
|
89
|
+
- lib/jekyll-metrics/hook.rb
|
90
|
+
- lib/jekyll-metrics/includes/metrics.html.liquid
|
91
|
+
- lib/jekyll-metrics/version.rb
|
92
|
+
homepage: https://github.com/zinovyev/jekyll-metrics
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata:
|
96
|
+
homepage_uri: https://github.com/zinovyev/jekyll-metrics
|
97
|
+
source_code_uri: https://github.com/zinovyev/jekyll-metrics
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 2.3.0
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubygems_version: 3.0.3
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Metrics plugin for Jekyll
|
117
|
+
test_files: []
|