Skip to content

Commit

Permalink
Fixed issues and missing handling of the languages support
Browse files Browse the repository at this point in the history
  • Loading branch information
awinterstein committed Dec 3, 2024
1 parent 87293ea commit 2656eaa
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 81 deletions.
7 changes: 0 additions & 7 deletions src/js/lang.js

This file was deleted.

2 changes: 1 addition & 1 deletion static/css/main.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion static/js/lang.js

This file was deleted.

41 changes: 13 additions & 28 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@
</div>
<div class="flex-1 flex items-center">
<div class="flex-shrink-0 flex items-center ml-2">
<a href="{{ config.base_url | safe }}" class="text-xl text-gray-800 dark:text-white">{{config.extra.navbar.title}}</a>
<a href="{{ config.base_url | safe }}{% if lang != config.default_language%}/{{ lang }}{% endif %}" class="text-xl text-gray-800 dark:text-white">{{config.extra.navbar.title}}</a>
</div>
<div class="hidden sm:block sm:ml-6">
<div class="nav-links flex space-x-4">
<!-- Current: "bg-gray-900 text-white", Default: "text-gray-300 hover:bg-gray-700 hover:text-white" -->
{% for item in config.extra.navbar.items %}
{% if lang == item.lang %}
{% for link in item.links %}
{%if lang == config.default_language %}{% set language_url_part = '' %}{% else %}{% set language_url_part = lang %}{% endif %} {# Empty for default language and language for others. #}
<a href="{{ config.base_url | trim_end_matches(pat='/') | safe }}/{{ link.url }}"
{% if current_path and ((link.url != '' and link.url in current_path) or link.url == '' and current_path == '/') %}
{% if current_path and ((link.url != language_url_part and link.url in current_path) or (link.url | trim_end_matches(pat='/') == language_url_part and current_path | trim_start_matches(pat='/') | trim_end_matches(pat='/') == language_url_part )) %}
class="bg-gray-900 text-white px-3 py-2 rounded-md text-sm font-medium" {# Highlight button, if button URL is part of the current path. #}
{% else %}
class="text-gray-800 dark:text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium"
Expand Down Expand Up @@ -197,30 +197,18 @@
{% endif %}

{% if config.extra.enable_multilingue %}

{# Get the non-active language from the languages map. This only works, as long as there are no more than two languages defined. #}
{% for key, item in config.languages -%}
{% set_global other_language = key -%}
{% endfor -%}

<!-- Language change button -->
<div class="flex p-2 ml-4 relative">
<button id="switch-lang" type="button"
class="bg-gray-200 text-gray-800 hover:text-gray-900 dark:bg-gray-800 dark:text-gray-400 dark:hover:text-white p-1 rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white">
<svg
class="w-6 h-6 bg-gray-200 text-gray-800 hover:text-gray-900 dark:bg-gray-800 dark:text-gray-400 dark:hover:text-white"
fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9">
</path>
</svg>
</button>
<div id="switch-lang-panel"
class="hidden absolute top-12 -left-1/2 z-10 p-4 rounded-lg divide-y bg-gray-300 dark:bg-gray-800 text-gray-800 dark:text-gray-400 flex flex-col w-28 ">
<span class="sr-only">Switch Lang</span>
{% for item in config.extra.lang.items %}
{% if lang == item.lang %}
{% for link in item.links %}
<a class="flex justify-center py-2 hover:text-gray-800 dark:hover:text-white"
href="{{ link.base_url }}">{{ link.name }}</a>
{% endfor %}
{% endif %}
{% endfor %}
</div>
<a href="{% if current_path %}{% if lang != config.default_language %}{{ current_path | trim_start_matches(pat='/'~lang) }}{% else %}{{ '/' ~ other_language ~ current_path }}{% endif %}{% endif %}"
class="bg-gray-200 text-gray-800 hover:text-gray-900 dark:bg-gray-800 dark:text-gray-400 dark:hover:text-white p-1 rounded-full">
{% if config.extra.languages[lang].symbol %}{{ config.extra.languages[lang].symbol }}{% else %}{{ lang }}{% endif %}
</a>
</div>
{% endif %}
</div>
Expand Down Expand Up @@ -294,9 +282,6 @@
<script src="/search_index.{{lang}}.js"></script>
<script defer src="{{ config.base_url | trim_end_matches(pat='/') | safe }}/js/search.js"></script>
{% endif %}
{% if config.extra.enable_multilingue %}
<script defer src="{{ config.base_url | trim_end_matches(pat='/') | safe }}/js/lang.js"></script>
{% endif %}
{% block extra_js %}
{% endblock extra_js %}
</body>
Expand Down
10 changes: 5 additions & 5 deletions templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
{% endmacro %}

<!-- Shows the given skills that are part of a project. -->
{% macro project_list_skills(skills) %}
{% macro project_list_skills(skills, lang) %}
<div class="flex sm:flex-row flex-col flex-wrap sm:gap-x-7">
{% for skill in skills %}
<a class="text-gray-900 dark:text-gray-400 flex py-1 items-center"
href="{{ get_taxonomy_url(kind='skills', name=skill) }}">
href="{{ get_taxonomy_url(kind='skills', name=skill, lang=lang) }}">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z">
Expand All @@ -58,7 +58,7 @@
</div>
{% endmacro %}

<!-- Shows the overview or full tile for a project page. -->
<!-- Shows the overview tile for a project page. -->
{% macro project_tile(page) %}
<div
class="border border-2 border-gray-200 dark:border-black rounded-xl p-5 shadow-2xl transform transition duration-500 hover:scale-105 bg-gray-200 dark:bg-gray-800">
Expand All @@ -73,7 +73,7 @@ <h2 class="text-2xl text-bold pt-0"><a href='{{ page.permalink }}'>{{ page.title
<span>
{% for project in page.taxonomies.projects %}
<a class="text-gray-900 dark:text-gray-400 flex py-1 items-center"
href="{{ get_taxonomy_url(kind='projects', name=project) }}">
href="{{ get_taxonomy_url(kind='projects', name=project, lang=lang) }}">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
Expand Down Expand Up @@ -125,7 +125,7 @@ <h2 class="text-2xl text-bold pt-0"><a href='{{ page.permalink }}'>{{ page.title
<!-- Skills & Technologies Section -->
{% if page.taxonomies.skills %}
<h2>Skills & Technologies</h2>
{{ macros::project_list_skills(skills=page.taxonomies.skills) }}
{{ macros::project_list_skills(skills=page.taxonomies.skills, lang=lang) }}
{% endif %}

</span>
Expand Down
19 changes: 3 additions & 16 deletions templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1><a href='{{ page.permalink }}'>{{ page.title }}</a></h1>
<span>
{% for project in page.taxonomies.projects %}
<a class="text-gray-900 dark:text-gray-400 flex py-1 items-center"
href="{{ get_taxonomy_url(kind='projects', name=project) }}">
href="{{ get_taxonomy_url(kind='projects', name=project, lang=lang) }}">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
Expand Down Expand Up @@ -56,22 +56,9 @@ <h1><a href='{{ page.permalink }}'>{{ page.title }}</a></h1>
{{ page.content | safe }}
</div>

<!-- Categories and Tags -->
<!-- Skills & Technologies Section -->
{% if page.taxonomies.skills %}
<h2>Skills & Technologies</h2>
<div class="flex sm:flex-row flex-col flex-wrap sm:gap-x-7">
{% for skill in page.taxonomies.skills %}
<a class="text-gray-900 dark:text-gray-400 flex py-1 items-center"
href="{{ get_taxonomy_url(kind='skills', name=skill) }}">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z">
</path>
</svg>
<span class="pl-1">{{skill}}</span>
</a>
{% endfor %}
</div>
{{ macros::project_list_skills(skills=page.taxonomies.skills, lang=lang) }}
{% endif %}
</div>

Expand Down
2 changes: 1 addition & 1 deletion templates/projects/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1 class="text-2xl text-bold">{{ page.title }}</h1>

<!-- List the top projects -->
<div class="flex flex-col gap-y-6 w-full sm:w-2/3 mt-10">
{% set categories = get_taxonomy(kind="projects") %}
{% set categories = get_taxonomy(kind="projects", lang=lang) %}
{% for project_type in categories.items %}
{% for project_page in project_type.pages %}
{%if project_page.extra.top_project%}
Expand Down
4 changes: 2 additions & 2 deletions templates/skills/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ <h1 class="text-2xl text-bold">{{ page.title }}</h1>
<div class="text-bold mt-4">{{ page.content | safe }}</div>

{% if config.extra.skills.main_skills_threshold %}
{% if config.extra.skills.main_skills_heading %}<h2> {{ config.extra.skills.main_skills_heading }}</h2>{% endif %}
{% if config.extra.skills.main_skills_heading[lang] %}<h2> {{ config.extra.skills.main_skills_heading[lang] }}</h2>{% endif %}
{{ macros::terms_list_skills_main(terms=terms, threshold=config.extra.skills.main_skills_threshold) }}

{% if config.extra.skills.other_skills_heading %}<h2>{{ config.extra.skills.other_skills_heading }}</h2>{% endif %}
{% if config.extra.skills.other_skills_heading[lang] %}<h2>{{ config.extra.skills.other_skills_heading[lang] }}</h2>{% endif %}
{{ macros::terms_list_skills_other(terms=terms, threshold=config.extra.skills.main_skills_threshold) }}
{% else %}
{{ macros::terms_list_skills(terms=terms) }}
Expand Down
36 changes: 17 additions & 19 deletions theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,29 @@ homepage = "https://www.winterstein.biz"
enable_search = false
enable_multilingue = false

[extra.lang]
items = [
{ lang = "en", links = [
{ base_url = "/", name = "English" },
{ base_url = "/fr", name = "French" }
] },
{ lang = "fr", links = [
{ base_url = "/", name = "Anglais" },
{ base_url = "/fr", name = "Français" }
] }
]
[extra.languages.en]
symbol = "🇬🇧"

[extra.languages.de]
symbol = "🇩🇪"

[extra.languages.fr]
symbol = "🇫🇷"


[extra.navbar]
title = "Project Portfolio"
items = [
{ lang = "en", links = [
{ url = "", name = "Home" },
{ url = "projects", name = "Projects" },
{ url = "skills", name = "Skills" }
{ url = "skills", name = "Skills" },
] },
{ lang = "de", links = [
{ url = "de", name = "Home" },
{ url = "de/projects", name = "Projekte" },
{ url = "de/skills", name = "Qualifikationen" },
] },
{ lang = "fr", links = [
{ url = "fr", name = "Accueil" },
{ url = "fr/categories", name = "Categories" },
{ url = "fr/tags", name = "Tags" }
] }
]

[extra.sidebar]
Expand Down Expand Up @@ -85,5 +83,5 @@ manifest = "/icons/site.webmanifest"
# Configuration parameters for the skills taxonomy overview page
[extra.skills]
#main_skills_threshold = 5 # Set this variable to show all skills with at least n projects as main skills
#main_skills_heading = "Main Skills" # The heading for the main skills list (only relevant, if main_skills_threshold is set)
#other_skills_heading = "Additional Skills" # The heading for the list of the other skills (only relevant, if main_skills_threshold is set)
#main_skills_heading = { en = "Main Skills", de = "Top-Fähigkeiten" } # The heading for the main skills list (only relevant, if main_skills_threshold is set)
#other_skills_heading = { en = "Additional Skills", de = "Weitere Fähigkeiten" } # The heading for the list of the other skills (only relevant, if main_skills_threshold is set)
1 change: 0 additions & 1 deletion update-css.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ elif command -v docker >/dev/null; then
sh -c "uglifyjs ./src/js/main.js --compress --mangle -o ./static/js/main.js &&
uglifyjs ./src/js/page.js --compress --mangle -o ./static/js/page.js &&
uglifyjs ./src/js/search.js --compress --mangle -o ./static/js/search.js &&
uglifyjs ./src/js/lang.js --compress --mangle -o ./static/js/lang.js
${TAILWINDCSS_COMMAND}" || exit 3


Expand Down

0 comments on commit 2656eaa

Please sign in to comment.