mirror of
				https://github.com/Brandon-Rozek/website.git
				synced 2025-10-31 13:51:13 +00:00 
			
		
		
		
	Fixing up offline page
This commit is contained in:
		
							parent
							
								
									3161801ca5
								
							
						
					
					
						commit
						5f0441e629
					
				
					 1 changed files with 15 additions and 18 deletions
				
			
		|  | @ -8,17 +8,19 @@ hidden: true | ||||||
| Your device is offline. You may have some pages cached for offline viewing, | Your device is offline. You may have some pages cached for offline viewing, | ||||||
| otherwise please wait for the internet to reconnect to continue browsing. | otherwise please wait for the internet to reconnect to continue browsing. | ||||||
| 
 | 
 | ||||||
| [Homepage](/) |  | ||||||
| 
 |  | ||||||
| {{< unsafe >}} | {{< unsafe >}} | ||||||
| 
 | 
 | ||||||
| <ul id='offline-posts'></ul> | <ul id='offline-posts'> | ||||||
|  |   <li><a href='/'>Homepage</a></li> | ||||||
|  | </ul> | ||||||
| 
 | 
 | ||||||
| <script> | <script> | ||||||
| 
 | 
 | ||||||
| function daysAgo(date) { | function daysAgo(date) { | ||||||
|   date.setHours(0, 0, 0, 0); |   date.setHours(0, 0, 0, 0); | ||||||
|   const time = date.getTime(); |   const time = date.getTime(); | ||||||
|  |   const today = new Date(); | ||||||
|  |   today.setHours(0, 0, 0, 0); | ||||||
|   const now = today.getTime(); |   const now = today.getTime(); | ||||||
|   const delta = ((now - time) / 1000 / 60 / 60 / 24) | 0; |   const delta = ((now - time) / 1000 / 60 / 60 / 24) | 0; | ||||||
| 
 | 
 | ||||||
|  | @ -35,19 +37,18 @@ function daysAgo(date) { | ||||||
| 
 | 
 | ||||||
| async function listPages() { | async function listPages() { | ||||||
|   // Get a list of all of the caches for this origin |   // Get a list of all of the caches for this origin | ||||||
|   const cacheNames = await caches.keys(); |  | ||||||
|   const result = []; |   const result = []; | ||||||
|  |   const cache = await caches.open('v1::website'); | ||||||
| 
 | 
 | ||||||
|   for (const name of cacheNames) { |   // Get a list of entries. Each item is a Request object | ||||||
|     // Open the cache |   for (const request of await cache.keys()) { | ||||||
|     if (name.includes('/blog')) { |     const url = request.url; | ||||||
|       const cache = await caches.open(name); |     if (url.includes('/blog')) { | ||||||
| 
 |       console.log(url) | ||||||
|       // Get a list of entries. Each item is a Request object |       const post = await cache.match(request); | ||||||
|       for (const request of await cache.keys()) { |       if (post.headers.get('content-type') === 'text/html') { | ||||||
|         const url = request.url; |  | ||||||
|         const post = await cache.match(request); |  | ||||||
|         const body = await post.text(); |         const body = await post.text(); | ||||||
|  |         console.log(body) | ||||||
|         const title = body.match(/<title>(.*)<\/title>/)[1]; |         const title = body.match(/<title>(.*)<\/title>/)[1]; | ||||||
|         result.push({ |         result.push({ | ||||||
|           url, |           url, | ||||||
|  | @ -55,18 +56,14 @@ async function listPages() { | ||||||
|           title, |           title, | ||||||
|           visited: new Date(post.headers.get('date')), |           visited: new Date(post.headers.get('date')), | ||||||
|         }); |         }); | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|    |    | ||||||
| 
 |  | ||||||
|   const el = document.querySelector('#offline-posts'); |   const el = document.querySelector('#offline-posts'); | ||||||
| 
 | 
 | ||||||
|   if (result.length) { |   if (result.length) { | ||||||
|     el.innerHTML = result |     el.innerHTML = result | ||||||
|       .sort((a, b) => { |  | ||||||
|         return a.published.toJSON() < b.published.toJSON() ? 1 : -1; |  | ||||||
|       }) |  | ||||||
|       .map((res) => { |       .map((res) => { | ||||||
|         let html = `<li> |         let html = `<li> | ||||||
|         <a href="${res.url}">${res.title}</a> |         <a href="${res.url}">${res.title}</a> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue