jekyll-animate-elements 0.0.1 → 0.0.3
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 +4 -4
- data/lib/jekyll-animate-elements/version.rb +7 -0
- data/lib/jekyll-animate-elements.rb +66 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0ea6ea98445c9c4cd06d36fa48ad8d2ddb6318700c89e2e3491f18333dc29d5
|
4
|
+
data.tar.gz: bfe5a32ebe7b9f95ea6cccb86899699737ca82b04f25b0ce1d4c2cf0bff2c49d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d917790a190248a6c03c1d594471eb99d825bd61f666ac4a3a2522618a940bc50a053ba4843029bc78fb43400a4f3e5e6da73bd52cd8d01f39c6bc47d6e69e5
|
7
|
+
data.tar.gz: 36d03d4e21891c13375382d5e9d1b43d5243339b1480586a04629c9c3e5c0e2f9da7529f318f2e42e2fcb196924e45527e62f4c3bb5a21883419a737ae960a90
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# based on the excellent post by Anthony Fu: https://antfu.me/posts/sliding-enter-animation
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'jekyll'
|
5
|
+
require "nokogiri"
|
6
|
+
|
7
|
+
Jekyll::Hooks.register([:pages, :documents], :post_render) do |page|
|
8
|
+
if page.site.config.key?("animation") and page.site.config["animation"].key?("enabled") and page.site.config["animation"]["enabled"]
|
9
|
+
config = page.site.config["animation"]
|
10
|
+
verbose = config["verbose"] || false
|
11
|
+
|
12
|
+
if page.path.end_with?(".html", ".md")
|
13
|
+
# add animation to html elements as style attribute
|
14
|
+
noko = Nokogiri::HTML(page.output)
|
15
|
+
|
16
|
+
# set default values
|
17
|
+
limit = config["max_elements"] || 20
|
18
|
+
selector = config["selector"] ||
|
19
|
+
"audio, blockquote, div.card, div.highlighter-rouge, div.news, div.repositories, div.row, div.social, div.tag-category-list, figure, h2, h3, ol, p, tr, ul, video"
|
20
|
+
|
21
|
+
noko.search(selector).each_with_index do |tag, index|
|
22
|
+
tag[:style] = (tag[:style] || "") + "--stagger: #{index+1};"
|
23
|
+
tag["data-animate"] = ""
|
24
|
+
if index == limit then
|
25
|
+
break
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
page.output = noko.to_html
|
30
|
+
if verbose
|
31
|
+
Jekyll.logger.info "Added animation to page #{page.path}"
|
32
|
+
end
|
33
|
+
|
34
|
+
elsif page.path.end_with?(".scss")
|
35
|
+
# add animation config to css file
|
36
|
+
# set default values
|
37
|
+
delay = config["delay"] || "100ms"
|
38
|
+
duration = config["duration"] || "0.6s"
|
39
|
+
name = config["name"] || "enter"
|
40
|
+
|
41
|
+
from = config["from"] || "opacity:0;transform:translateY(10px)"
|
42
|
+
# transform value to string, if it is a hash
|
43
|
+
if from.is_a?(Hash)
|
44
|
+
from = from.map { |k, v| "#{k}:#{v}" }.join(";")
|
45
|
+
end
|
46
|
+
|
47
|
+
to = config["to"] || "opacity:1;transform:none"
|
48
|
+
# transform value to string, if it is a hash
|
49
|
+
if to.is_a?(Hash)
|
50
|
+
to = to.map { |k, v| "#{k}:#{v}" }.join(";")
|
51
|
+
end
|
52
|
+
|
53
|
+
css = page.output
|
54
|
+
css += "@keyframes #{name}{from{#{from}}to{#{to}}}[data-animate]{--stagger:0;--delay:#{delay};--start:0.1ms}
|
55
|
+
@media(prefers-reduced-motion:no-preference){[data-animate]{animation:#{name} #{duration} both;animation-delay: calc(var(--stagger) * var(--delay) + var(--start))}}"
|
56
|
+
page.output = css
|
57
|
+
|
58
|
+
if verbose
|
59
|
+
Jekyll.logger.info "Added animation to css file #{page.path}"
|
60
|
+
end
|
61
|
+
|
62
|
+
elsif verbose
|
63
|
+
Jekyll.logger.info "Skipped adding animation to file #{page.path}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-animate-elements
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Corrêa de Araújo
|
@@ -64,7 +64,9 @@ email:
|
|
64
64
|
executables: []
|
65
65
|
extensions: []
|
66
66
|
extra_rdoc_files: []
|
67
|
-
files:
|
67
|
+
files:
|
68
|
+
- lib/jekyll-animate-elements.rb
|
69
|
+
- lib/jekyll-animate-elements/version.rb
|
68
70
|
homepage: https://github.com/george-gca/jekyll-animate-elements
|
69
71
|
licenses:
|
70
72
|
- MIT
|