💾 Archived View for gemini.ctrl-c.club › ~de_alchmst › b-logs › ruby › site-gen › 020:template-gener… captured on 2024-07-08 at 23:51:18. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-05-10)
-=-=-=-=-=-=-
With templates I can get rid of some repetetive stuff, but I stil have to write my b-logs in both html and gemtext, which I don't want to. Therefore I made few scripts to generate those templates for me from markdown-like markup langue.
# h1 ## h2 ### h3 this will all be on single line because I like to have my text manually wrapped under 80 chars new paragraf
Also files are named as path to its outcome on site wth extra number before name, or name two times if it is not part of series. This is so that it can be sorted in correct order. This file is called
b-log.ruby.site-gen.020:template-generator
This script will read all 'b-log' starting files and genrate coresponding .template files for both html and gemtext. It will add coresponding header/footer template words and previous/next links, but it will not actually translate text to html/gemtext yet. Instead it will add complex TO_HTML and TO_GEMTEXT words with link to original b-log file.
Nothing that interesting, just a bunch of regex. Converting to html was actually easier, because I did not have to care about putting paragrafs onto one line while keeping empty lines around other elements. Escape codes for regex replacements can only be put in single quoted string that does not support newline escape so that was funny. Also sometimes you want to put regex operations into empty while loop to count replacement outcome in next search.
# like this because I want to # consume the added newline if next element # is also link while part.sub! /\n?[^\n\S]*\[(.+?)\]\((.+?)\)[^\n\S]*\n?/, "\n=> "+'\2 \1'+"\n" end
Also since the script are called from backtick string, I return value through stdout with print. It is important to not use puts, for it adds newline that can break some stuff.
----------------------------