oizys/modules/runes/generate.nu

62 lines
1.3 KiB
Text
Raw Permalink Normal View History

2024-08-06 13:45:28 -05:00
#!/usr/bin/env nix-shell
#!nix-shell -p nushell ascii-image-converter -i nu
let runes = [
{name: "algiz" url: "https://upload.wikimedia.org/wikipedia/commons/1/14/Runic_letter_algiz.png" },
{name: "othalan" url: "https://upload.wikimedia.org/wikipedia/commons/1/16/Runic_letter_othalan.png" },
{name: "mannaz" url: "https://upload.wikimedia.org/wikipedia/commons/0/0c/Runic_letter_mannaz.png" },
{name: "naudiz" url: "https://upload.wikimedia.org/wikipedia/commons/b/b9/Runic_letter_naudiz.png" },
]
def convert [] {
let rune = $in
let image = http get $rune.url
let flags = [--height 15 --negative]
{
name: $rune.name
braille: ( $image | ascii-image-converter - --braille ...$flags)
ascii: ( $image | ascii-image-converter - ...$flags)
}
}
2024-08-08 11:58:30 -05:00
def nix-file [] {
2024-08-06 13:45:28 -05:00
let rune = $in | convert
$"{
braille = ''
($rune.braille)
'';
ascii = ''
($rune.ascii)
'';
}
" | save -f $"($rune.name).nix"
}
def col [] {
2024-08-08 11:58:30 -05:00
$in | reduce --fold "" {|it, acc|
2024-08-06 13:45:28 -05:00
$acc + $'<td><img src="($it.url)"></td>'
}
}
def row [] { $"<tr>($in)</tr>" }
def readme [] {
let runes = $in
let dims = { rows: 2 cols: 2 }
2024-08-08 11:58:30 -05:00
let cells = ($runes | chunks $dims.rows | each { col | row})
2024-08-06 13:45:28 -05:00
let table = [ "<table>" ...$cells "</table>" ] | str join
$"# Runes\n\n($table)\n"
}
$runes
| readme
| save -f "README.md"
$runes
2024-08-08 11:58:30 -05:00
| each { nix-file }
2024-08-06 13:45:28 -05:00
2024-08-08 11:58:30 -05:00
nix fmt