sigwinhq / yassg

Yet Another Static Site Generator
MIT License
3 stars 0 forks source link

Hugo to YASSG #84

Closed brankol closed 8 months ago

brankol commented 2 years ago

Global config

Hugo: {{ .Site.Title }} Twig: {{ site.title }}

After adding config/twig.yaml:

twig:
    globals:
        site:
            title: Sigwin
brankol commented 2 years ago

Environment mode

Hugo: {{ if .Site.IsServer }} Twig {% if app.environment == 'dev' %}

brankol commented 2 years ago

Partials/Includes

Hugo:

{{ .Scratch.Set "source" "contact" }}
{{ .Scratch.Set "button_text" "Send" }}
{{ partial "contact-form.html" . }}

Twig:

{% include 'includes/contact_form.html.twig' with {
    source: 'contact',
    button_text: 'Send',
} only %}
brankol commented 2 years ago

Main navigation

Hugo:

{{ $currentPage := . }}
{{ range .Site.Menus.main }}
    {{ $active := in $currentPage.RelPermalink .URL }}
    <a
        href="{{ .URL }}"
        class="{{ if $active }} active{{ end }}"
    >{{ .Name }} {{ .Post }}</a>
{{ end }}

Twig:

{% set current_route = app.request.attributes.get('_route') %}
{% for route in site.menu.main %}
    {% set page = yassg_find_one_by('pages', {condition: {'item.slug': route}}) %}
    <a
        href="{{ path(route) }}"
        class="{% if route == current_route %} active{% endif %}"
    >{{ page.title }}</a>
{% endfor %}
dkarlovi commented 8 months ago

Non-actionable.