refactor(wpcarro/website): Prefer substituteAll
`substituteAll` supports templating with @variables@, which I think really cleans things up. Change-Id: Icfad15ac9e174495ba02260d817f7330f1616c6f Reviewed-on: https://cl.tvl.fyi/c/depot/+/4722 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
This commit is contained in:
		
							parent
							
								
									52369a11e3
								
							
						
					
					
						commit
						e107311cb8
					
				
					 8 changed files with 94 additions and 85 deletions
				
			
		|  | @ -6,16 +6,16 @@ let | |||
|   inherit (builtins) hasAttr filter readFile; | ||||
|   inherit (depot.web.blog) post includePost renderPost; | ||||
|   inherit (depot.users) wpcarro; | ||||
|   inherit (pkgs) runCommandNoCC; | ||||
| 
 | ||||
|   config = { | ||||
|     name = "wpcarro's blog"; | ||||
|     baseUrl = "https://wpcarro.dev/blog"; | ||||
|     footer = ""; | ||||
|   }; | ||||
| 
 | ||||
|   posts = filter includePost (list post (import ./posts.nix)); | ||||
| 
 | ||||
|   rendered = runCommandNoCC "wpcarros-blog" {} '' | ||||
|   rendered = pkgs.runCommandNoCC "wpcarros-blog-posts" {} '' | ||||
|     mkdir -p $out | ||||
| 
 | ||||
|     ${lib.concatStringsSep "\n" (map (post: | ||||
|  | @ -23,41 +23,26 @@ let | |||
|     ) posts)} | ||||
|   ''; | ||||
| 
 | ||||
|   formatDate = date: readFile (runCommandNoCC "date" {} '' | ||||
|   formatDate = date: readFile (pkgs.runCommandNoCC "date" {} '' | ||||
|     date --date='@${toString date}' '+%B %e, %Y' > $out | ||||
|   ''); | ||||
| 
 | ||||
|   postsList = pkgs.writeText "index.html" '' | ||||
|     <div class="max-w-sm md:max-w-prose mx-auto"> | ||||
|       <section class="pt-8 pb-14"> | ||||
|         <p class="font-bold pb-4">Personal blog by <a class="font-bold text-blue-600 hover:underline" href="https://wpcarro.dev">wpcarro</a>.</p> | ||||
|         <p class="text-gray-500">> Half-baked musings lossily encoded.</p> | ||||
|         <p class="text-gray-500">> - misc reviewer</p> | ||||
|       </section> | ||||
|       <ul> | ||||
|         ${lib.concatStringsSep "\n" (map (post: '' | ||||
|           <li class="pb-10"> | ||||
|             <h2 class="text-bold font-2xl "> | ||||
|               <a class="font-bold text-blue-600 hover:underline" href="${config.baseUrl}/${post.key}.html"> | ||||
|                 ${post.title} | ||||
|               </a> | ||||
|             </h2> | ||||
|             <p class="text-gray-500"> | ||||
|               ${formatDate post.date} | ||||
|             </p> | ||||
|           </li> | ||||
|         '') posts)} | ||||
|       </ul> | ||||
|     </div> | ||||
|   ''; | ||||
|   postsHtml = readFile (pkgs.substituteAll { | ||||
|     src = ./fragments/posts.html; | ||||
|     postsHtml = lib.concatStringsSep "\n" (map toPostHtml posts); | ||||
|   }); | ||||
| 
 | ||||
|   toPostHtml = post: readFile (pkgs.substituteAll { | ||||
|     src = ./fragments/post.html; | ||||
|     postUrl = "${config.baseUrl}/${post.key}.html"; | ||||
|     postTitle = post.title; | ||||
|     postDate = formatDate post.date; | ||||
|   }); | ||||
| in { | ||||
|   inherit posts rendered config; | ||||
| 
 | ||||
|   root = runCommandNoCC "wpcarros-blog" {} '' | ||||
|   root = pkgs.runCommandNoCC "wpcarros-blog" {} '' | ||||
|     mkdir -p $out | ||||
| 
 | ||||
|     cat ${wpcarro.website.header} \ | ||||
|         ${postsList} \ | ||||
|         ${wpcarro.website.addendum} > $out/index.html | ||||
|     cp ${wpcarro.website.render postsHtml} $out/index.html | ||||
|   ''; | ||||
| } | ||||
|  |  | |||
							
								
								
									
										0
									
								
								users/wpcarro/website/blog/fragments/.skip-subtree
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								users/wpcarro/website/blog/fragments/.skip-subtree
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										8
									
								
								users/wpcarro/website/blog/fragments/post.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								users/wpcarro/website/blog/fragments/post.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| <li class="pb-6 md:pb-10"> | ||||
|   <h2 class="text-bold text-xl"> | ||||
|     <a class="font-bold text-blue-600 hover:underline" href="@postUrl@"> | ||||
|       @postTitle@ | ||||
|     </a> | ||||
|   </h2> | ||||
|   <p class="text-gray-500">@postDate@</p> | ||||
| </li> | ||||
							
								
								
									
										10
									
								
								users/wpcarro/website/blog/fragments/posts.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								users/wpcarro/website/blog/fragments/posts.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| <div class="max-w-sm md:max-w-prose mx-auto"> | ||||
|   <section class="pt-8 pb-14"> | ||||
|     <p class="font-bold pb-3 text-xl"> | ||||
|       Personal blog by <a class="font-bold text-blue-600 hover:underline" href="https://wpcarro.dev">wpcarro</a>. | ||||
|     </p> | ||||
|     <p class="text-gray-500">> Half-baked musings lossily encoded.</p> | ||||
|     <p class="text-gray-500">> - misc reviewer</p> | ||||
|   </section> | ||||
|   <ul>@postsHtml@</ul> | ||||
| </div> | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue