Skip to content

Commit e78e206

Browse files
committed
- Added the metadata files for deployment that tw can not generate
- Generate plugin library and favicon during build
1 parent 9b48745 commit e78e206

11 files changed

+175
-3
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
output/
22
node_modules
33
.history
4-
debug.log
4+
debug.log
5+
.DS_STORE

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ before_script:
1212
- cd noteself
1313
- "git checkout develop"
1414
script:
15-
- tiddlywiki ./wiki --verbose --build index --build OnlineDemo
15+
- tiddlywiki ./wiki --verbose --build index --build OnlineDemo --build favicon --build library
16+
- cp -R wiki/output ../dist
1617
deploy:
1718
provider: pages
1819
skip_cleanup: true
19-
local_dir: wiki/output
20+
local_dir: ../dist
2021
target_branch: master
2122
github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard
2223
on:

dist/online/icons/icon-32.png

1.25 KB
Loading
1.34 KB
Loading
2.99 KB
Loading
1.87 KB
Loading
3.9 KB
Loading
5.9 KB
Loading
8.62 KB
Loading

dist/online/manifest.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "NoteSelf",
3+
"short_name": "NoteSelf",
4+
"description": "The personal wiki that syncs",
5+
"lang": "en",
6+
"start_url": "/online",
7+
"scope": "/online",
8+
"display": "standalone",
9+
"theme_color": "#93cf93",
10+
"orientation": "portrait",
11+
"icons": [
12+
{
13+
"src": "icons/launcher-icon-0-75x.png",
14+
"sizes": "36x36",
15+
"type": "image/png",
16+
"density": 0.75
17+
},
18+
{
19+
"src": "icons/launcher-icon-1x.png",
20+
"sizes": "48x48",
21+
"type": "image/png",
22+
"density": 1.0
23+
},
24+
{
25+
"src": "icons/launcher-icon-1-5x.png",
26+
"sizes": "72x72",
27+
"type": "image/png",
28+
"density": 1.5
29+
},
30+
{
31+
"src": "icons/launcher-icon-2x.png",
32+
"sizes": "96x96",
33+
"type": "image/png",
34+
"density": 2.0
35+
},
36+
{
37+
"src": "icons/launcher-icon-3x.png",
38+
"sizes": "144x144",
39+
"type": "image/png",
40+
"density": 3.0
41+
},
42+
{
43+
"src": "icons/launcher-icon-4x.png",
44+
"sizes": "192x192",
45+
"type": "image/png",
46+
"density": 4.0
47+
}
48+
]
49+
}

dist/online/sw.js

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
var cdn = {
2+
max: 'https://maxcdn.bootstrapcdn.com'
3+
}
4+
5+
var vendor = {
6+
fontAwesome: 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3'
7+
};
8+
9+
var URLS = {
10+
app: [
11+
'icons/launcher-icon-0-75x.png',
12+
'icons/launcher-icon-1-5x.png',
13+
'icons/launcher-icon-1x.png',
14+
'icons/launcher-icon-2x.png',
15+
'icons/launcher-icon-3x.png',
16+
'icons/launcher-icon-4x.png',
17+
'icons/icon-32.png',
18+
'index.html',
19+
'manifest.json'
20+
],
21+
vendor: [
22+
`${vendor.fontAwesome}/css/font-awesome.min.css`,
23+
`${vendor.fontAwesome}/fonts/fontawesome-webfont.woff2`, // browsers that support sw support woff2
24+
]
25+
}
26+
27+
var CACHE_NAMES = {
28+
app: 'noteself-cache-v7',
29+
vendor: 'vendor-cache-v7'
30+
};
31+
32+
function isVendor(url) {
33+
return url.startsWith(cdn.max);
34+
}
35+
36+
function cacheAll(cacheName, urls) {
37+
return caches.open(cacheName).then((cache) => cache.addAll(urls));
38+
}
39+
40+
function addToCache(cacheName, request, response) {
41+
if (response.ok) {
42+
var clone = response.clone()
43+
caches.open(cacheName).then((cache) => cache.put(request, clone));
44+
}
45+
return response;
46+
}
47+
48+
function lookupCache(request) {
49+
return caches.match(request).then(function(cachedResponse) {
50+
if (!cachedResponse) {
51+
throw Error(`${request.url} not found in cache`);
52+
}
53+
return cachedResponse;
54+
});
55+
}
56+
57+
function fetchThenCache(request, cacheName) {
58+
var fetchRequest = fetch(request);
59+
// add to cache, but don't block resolve of this promise on caching
60+
fetchRequest.then((response) => addToCache(cacheName, request, response));
61+
return fetchRequest;
62+
}
63+
64+
function raceRequest(request, cacheName) {
65+
var attempts = [
66+
fetchThenCache(request, cacheName),
67+
lookupCache(request)
68+
];
69+
return new Promise(function(resolve, reject) {
70+
// resolve this promise once one resolves
71+
attempts.forEach((attempt) => attempt.then(resolve));
72+
// reject if all promises reject
73+
attempts.reduce((verdict, attempt) => verdict.catch(() => attempt))
74+
.catch(() => reject(Error('Unable to resolve request from network or cache.')));
75+
})
76+
}
77+
78+
function cleanupCache() {
79+
var validKeys = Object.keys(CACHE_NAMES).map((key) => CACHE_NAMES[key]);
80+
return caches.keys().then((localKeys) => Promise.all(
81+
localKeys.map((key) => {
82+
if (validKeys.indexOf(key) === -1) { // key no longer in our list
83+
return caches.delete(key);
84+
}
85+
})
86+
));
87+
}
88+
89+
self.addEventListener('install', function(evt) {
90+
var cachingCompleted = Promise.all([
91+
cacheAll(CACHE_NAMES.app, URLS.app),
92+
//cacheAll(CACHE_NAMES.vendor, URLS.vendor)
93+
]).then(() => self.skipWaiting())
94+
95+
evt.waitUntil(cachingCompleted);
96+
});
97+
98+
self.addEventListener('activate', function(evt) {
99+
evt.waitUntil(Promise.all([
100+
cleanupCache(),
101+
self.clients.claim() // claim immediately so the page can be controlled by the sw immediately
102+
]));
103+
});
104+
105+
self.addEventListener('fetch', function(evt) {
106+
var request = evt.request;
107+
var response;
108+
109+
// only handle GET requests
110+
if (request.method !== 'GET') return;
111+
112+
if (isVendor(request.url)) {
113+
// vendor requests: check cache first, fallback to fetch
114+
response = lookupCache(request)
115+
.catch(() => fetchThenCache(request, CACHE_NAMES.vendor));
116+
} else {
117+
// app request: race cache/fetch (bonus: update in background)
118+
response = raceRequest(request, CACHE_NAMES.app);
119+
}
120+
evt.respondWith(response);
121+
});

0 commit comments

Comments
 (0)