Implement localization

This commit is contained in:
jultty 2024-05-20 10:53:26 -03:00
commit 506c0203d9
12 changed files with 218 additions and 36 deletions

View file

@ -1,11 +1,23 @@
function get_data() { function get_data() {
return { return {
posts: [ pt: {
{ posts: [
title: "Scripts em OCaml", {
slug: "scripts-em-ocaml", title: "Scripts em OCaml",
}, slug: "scripts-em-ocaml",
] date: "23/03/2024",
},
]
},
en: {
posts: [
{
title: "Hello, Worldling",
slug: "hello-worldling",
date: "May 20, 2024",
},
]
}
} }
} }

View file

@ -1,13 +1,26 @@
const data = get_data() const data = get_data()
const post_list = document.getElementById("posts") const post_list = document.getElementById('posts')
document.addEventListener("DOMContentLoaded", function() { const userLang = navigator.language || navigator.userLanguage
data.posts.forEach(post => { let lang = userLang.includes('pt') ? 'pt' : 'en'
const item = document.createElement("li")
const anchor = document.createElement("a") document.addEventListener('DOMContentLoaded', function() {
data[lang].posts.forEach(post => {
const item = document.createElement('li')
const anchor = document.createElement('a')
const date = document.createElement('span')
anchor.innerText = post.title anchor.innerText = post.title
anchor.href = 'posts/' + post.slug + '.html' anchor.href = 'posts/' + post.slug + '.html'
date.innerText = `${parse_date(post.date)} - `
item.appendChild(date)
item.appendChild(anchor) item.appendChild(anchor)
post_list.appendChild(item) post_list.appendChild(item)
}) })
}) })
function parse_date(date) {
current_year = new Date().getFullYear()
return date.replace(`, ${current_year}`, '')
.replace(`/${current_year}`, '')
}

9
assets/js/post-l10n.js Normal file
View file

@ -0,0 +1,9 @@
const userLang = navigator.language || navigator.userLanguage
let lang = userLang.includes('pt') ? 'pt' : 'en'
console.log('loaded post-l10n.js', lang)
if (lang != 'pt') {
const footer_back = document.getElementById('footer-back-link')
console.log(footer_back)
footer_back.innerText = 'Back'
}

View file

@ -5,13 +5,17 @@
src: url('Share Tech Mono.ttf'), format('truetype'); src: url('Share Tech Mono.ttf'), format('truetype');
} }
body { html {
background-color: #222222; background-color: #222222;
font-family: 'ShareTech', monospace; font-family: 'ShareTech', monospace;
color: #F1E9E5;
}
.header-art {
color: #888
} }
p { p {
color: #F1E9E5;
margin: 30px; margin: 30px;
} }
@ -31,7 +35,7 @@ h1 {
font-weight: bold; font-weight: bold;
color: #ccc; color: #ccc;
font-size: 25px; font-size: 25px;
margin: 20px 0px 10px 20px; margin: 40px 0px 10px 20px;
} }
h2 { h2 {
@ -53,3 +57,15 @@ li { margin-bottom: 10px; }
color: #ccc; color: #ccc;
padding: 20px; padding: 20px;
} }
footer {
margin-top: 40px;
}
.footer-text {
padding: 20px 20px;
}
.footer-back {
float: right;
}

View file

@ -11,7 +11,8 @@
</head> </head>
<body> <body>
<header> <header>
<pre role="img" aria-label="ASCII Art with jutty.dev in a 3D, slanted font"> <pre class="header-art"
role="img" aria-label="ASCII art with jutty.dev in a 3D, slanted font">
__ __ __ __ __ __

View file

@ -1,15 +0,0 @@
-- source: https://stackoverflow.com/a/76048743
local title
function Header(e)
if title then return end
title = pandoc.utils.stringify(e) .. " • jutty.dev"
end
function Meta(e)
if not e.pagetitle then
e.pagetitle = title
return e
end
end

View file

@ -1,13 +1,14 @@
#!/usr/bin/env utop #!/usr/bin/env utop
let args = "--css ../../assets/style.css -s --to html5 " ^ let args = "--css ../assets/style.css --standalone " ^
"--highlight-style zenburn " ^ "--lua-filter filters/title.lua " "--from markdown+yaml_metadata_block " ^ "--to html5 " ^
"--highlight-style zenburn " ^ "--template=template.html "
let vert md = begin let vert md = begin
let filename_split = String.split_on_char '.' md in let filename_split = String.split_on_char '.' md in
Sys.command ( Sys.command (
"pandoc " ^ args ^ " md/" ^ md ^ " -o " ^ List.nth filename_split 0 "pandoc " ^ args ^ " md/" ^ md ^ " -o " ^ List.nth filename_split 0 ^ ".html"
) )
end ;; end ;;

39
posts/hello-worldling.html generated Normal file
View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<meta name="author" content="Juno Takano" />
<meta name="dcterms.date" content="2024-05-20" />
<title>Hello, Worldling • jutty.dev</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
<link rel="stylesheet" href="../assets/style.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="https://blog.jutty.dev/feed.rss"/>
<script src="../assets/js/post-l10n.js" defer></script>
</head>
<body>
<header id="title-block-header">
<h1 class="title">Hello, Worldling</h1>
</header>
<p>Oh hi</p>
<footer>
<hr/>
<div class="footer-text">
<span class="author">Juno Takano</span>,
<span class="date">May 20, 2024</span>
<span class="footer-back" aria-role="nav" aria-label="Navigate back">
<a id="footer-back-link" href="../index.html">Voltar</a>
</span>
</div>
</footer>
</body>
</html>

View file

@ -0,0 +1,7 @@
---
title: Hello, Worldling
author: Juno Takano
date: May 20, 2024
---
Oh hi

View file

@ -1,4 +1,8 @@
# Scripts em OCaml ---
title: Scripts em OCaml
author: Juno Takano
date: 23 de fevereiro de 2024
---
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. 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.

View file

@ -4,6 +4,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="generator" content="pandoc" /> <meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<meta name="author" content="Juno Takano" />
<title>Scripts em OCaml • jutty.dev</title> <title>Scripts em OCaml • jutty.dev</title>
<style> <style>
code{white-space: pre-wrap;} code{white-space: pre-wrap;}
@ -76,10 +77,14 @@
code span.wa { color: #7f9f7f; font-weight: bold; } /* Warning */ code span.wa { color: #7f9f7f; font-weight: bold; } /* Warning */
.display.math{display: block; text-align: center; margin: 0.5rem auto;} .display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style> </style>
<link rel="stylesheet" href="../../assets/style.css" /> <link rel="stylesheet" href="../assets/style.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="https://blog.jutty.dev/feed.rss"/>
<script src="../assets/js/post-l10n.js" defer></script>
</head> </head>
<body> <body>
<h1 id="scripts-em-ocaml">Scripts em OCaml</h1> <header id="title-block-header">
<h1 class="title">Scripts em OCaml</h1>
</header>
<p>Este blog gera suas postagens com o Pandoc, mas quem faz o trabalho <p>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 lógico de identificar os arquivos e montar os comandos é um pequeno
script em OCaml.</p> script em OCaml.</p>
@ -121,5 +126,15 @@ a directory/Non-recursively - Rosetta Code</a></li>
<li><a href="https://jez.io/pandoc-markdown-css-theme/">Pandoc Markdown <li><a href="https://jez.io/pandoc-markdown-css-theme/">Pandoc Markdown
CSS Theme</a></li> CSS Theme</a></li>
</ul> </ul>
<footer>
<hr/>
<div class="footer-text">
<span class="author">Juno Takano</span>,
<span class="date">23 de fevereiro de 2024</span>
<span class="footer-back" aria-role="nav" aria-label="Navigate back">
<a id="footer-back-link" href="../index.html">Voltar</a>
</span>
</div>
</footer>
</body> </body>
</html> </html>

80
posts/template.html generated Normal file
View file

@ -0,0 +1,80 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang$" xml:lang="$lang$"$if(dir)$ dir="$dir$"$endif$>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
$for(author-meta)$
<meta name="author" content="$author-meta$" />
$endfor$
$if(date-meta)$
<meta name="dcterms.date" content="$date-meta$" />
$endif$
$if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
$endif$
$if(description-meta)$
<meta name="description" content="$description-meta$" />
$endif$
<title>$if(title-prefix)$$title-prefix$ $endif$$pagetitle$ • jutty.dev</title>
<style>
$styles.html()$
</style>
$for(css)$
<link rel="stylesheet" href="$css$" />
$endfor$
<link rel="alternate" type="application/rss+xml" title="RSS" href="https://blog.jutty.dev/feed.rss"/>
<script src="../assets/js/post-l10n.js" defer></script>
$for(header-includes)$
$header-includes$
$endfor$
$if(math)$
$math$
$endif$
</head>
<body>
$for(include-before)$
$include-before$
$endfor$
$if(title)$
<header id="title-block-header">
<h1 class="title">$title$</h1>
$if(subtitle)$
<p class="subtitle">$subtitle$</p>
$endif$
$if(abstract)$
<div class="abstract">
<div class="abstract-title">$abstract-title$</div>
$abstract$
</div>
$endif$
</header>
$endif$
$if(toc)$
<nav id="$idprefix$TOC" role="doc-toc">
$if(toc-title)$
<h2 id="$idprefix$toc-title">$toc-title$</h2>
$endif$
$table-of-contents$
</nav>
$endif$
$body$
$for(include-after)$
$include-after$
$endfor$
<footer>
<hr/>
<div class="footer-text">
$for(author)$
<span class="author">$author$</span>,
$endfor$
$if(date)$
<span class="date">$date$</span>
<span class="footer-back" aria-role="nav" aria-label="Navigate back">
<a id="footer-back-link" href="../index.html">Voltar</a>
</span>
$endif$
</div>
</footer>
</body>
</html>