This was broken in my blog for way too long. Change-Id: I03c45c666d67006a4608a4b19d6167ab692e321d Reviewed-on: https://cl.tvl.fyi/c/depot/+/5905 Reviewed-by: wpcarro <wpcarro@gmail.com> Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
		
			
				
	
	
		
			47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
{ depot, lib, pkgs, ... }:
 | 
						|
 | 
						|
with depot.nix.yants;
 | 
						|
 | 
						|
let
 | 
						|
  inherit (builtins) hasAttr filter readFile;
 | 
						|
  inherit (depot.web.blog) post includePost renderPost;
 | 
						|
  inherit (depot.users.wpcarro.website) domain renderTemplate withBrand;
 | 
						|
  inherit (lib.lists) sort;
 | 
						|
 | 
						|
  config = {
 | 
						|
    name = "bill and his blog";
 | 
						|
    baseUrl = "https://${domain}/blog";
 | 
						|
    staticUrl = "https://static.tvl.fyi/latest";
 | 
						|
    footer = "";
 | 
						|
  };
 | 
						|
 | 
						|
  posts = sort (x: y: x.date > y.date)
 | 
						|
    (filter includePost (list post (import ./posts.nix)));
 | 
						|
 | 
						|
  rendered = pkgs.runCommand "blog-posts" { } ''
 | 
						|
    mkdir -p $out
 | 
						|
 | 
						|
    ${lib.concatStringsSep "\n" (map (post:
 | 
						|
      "cp ${renderPost config post} $out/${post.key}.html"
 | 
						|
    ) posts)}
 | 
						|
  '';
 | 
						|
 | 
						|
  formatDate = date: readFile (pkgs.runCommand "date" { } ''
 | 
						|
    date --date='@${toString date}' '+%B %e, %Y' > $out
 | 
						|
  '');
 | 
						|
 | 
						|
  postsHtml = renderTemplate ./fragments/posts.html {
 | 
						|
    postsHtml = lib.concatStringsSep "\n" (map toPostHtml posts);
 | 
						|
  };
 | 
						|
 | 
						|
  toPostHtml = post: readFile (renderTemplate ./fragments/post.html {
 | 
						|
    postUrl = "${config.baseUrl}/posts/${post.key}.html";
 | 
						|
    postTitle = post.title;
 | 
						|
    postDate = formatDate post.date;
 | 
						|
  });
 | 
						|
in
 | 
						|
pkgs.runCommand "blog" { } ''
 | 
						|
  mkdir -p $out
 | 
						|
  cp ${withBrand (readFile postsHtml)} $out/index.html
 | 
						|
  cp -r ${rendered} $out/posts
 | 
						|
''
 |