Skip to content

Commit fd35b90

Browse files
committed
add cacheing
1 parent 63f1b59 commit fd35b90

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

_layouts/default.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
<html xmlns="http://www.w3.org/1999/xhtml"{% if page.vertical-writing %} class="vertical-writing-recommended"{% endif %}>
33
{% include head.html %}
44
<body>
5+
{% renderonceusecache header.html %}
56
{% include header.html %}
7+
{% endrenderonceusecache %}
68
<div class="page-content">
79
<div class="wrapper">
810
{{ content }}
911
</div>
1012
</div>
13+
{% renderonceusecache footer.html %}
1114
{% include footer.html %}
15+
{% endrenderonceusecache %}
1216
</body>
1317
</html>

_plugins/render_once_use_cache.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
module Jekyll
3+
class RenderOnceUseCacheTag < Liquid::Block
4+
@@cache = {}
5+
6+
def initialize(tag_name, text, tokens)
7+
super
8+
@text = text
9+
end
10+
11+
def render(context)
12+
@@cache[@text] = super unless @@cache.include?(@text)
13+
@@cache[@text]
14+
end
15+
end
16+
end
17+
18+
Liquid::Template.register_tag('renderonceusecache', Jekyll::RenderOnceUseCacheTag)
19+

0 commit comments

Comments
 (0)