Compare commits

...

10 commits

21 changed files with 207 additions and 55 deletions

View file

@ -1,3 +1,24 @@
# navbar
[home]
en = "home"
es = "inicio"
[about]
en = "about"
es = "acerca de"
[blog]
en = "blog"
es = "blog"
[music]
en = "music"
es = "música"
[etc]
en = "etc"
es = "etc"
# 404
[404]
en = "404 not found"
@ -11,11 +32,12 @@ es = "vuelve a casa <3"
en = "by yasuhira"
es = "por yasuhira"
# homepage
[home]
en = "home"
es = "inicio"
# under construction
[under-construction]
en = "this page is under construction!!"
es = "aún estoy haciendo esta página!!"
# homepage
[please-visit]
en = "please visit..."
es = "visita también..."

View file

@ -1,49 +1,23 @@
[en]
[en.home]
[home]
name = "home"
url = "/en/"
url = "/"
[en.about]
[about]
name = "about"
url = "/en/about/"
url = "/about/"
[en.blog]
[blog]
name = "blog"
url = "/en/blog/"
url = "/blog/"
[en.reviews]
[reviews]
name = "reviews"
url = "/en/reviews/"
url = "/reviews/"
[en.music]
[music]
name = "music"
url = "https://smalrainbow.bandcamp.com/"
new_tab = true
[en.etc]
name = "etc"
[es]
[es.home]
name = "inicio"
url = "/es/"
[es.about]
name = "acerca de"
url = "/es/acerca-de/"
[es.blog]
name = "blog"
url = "/es/blog/"
[es.reviews]
name = "reviews"
url = "/es/reviews/"
[es.music]
name = "música"
url = "https://smalrainbow.bandcamp.com/"
new_tab = true
[es.etc]
[etc]
name = "etc"

View file

@ -1,6 +1,6 @@
<div class="footer-flex">
<div class="footer-left">
{% if show_lang_in_footer %}
{% if not dont_show_lang_in_footer %}
{% include "lang-available.njk" %}
{% endif %}
</div>

View file

@ -1,8 +1,8 @@
<nav class="navbar-wrapper">
<div class="navbar-content">
<ul>
{% for item in navbar[page.lang] | values %}
<li id="{{ item.name }}">{% if item.url %}<a href="{{ item.url }}" {% if item.new_tab %}target="_blank"{% endif %}>{{ item.name }}</a>{% else %}<p>{{ item.name }}</p>{% endif %}</li>
{% for item in navbar | values %}
<li id="{{ item.name }}">{% if item.url %}<a href="{{ item.url | locale_url_resolve }}" {% if item.new_tab %}target="_blank"{% endif %}>{{ item.name | i18n }}</a>{% else %}<p>{{ item.name | i18n }}</p>{% endif %}</li>
{% endfor %}
<li id="nav-hover" aria-hidden="true"></li>
</ul>

View file

@ -1,6 +1,3 @@
---
show_lang_in_footer: true
---
{% extends "_layouts/base.njk" %}
{% block content %}

View file

@ -4,6 +4,7 @@ lastfm: true
flight:
img: "/img/Witch-on-broom.gif"
url: "https://www.youtube.com/embed/w1dXpAJ1qfA"
dont_show_lang_in_footer: true
---
{% extends "_layouts/base.njk" %}

View file

@ -1,7 +1,6 @@
---
# TODO: finish post page
tags: post
show_lang_in_footer: true
---
{% extends "_layouts/base.njk" %}
{% block content %}

View file

@ -0,0 +1,9 @@
{% extends "_layouts/base.njk" %}
{% block content %}
<div id="under-construction">
<h2>{{ "under-construction" | i18n }}</h2>
<img src="/img/fatalframe.gif" alt={{ "under-construction" | i18n }}>
{{ content | safe }}
</div>
{% endblock content %}

View file

@ -89,6 +89,23 @@ body {
}
}
// under construction
#under-construction {
width: 100%;
h2 {
font-size: 1.4em;
text-align: center;
text-decoration: none;
margin-top: 8px;
}
img {
display: block;
width: fit-content;
margin: 8px auto;
}
}
.header-wrapper {
display: flex;
align-items: flex-start;

View file

@ -1,4 +1,6 @@
const { I18nPlugin } = require("@11ty/eleventy");
const {
I18nPlugin
} = require("@11ty/eleventy");
const i18n = require("eleventy-plugin-i18n");
const eleventySass = require("eleventy-sass");
const toml = require("@iarna/toml");
@ -6,9 +8,9 @@ const toml = require("@iarna/toml");
const fs = require("fs");
const path = require("path");
module.exports = function(eleventyConfig) {
module.exports = function (eleventyConfig) {
eleventyConfig.setLayoutsDirectory("_layouts");
eleventyConfig.addPassthroughCopy("img");
eleventyConfig.addPassthroughCopy("css/fonts");
eleventyConfig.addPassthroughCopy("js");
@ -16,9 +18,15 @@ module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("robots.txt");
eleventyConfig.addPassthroughCopy("roms");
const defaultLanguage = "en";
// expose as global site data for templates
eleventyConfig.addGlobalData("site", {
defaultLocale: defaultLanguage
});
eleventyConfig.addNunjucksFilter("values", obj => Object.values(obj));
eleventyConfig.addFilter("i18n_filter", function(collection, limit = null) {
eleventyConfig.addFilter("i18n_filter", function (collection, limit = null) {
const lang = this.page.lang; // access page.lang from context
let filtered = collection.filter(item => item.data.lang === lang);
if (limit !== null) {
@ -29,8 +37,8 @@ module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(eleventySass);
eleventyConfig.addPlugin(I18nPlugin, {
defaultLanguage: "en",
errorMode: "allow-fallback" // /en/ -> /
defaultLanguage: defaultLanguage,
errorMode: "allow-fallback", // /en/ -> /
});
eleventyConfig.addDataExtension("toml", (contents) => toml.parse(contents));
@ -40,6 +48,94 @@ module.exports = function(eleventyConfig) {
);
const translations = toml.parse(translationsToml);
const LOCALE_URL_DEBUG = process.env.LOCALE_URL_DEBUG === "1" || process.env.LOCALE_URL_DEBUG === "true";
eleventyConfig.addNunjucksFilter("locale_url_resolve", function (targetUrl, desiredLocale) {
const ctx = (this && this.ctx) ? this.ctx : {};
const collections = (ctx.collections) ? ctx.collections : {};
const all = collections.all || [];
if (!targetUrl || typeof targetUrl !== "string") return targetUrl;
if (!targetUrl.startsWith("/")) return targetUrl; // external or relative link -> leave as is
// determine locale to resolve to
const pageLang = desiredLocale || (ctx.page && ctx.page.lang) || ctx.locale || defaultLanguage;
if (LOCALE_URL_DEBUG) {
console.warn(`[locale_url_resolve] resolving targetUrl="${targetUrl}" desiredLocale="${desiredLocale}" pageLang="${pageLang}"`);
}
// if requested locale is default, return the raw url (your default publishes to root)
if (pageLang === defaultLanguage) {
if (LOCALE_URL_DEBUG) console.warn(`[locale_url_resolve] requested locale is default (${defaultLanguage}) — returning raw URL "${targetUrl}"`);
return targetUrl;
}
// normalize targetUrl to ensure trailing slash for comparison
const normUrl = targetUrl.endsWith("/") ? targetUrl : (targetUrl + "/");
// try to find the canonical (default language) page corresponding to targetUrl
let canonical = all.find(p => {
return (p.url === normUrl || p.url === targetUrl) && p.data && p.data.lang === defaultLanguage;
});
// if not found, try to find any page with that url (maybe targetUrl already localized)
if (!canonical) {
canonical = all.find(p => (p.url === normUrl || p.url === targetUrl));
}
if (LOCALE_URL_DEBUG) {
if (canonical) {
const cs = (canonical.page && canonical.page.filePathStem) ? canonical.page.filePathStem : "(no stem)";
const clang = (canonical.data && canonical.data.lang) ? canonical.data.lang : "(no lang)";
console.warn(`[locale_url_resolve] canonical found: url="${canonical.url}" filePathStem="${cs}" lang="${clang}"`);
} else {
console.warn(`[locale_url_resolve] canonical NOT found for targetUrl="${targetUrl}". Will fallback to prefixed URL.`);
}
}
// if cannot find canonical page, fall back to a prefixed URL (best effort)
if (!canonical) {
const fallback = (`/${pageLang}${targetUrl}`).replace(/\/{2,}/g, "/");
if (LOCALE_URL_DEBUG) console.warn(`[locale_url_resolve] fallback -> "${fallback}"`);
return fallback;
}
// determine canonical filePathStem (the source input path without extension)
const canonicalLang = canonical.data && canonical.data.lang ? canonical.data.lang : defaultLanguage;
const canonicalStem = (canonical.page && canonical.page.filePathStem) ? canonical.page.filePathStem : "";
// remove the canonical lang prefix from the stem to create a "key" we can match across locales.
// e.g. "/en/about" -> "/about", "/es/about" -> "/about"
const key = canonicalStem.replace(new RegExp(`^/${canonicalLang}`), "").replace(/^\/+/, "");
if (LOCALE_URL_DEBUG) {
console.warn(`[locale_url_resolve] canonicalLang="${canonicalLang}" canonicalStem="${canonicalStem}" key="${key}"`);
}
// find the localized page whose filePathStem ends with that key and whose lang matches pageLang.
const localized = all.find(p => {
const pLang = p.data && p.data.lang;
const pStem = (p.page && p.page.filePathStem) ? p.page.filePathStem : "";
// be defensive: ensure pLang exists
if (!pLang) return false;
return pLang === pageLang && pStem.endsWith(key);
});
if (localized && localized.url) {
if (LOCALE_URL_DEBUG) {
const ls = (localized.page && localized.page.filePathStem) ? localized.page.filePathStem : "(no stem)";
console.warn(`[locale_url_resolve] localized found: url="${localized.url}" filePathStem="${ls}" lang="${localized.data.lang}"`);
}
return localized.url;
}
// no localized page found — fall back to prefixed path
const fallback2 = (`/${pageLang}${targetUrl}`).replace(/\/{2,}/g, "/");
if (LOCALE_URL_DEBUG) console.warn(`[locale_url_resolve] localized NOT found for key="${key}" — fallback -> "${fallback2}"`);
return fallback2;
});
eleventyConfig.addPlugin(i18n, {
translations,
fallbackLocales: {

4
en/about.md Normal file
View file

@ -0,0 +1,4 @@
---
title: about me
layout: under_construction
---

4
en/blog/index.md Normal file
View file

@ -0,0 +1,4 @@
---
title: blog
layout: under_construction
---

View file

@ -0,0 +1,4 @@
---
title: umihara kawase
layout: under_construction
---

View file

@ -10,3 +10,5 @@ welcome to my site!! as with every website this is a heavy work in progress. how
- all pages marked as "under construction"
![rakka hairbush fail](/img/rakka-hairbrush-fail.gif)
you can browser however you like in the meanwhile.

4
en/reviews/index.md Normal file
View file

@ -0,0 +1,4 @@
---
title: reviews
layout: under_construction
---

View file

@ -1,5 +1,5 @@
---
title: 404 not found
title: 404 no encontrado
---
{% extends "_layouts/base.njk" %}

5
es/about.md Normal file
View file

@ -0,0 +1,5 @@
---
title: sobre mí
layout: under_construction
slug_override: acerca-de
---

4
es/blog/index.md Normal file
View file

@ -0,0 +1,4 @@
---
title: blog
layout: under_construction
---

View file

@ -0,0 +1,4 @@
---
title: umihara kawase
layout: under_construction
---

View file

@ -3,10 +3,12 @@ layout: home
title: home
---
#### holaaa
bienvenid@ a mi sitio!! aun no lo termino pero revisa lo que tenga hecho <3 pienso terminar primero:
bienvenid@ a mi sitio!! aún no lo termino <3 pienso terminar primero:
- un feed rss (atom)
- mejor soporte para celulares
- ~~página 404~~
- terminar todas las páginas marcadas como "en construcción"
![rakka hairbush fail](/img/rakka-hairbrush-fail.gif)
por mientras siéntete en casa y revisa lo que quieras.

4
es/reviews/index.md Normal file
View file

@ -0,0 +1,4 @@
---
title: reviews
layout: under_construction
---