From 098bbb4d67a0df8d191ba9a8665b86e8dbad7759 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 15 Jun 2020 23:18:17 -0400 Subject: feat(gws.fyi): Make title work properly in index This is remarkably silly, but it gets the job done Change-Id: Ifbc57988a59c4f51a3bba0ed8ad397cb9855d8ab Reviewed-on: https://cl.tvl.fyi/c/depot/+/423 Reviewed-by: glittershark --- users/glittershark/gws.fyi/orgExportHTML.nix | 30 +++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'users/glittershark/gws.fyi/orgExportHTML.nix') diff --git a/users/glittershark/gws.fyi/orgExportHTML.nix b/users/glittershark/gws.fyi/orgExportHTML.nix index b37be10045dd..153036789f6b 100644 --- a/users/glittershark/gws.fyi/orgExportHTML.nix +++ b/users/glittershark/gws.fyi/orgExportHTML.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ pkgs ? import {}, ... }: with pkgs; with lib; @@ -20,14 +20,29 @@ let in -src: +opts: let + src = if isAttrs opts then opts.src else opts; + headline = if isAttrs opts then opts.headline else null; + + bn = builtins.baseNameOf src; + filename = elemAt (splitString "." bn) 0; outName = - let bn = builtins.baseNameOf src; - filename = elemAt (splitString "." bn) 0; - in filename + ".html"; + if isNull headline + then + let bn = builtins.baseNameOf src; + filename = elemAt (splitString "." bn) 0; + in filename + ".html" + else "${filename}-${replaceStrings [" "] ["-"] filename}.html"; + + escapeDoubleQuotes = replaceStrings ["\""] ["\\\""]; + + navToHeadline = optionalString (! isNull headline) '' + (search-forward "${escapeDoubleQuotes headline}") + (org-narrow-to-subtree) + ''; in @@ -38,8 +53,9 @@ runCommand outName {} '' --load ${./config.el} \ --visit file.org \ --eval "(progn - (require 'org) + ${escapeDoubleQuotes navToHeadline} (org-html-export-to-html))" \ --kill - cp file.html $out + substitute file.html $out \ + --replace '' "" '' -- cgit 1.4.1