diff --git a/main.lux b/main.lux index b4fc49f..b5533d0 100644 --- a/main.lux +++ b/main.lux @@ -108,7 +108,9 @@ fn htmlPostEntry(title: String, date: String, url: String): String = "
" + "

" + sectionTitle + "

" + "
" + postsHtml + "
" -fn htmlHomePage(siteTitle: String, snippetsHtml: String): String = "

" + siteTitle + "

" + "
" + "Βράνδων Λουκᾶς" + "
" + "

" + "Bitcoin Lightning Payments @ voltage.cloud" + "Bitcoin Privacy & Scalability @ payjoin.org." + "Love sovereign software & history." + "Learning Nix, Elm, Rust, Ancient Greek and Latin." + "

" + "
" + snippetsHtml + "
" +fn htmlWelcome(): String = "
Welcome!I'm a software builder by trade who's interested in too many things for my own good.Here's a sample:
" + +fn htmlHomePage(siteTitle: String, snippetsHtml: String): String = "

" + siteTitle + "

" + "
" + "Βράνδων Λουκᾶς" + "
" + "

" + "Bitcoin Lightning Payments @ voltage.cloud" + "Bitcoin Privacy & Scalability @ payjoin.org." + "Love sovereign software & history." + "Learning Nix, Elm, Rust, Ancient Greek and Latin." + "

" + "
" + htmlWelcome() + snippetsHtml + "
" fn htmlSnippetCard(content: String): String = "
" + "
" + content + "
" + "
" @@ -194,26 +196,29 @@ fn renderSnippets(snippetDir: String, files: List): List with {F }, } +fn insertString(sorted: List, item: String): List = { + match List.head(sorted) { + None => [item], + Some(first) => if item <= first then List.concat([item], sorted) else match List.tail(sorted) { + Some(rest) => List.concat([first], insertString(rest, item)), + None => [first, item], +} +} +} + +fn sortStrings(items: List): List = List.fold(items, [], insertString) + fn writeHomePage(outputDir: String, contentDir: String, siteTitle: String, siteDesc: String): Unit with {File} = { let snippetDir = contentDir + "/snippets" let snippetEntries = if File.exists(snippetDir) then { let entries = File.readDir(snippetDir) - List.filter(entries, fn(e: String): Bool => String.endsWith(e, ".md")) + let mdFiles = List.filter(entries, fn(e: String): Bool => String.endsWith(e, ".md")) + sortStrings(mdFiles) } else [] let snippetCards = renderSnippets(snippetDir, snippetEntries) - let firstCard = match List.head(snippetCards) { - Some(c) => c, - None => "", -} - let restCards = match List.tail(snippetCards) { - Some(rest) => rest, - None => [], -} - let gridHtml = "
" + String.join(restCards, " + let gridHtml = "
" + String.join(snippetCards, " ") + "
" - let snippetsHtml = firstCard + " -" + gridHtml - let body = htmlHomePage(siteTitle, snippetsHtml) + let body = htmlHomePage(siteTitle, gridHtml) let pageTitle = "Bitcoin Lightning Developer & Privacy Advocate | " + siteTitle let html = htmlDocument(pageTitle, siteDesc, body) File.write(outputDir + "/index.html", html)