Start pulling /now page from omg.lol
This commit is contained in:
		
							parent
							
								
									6e77331b38
								
							
						
					
					
						commit
						bd772ae6d7
					
				
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 5.5 MiB  | 
							
								
								
									
										28
									
								
								src/now.11tydata.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/now.11tydata.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					module.exports = {
 | 
				
			||||||
 | 
					    eleventyComputed: {
 | 
				
			||||||
 | 
					        content: async () => {
 | 
				
			||||||
 | 
					            // Retrieve the /now page from the server
 | 
				
			||||||
 | 
					            const response = await fetch("https://api.omg.lol/address/lewis/now");
 | 
				
			||||||
 | 
					            const body = await response.json();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Convert the unix timestamp to a JS datetime timestamp            
 | 
				
			||||||
 | 
					            const updated = new Date(body.response.now.updated * 1000);
 | 
				
			||||||
 | 
					            let content = body.response.now.content;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Replace the last-updated tag
 | 
				
			||||||
 | 
					            content = content.replace("{last-updated}", `<span class="now_updated">Updated ${updated.toLocaleDateString('en-GB', { dateStyle: "medium" })}</span>`);
 | 
				
			||||||
 | 
					            // Strip out omg.lol-specific tags
 | 
				
			||||||
 | 
					            content = content.replaceAll(/{[^}]*}/g, "");
 | 
				
			||||||
 | 
					            // remove comments
 | 
				
			||||||
 | 
					            content = content.replaceAll(/\/\*.*?\*\//g, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Remove everything before the --- Now --- marker, because I handle page titles and headings in 11ty
 | 
				
			||||||
 | 
					            if (content.includes("--- Now ---")) {
 | 
				
			||||||
 | 
					                const [before, after] = content.split("--- Now ---");
 | 
				
			||||||
 | 
					                content = after;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            return content;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								src/now.md
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/now.md
									
									
									
									
									
								
							@ -3,17 +3,4 @@ title: My /now page
 | 
				
			|||||||
layout: page.njk
 | 
					layout: page.njk
 | 
				
			||||||
---
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## What I'm reading
 | 
					{{ content | safe }}
 | 
				
			||||||
 | 
					 | 
				
			||||||
* :book: The Player of Games by Iain M. Banks
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## What I'm watching
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
* :tv: For All Mankind
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## What I'm enjoying
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
* :bicycle: Preparing for a 100km charity cycle
 | 
					 | 
				
			||||||
* :people-roof: Spending time with my family
 | 
					 | 
				
			||||||
* :computer: Working on my ZX Basic interpreter
 | 
					 | 
				
			||||||
* :gamepad: Playing The Outer Worlds on Nintendo Switch
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user