Skip to content

Commit 3b7ab4c

Browse files
committed
add yaml frontmatter options
1 parent 9677640 commit 3b7ab4c

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

_config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ repos:
5050

5151
# Style Variables
5252
brand_color: "#2cb34a"
53+
54+
# Offline caching
55+
offline_cache: true
56+
cache_name: DOCter-v1

_layouts/default.html

+9-7
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ <h1 class="site-title"><a class="title-link" href="{{ site.baseurl }}/">{{ site.
4949
</div><!--/.wrap -->
5050
</footer>
5151
</div> <!-- /.container -->
52-
<script>
53-
if('serviceWorker' in navigator) {
54-
navigator.serviceWorker
55-
.register('/sw.js')
56-
.then(function() { console.log('Service Worker Registered'); });
57-
}
58-
</script>
52+
{% if site.offline_cache == true %}
53+
<script>
54+
if('serviceWorker' in navigator) {
55+
navigator.serviceWorker
56+
.register('/sw.js')
57+
.then(function() { console.log('Service Worker Registered'); });
58+
}
59+
</script>
60+
{% endif %}
5961
</body>
6062
</html>

sw.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ layout: null
44

55
importScripts('/cache-polyfill.js');
66

7+
var filesToCache = [
8+
// root
9+
'/',
10+
'/index.html',
11+
// css
12+
'/assets/css/main.css',
13+
'/assets/css/normalize.css',
14+
'/assets/css/syntax.css',
15+
// images
16+
'/assets/img/octocat.png',
17+
// pages
18+
'/example_page/',
19+
// posts
20+
{% for post in site.posts %}'{{ post.url }}',{% endfor %}
21+
];
22+
723
self.addEventListener('install', function(e) {
824
e.waitUntil(
9-
caches.open('DOCter').then(function(cache) {
10-
return cache.addAll([
11-
// root
12-
'/',
13-
'/index.html',
14-
// css
15-
'/assets/css/main.css',
16-
'/assets/css/normalize.css',
17-
'/assets/css/syntax.css',
18-
// images
19-
'/assets/img/octocat.png',
20-
// pages
21-
'/example_page/',
22-
// posts
23-
{% for post in site.posts %}'{{ post.url }}',{% endfor %}
24-
]);
25+
caches.open('{{ site.cache_name }}').then(function(cache) {
26+
return cache.addAll(filesToCache);
2527
})
2628
);
2729
});

0 commit comments

Comments
 (0)