Initial commit

This commit is contained in:
jultty 2024-02-23 20:00:34 -03:00
commit 93330ddc28
9 changed files with 145 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
posts/html/*

4
README.md Normal file
View file

@ -0,0 +1,4 @@
A bare-bones personal website relying only on simple scripts.
## Next
- [ ] Update data object programmatically on HTML post generation

Binary file not shown.

11
assets/js/data.js Normal file
View file

@ -0,0 +1,11 @@
function get_data() {
return {
posts: [
{
title: "Scripts em OCaml",
slug: "scripts-em-ocaml",
},
]
}
}

13
assets/js/main.js Normal file
View file

@ -0,0 +1,13 @@
const data = get_data()
const post_list = document.getElementById("posts")
document.addEventListener("DOMContentLoaded", function() {
data.posts.forEach(post => {
const item = document.createElement("li")
const anchor = document.createElement("a")
anchor.innerText = post.title
anchor.href = 'posts/html/' + post.slug + '.md.html'
item.appendChild(anchor)
post_list.appendChild(item)
})
})

57
assets/style.css Normal file
View file

@ -0,0 +1,57 @@
* {
margin: 0px;
}
@font-face {
font-family: 'ShareTech';
src: url('Share Tech Mono 400.ttf'), format('truetype');
}
body {
background-color: #222222;
font-family: 'ShareTech', monospace;
}
p {
color: #F1E9E5;
margin: 30px;
}
a {
text-decoration: underline dotted #888;
color: #AEDBCE;
}
a:hover {
color: #39AEA9;
text-decoration: underline dotted #fff;
transition: 1500ms;
}
h1 {
font-size: 25px;
font-weight: bold;
color: #ccc;
font-size: 25px;
margin: 20px 0px 10px 20px;
}
h2 {
font-size: 25px;
font-weight: bold;
color: #ccc;
font-size: 25px;
margin: 20px 0px 10px 20px;
}
ul {
margin-top: 10px;
color: #F1E9E5;
}
li {
margin-bottom: 10px;
}
.sourceCode { color: #ccc; }
.sourceCode span { margin-left: 20px; }

19
index.html Normal file
View file

@ -0,0 +1,19 @@
!<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jutty.dev</title>
<link href="assets/style.css" rel="stylesheet">
<script src="assets/js/data.js"></script>
<script src="assets/js/main.js" defer></script>
</head>
<body>
<header>
<h1>jutty.dev</h1>
</header>
<nav>
<ul id="posts"></ul>
</nav>
</body>
</html>

11
posts/gen.ml Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env utop
let pandoc_params = "--css ../../assets/style.css -s --to html5 --metadata pagetitle='basename' "
let vert md = begin
if md <> "gen.ml" && md <> "html" then
ignore( Sys.command ("pandoc " ^ pandoc_params ^ md ^ " -o html/" ^ md ^ ".html ") )
end ;;
let contents = Array.to_list (Sys.readdir ".") in
List.map vert contents ;;

29
posts/scripts-em-ocaml.md Normal file
View file

@ -0,0 +1,29 @@
# Scripts em OCaml
Este blog gera suas postagens com o Pandoc, mas quem faz o trabalho lógico de identificar os arquivos e montar os comandos é um pequeno script em OCaml.
Descobri essa linguagem quando comecei a investigar como poderia substituir o Bash como uma linguagem para scripts. Eu acho que o Bash é excelente para cumprir essa função, apesar de bastante inseguro e propenso a erros. O que me incomodava mesmo era ver que todo aquele tempo escrevendo scripts com Bash poderia ser tempo aprendendo uma linguagem cujo conhecimento se transferisse para muitas outras aplicações.
O script consiste nestas nove linhas apenas:
```ocaml
let pandoc_params = "--css ../../assets/style.css -s --to html5 --metadata pagetitle='basename' "
let vert md = begin
if md <> "gen.ml" && md <> "html" then
ignore( Sys.command ("pandoc " ^ pandoc_params ^ md ^ " -o html/" ^ md ^ ".html ") )
end ;;
let contents = Array.to_list (Sys.readdir ".") in
List.map vert contents ;;
```
Primeiro, armazeno em `pandoc_params` os parâmetros comuns que serão passados ao Pandoc para gerar os arquivos HTML a partir dos arquivos em Markdown.
Em seguida, defino a função `vert`, que, caso o arquivo não se chame "gen.ml" (o próprio script) nem "html" (o diretório onde os arquivos gerados ficam), o comando do Pandoc é chamado com os nomes dos arquivos de entrada e saída.
Essa função então é aplicada com `List.map vert contents` a cada arquivo do diretório atual.
## Referências
- [Pandoc Markdown CSS Theme](https://jez.io/pandoc-markdown-css-theme/)
- [Walk a directory/Non-recursively - Rosetta Code](https://rosettacode.org/wiki/Walk_a_directory/Non-recursively#OCaml)