Skip to content
Permalink
Browse files

Support pwa for assets cache

  • Loading branch information...
laozhu committed Jan 1, 2019
1 parent 47cc65d commit 64a98c5b490f20a8a5e4a0f6cfe73e6a4082ac7d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,55 @@
var cacheName = 'hugo-nuo-v1';
var filesToCache = [
'./favicon.ico',
'./manifest.json',
'./styles/main.min.css',
'./scripts/index.min.js',
'./images/avatar.png',
'./images/grey-prism.svg',
'./images/qrcode.jpg',
'./icons/icon-16x16.png',
'./icons/icon-32x32.png',
'./icons/icon-128x128.png',
'./icons/icon-144x144.png',
'./icons/icon-152x152.png',
'./icons/icon-192x192.png',
'./icons/icon-256x256.png',
'./icons/icon-512x512.png',
'https://fonts.googleapis.com/css?family=Lobster',
'https://fonts.gstatic.com/s/lobster/v20/neILzCirqoswsqX9zoKmM4MwWJU.woff2',
'https://at.alicdn.com/t/font_174169_qmgvd10zwbf.woff',
'https://cdn.jsdelivr.net/npm/smooth-scroll@15.0.0/dist/smooth-scroll.min.js',
'https://cdn.jsdelivr.net/npm/medium-zoom@1.0.2/dist/medium-zoom.min.js',
'https://cdn.jsdelivr.net/npm/video.js@7.3.0/dist/video-js.min.css',
'https://cdn.jsdelivr.net/npm/video.js@7.3.0/dist/video.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js?V=2.7.5'
];

self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll(filesToCache);
})
);
});

self.addEventListener('fetch', function (event) {
event.respondWith(
caches.match(event.request).then(function (response) {
if (response) return response;
var request = event.request.clone();
return fetch(request).then(function (httpResponse) {
if (!httpResponse || httpResponse.status !== 200) return httpResponse;
// Update caches
var responseClone = httpResponse.clone();
caches.open(cacheName).then(function (cache) {
cache.put(event.request, responseClone);
});
return httpResponse;
});
})
);
});


@@ -1,11 +1,11 @@
@font-face {
font-family: 'icon'; /* project id 174169 */
font-display: 'swap';
src: url('//at.alicdn.com/t/font_174169_qmgvd10zwbf.eot');
src: url('//at.alicdn.com/t/font_174169_qmgvd10zwbf.eot?#iefix') format('embedded-opentype'),
url('//at.alicdn.com/t/font_174169_qmgvd10zwbf.woff') format('woff'),
url('//at.alicdn.com/t/font_174169_qmgvd10zwbf.ttf') format('truetype'),
url('//at.alicdn.com/t/font_174169_qmgvd10zwbf.svg#iconfont') format('svg');
src: url('https://at.alicdn.com/t/font_174169_qmgvd10zwbf.eot');
src: url('https://at.alicdn.com/t/font_174169_qmgvd10zwbf.eot?#iefix') format('embedded-opentype'),
url('https://at.alicdn.com/t/font_174169_qmgvd10zwbf.woff') format('woff'),
url('https://at.alicdn.com/t/font_174169_qmgvd10zwbf.ttf') format('truetype'),
url('https://at.alicdn.com/t/font_174169_qmgvd10zwbf.svg#iconfont') format('svg');
}

.icon {
@@ -39,12 +39,6 @@ copyright = "© This post is licensed under a Creative Commons Attribution-NonCo
author = "Ritchie Zhu"
bg = "images/grey-prism.svg"
avatar = "images/avatar.jpg"
favicon = "images/favicon.ico"
favicon16 = "images/favicon-16x16.png"
favicon32 = "images/favicon-32x32.png"
iconWindows = "images/tile-image-windows.png"
iconApple = "images/touch-icon-apple.png"
iconAndroid = "images/touch-icon-android.png"
seotitle = "Hugo Blog (SEO Version)"
subtitle = "~ Keep It Simple & Stupid ~"
description = "Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again."
@@ -1,4 +1,5 @@
{{ $script := resources.Get "scripts/index.js" | resources.Minify }}
{{- $script := resources.Get "scripts/index.js" | resources.Minify -}}
{{- $serviceWorker := resources.Get "service-worker.js" -}}

<!-- Site Footer -->
<footer class="site-footer">
@@ -46,13 +47,21 @@
<!-- Main Scripts -->
<script src="{{ $script.RelPermalink }}"></script>

<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('{{ $serviceWorker.RelPermalink }}').then(function() {
console.log('[ServiceWorker] Registered');
});
}
</script>

<!-- Google Analytics -->
{{ if .Site.GoogleAnalytics }}
{{ template "_internal/google_analytics_async.html" . }}
{{ end }}

<!-- Baidu Tongji -->
{{ if isset .Site.Params "baidutongji" }}
{{ with .Site.Params.baidutongji }}
<script>
var _hmt = _hmt || [];
(function() {
@@ -1,14 +1,15 @@
<!-- Site & Page Meta Data -->
{{- $gohugoio := "gohugoio" -}}
{{- $themeColor := "#5fbf5e" -}}
{{- $bg := resources.Get (.Site.Params.bg | default "/images/grey-prism.svg") -}}
{{- $avatar := resources.Get (.Site.Params.avatar | default "/images/avatar.jpg") -}}
{{- $favicon := resources.Get (.Site.Params.favicon | default "/images/favicon.ico") -}}
{{- $favicon16 := resources.Get (.Site.Params.favicon16 | default "/images/favicon-16x16.png") -}}
{{- $favicon32 := resources.Get (.Site.Params.favicon32 | default "/images/favicon-32x32.png") -}}
{{- $iconWindows := resources.Get (.Site.Params.iconWindows | default "/images/tile-image-windows.png") -}}
{{- $iconApple := resources.Get (.Site.Params.iconApple | default "/images/touch-icon-apple.png") -}}
{{- $iconAndroid := resources.Get (.Site.Params.iconAndroid | default "/images/touch-icon-android.png") -}}
{{- $themeColor := "#02b875" -}}
{{- $favicon := "favicon.ico" -}}
{{- $icon16 := "icons/icon-16x16.png" -}}
{{- $icon32 := "icons/icon-32x32.png" -}}
{{- $icon144 := "icons/icon-144x144.png" -}}
{{- $icon152 := "icons/icon-152x152.png" -}}
{{- $icon192 := "icons/icon-192x192.png" -}}
{{- $manifest := "manifest.json" -}}
{{- $bg := resources.Get (.Site.Params.bg | default "images/grey-prism.svg") -}}
{{- $avatar := resources.Get (.Site.Params.avatar | default "images/avatar.png") -}}
{{- $style := resources.Get "styles/main.scss" | resources.ToCSS | resources.Minify -}}

<!-- DNS Prefetch -->
@@ -98,18 +99,20 @@
{{ with .Site.Params.sositeverification }}<meta name="360-site-verification" content="{{ . }}">{{ end }}

<!-- Favicon and Touch icons -->
<meta name="theme-color" content="{{ $themeColor }}">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="{{ .Site.Title }}">
<meta name="msapplication-tooltip" content="{{ .Site.Title }}">
<meta name='msapplication-navbutton-color' content="{{ $themeColor }}">
<meta name="msapplication-TileColor" content="{{ $themeColor }}">
<meta name="msapplication-TileImage" content="{{ $iconWindows.RelPermalink }}">
<link rel="icon" href="{{ $favicon.RelPermalink }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ $favicon16.RelPermalink }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ $favicon32.RelPermalink }}">
<link rel="icon" sizes="192x192" href="{{ $iconAndroid.RelPermalink }}">
<link rel="apple-touch-icon" href="{{ $iconApple.RelPermalink }}">
<meta name="msapplication-TileImage" content="{{ $icon144 | relURL }}">
<link rel="icon" href="{{ $favicon | relURL }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ $icon16 | relURL }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ $icon32 | relURL }}">
<link rel="icon" sizes="192x192" href="{{ $icon192 | relURL }}">
<link rel="apple-touch-icon" href="{{ $icon152 | relURL }}">
<link rel="manifest" href="{{ $manifest | relURL }}">

<!-- Preload -->
<link rel="preload" href="{{ $style.RelPermalink }}" as="style">
@@ -1,5 +1,6 @@
{{- $wechat := resources.Get (.Site.Params.wechat | default "/images/qrcode.jpg") -}}
{{- $avatar := resources.Get (.Site.Params.avatar | default "/images/avatar.jpg") -}}
{{- $wechat := resources.Get (.Site.Params.wechat | default "images/qrcode.jpg") -}}
{{- $avatar := resources.Get (.Site.Params.avatar | default "images/avatar.png") -}}

<header class="site-header">
<img class="avatar" src="{{ $avatar.RelPermalink }}" alt="Avatar">
{{ if eq .Kind "home" }}
@@ -4,7 +4,7 @@ <h3 class="post-title"><a href="{{ .Permalink }}" class="post-link">{{ .Title }}
<p class="post-meta">@{{ if isset .Params "author" }}{{ .Params.author }}{{ else }}{{ .Site.Params.author }}{{ end }} · {{ .Date.Format "Jan 2, 2006" }} · {{ .ReadingTime }} min read</p>
</header>
{{ if isset .Params "cover" }}
<img class="post-cover" src="{{ .Params.cover }}" alt="{{ .Title }}">
<img class="post-cover" src="{{ .Params.cover }}" alt="{{ .Title }}" lazyload="on">
{{ end }}
<p class="post-summary">{{ .Summary | plainify | htmlUnescape }}</p>
<footer class="post-footer">
@@ -66,7 +66,7 @@
*/}}

{{/* DEFAULTS */}}
{{- $poster := resources.Get (.Site.Params.poster | default "/images/poster.jpg") -}}
{{- $poster := resources.Get (.Site.Params.poster | default "images/poster.jpg") -}}

{{ if .IsNamedParams }}

Large diffs are not rendered by default.

BIN +5.3 KB static/favicon.ico
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,41 @@
{
"name": "Ritchie Pub.",
"short_name": "ritchie",
"display": "standalone",
"orientation": "any",
"start_url": "./?utm_source=homescreen",
"theme_color": "#02b875",
"background_color": "#fafafa",
"icons": [
{
"src": "icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "icons/icon-144x144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/icon-256x256.png",
"sizes": "256x256",
"type": "image/png"
},
{
"src": "icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
File renamed without changes.

0 comments on commit 64a98c5

Please sign in to comment.
You can’t perform that action at this time.