Commit f94fef0f authored by Carl Schwan's avatar Carl Schwan 🚴

Simplify the url considerably

parent 8e925b04
Pipeline #33723 canceled with stage
...@@ -26,7 +26,7 @@ if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false ...@@ -26,7 +26,7 @@ if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false
Request::setTrustedHosts([$trustedHosts]); Request::setTrustedHosts([$trustedHosts]);
} }
$kernel = new Kernel('prod', false); $kernel = new Kernel('dev', true);
$request = Request::createFromGlobals(); $request = Request::createFromGlobals();
$response = $kernel->handle($request); $response = $kernel->handle($request);
$response->send(); $response->send();
......
...@@ -48,7 +48,7 @@ class MainController extends AbstractController ...@@ -48,7 +48,7 @@ class MainController extends AbstractController
/** /**
* @Route("/{category}", defaults={"_locale": "en"}) * @Route("/{category}", defaults={"_locale": "en"})
* @Route("/{_locale}/{category}", name="app_main_category_intl", requirements={"_locale": "%app.locales%"}) * @Route("/{_locale}/{category}", name="app_main_category_intl", requirements={"_locale": "%app.locales%", "category": "development|education|games|graphics|internet|multimedia|office|system|utilities|unmaintained"})
* @param Request $request * @param Request $request
* @param string $_locale * @param string $_locale
* @param string $category * @param string $category
...@@ -82,33 +82,52 @@ class MainController extends AbstractController ...@@ -82,33 +82,52 @@ class MainController extends AbstractController
} }
/** /**
* @Route("/{category}/{application}", requirements={"_locale": "%app.locales%"}, defaults={"_locale": "en"}) * @Route("/{application}", requirements={"_locale": "%app.locales%"}, defaults={"_locale": "en"})
* @Route("/{_locale}/{category}/{application}", name="app_main_application_intl", requirements={"_locale": "%app.locales%"}) * @Route("/{_locale}/{application}", name="app_main_application_intl", requirements={"_locale": "%app.locales%"})
* @param Request $request * @param Request $request
* @param string $_locale * @param string $_locale
* @param string $category * @param string $category
* @param string $application * @param string $application
* @return Response * @return Response
*/ */
public function application(Request $request, string $_locale, string $category, string $application): Response public function application(Request $request, string $_locale, string $application): Response
{ {
if ($request->query->get('site_locale')) { if ($request->query->get('site_locale')) {
return $this->redirectToRoute('app_main_application_intl', ['_locale' => $request->query->get('site_locale'), 'category' => $category, 'application' => $application]); return $this->redirectToRoute('app_main_application_intl', [
'_locale' => $request->query->get('site_locale'),
'application' => $application,
]);
} }
$applicationObj = AppData::fromName($application); if (startsWith($application, 'org.kde')) {
return $this->redirectToRoute('app_main_application_intl', [
'_locale' => $_locale,
'application' => substr($application, 8),
]);
}
$applicationObj = AppData::fromName('org.kde.' . $application);
if (!($applicationObj || startsWith($application, 'org'))) { if (!$applicationObj) {
return $this->redirectToRoute('app_main_application_intl', ['_locale' => $_locale, 'category' => $category, 'application' => 'org.kde.' . $application]);
} else if (!$applicationObj) {
throw $this->createNotFoundException('The product does not exist'); throw $this->createNotFoundException('The product does not exist');
} }
return $this->render('main/application.html.twig', [ return $this->render('main/application.html.twig', [
'application' => $applicationObj, 'application' => $applicationObj,
'category' => $category,
'locale' => $_locale, 'locale' => $_locale,
'translations' => $this->getParameter('app.translations'), 'translations' => $this->getParameter('app.translations'),
]); ]);
} }
/**
* @Route("/{category}/{application}", requirements={"_locale": "%app.locales%"}, defaults={"_locale": "en"})
* @Route("/{_locale}/{category}/{application}", name="riuehiiuhiu", requirements={"_locale": "%app.locales%"})
*/
public function redirectOldCategory(Request $request, string $_locale, string $category, string $application): Response
{
return $this->redirectToRoute('app_main_application_intl', [
'_locale' => $_locale,
'application' => $application,
]);
}
} }
...@@ -31,13 +31,13 @@ SPDX-License-Identifier: AGPL-3.0-or-later ...@@ -31,13 +31,13 @@ SPDX-License-Identifier: AGPL-3.0-or-later
<div class="app text-center col-12 col-sm-6 col-md-4 col-lg-3 p-2"> <div class="app text-center col-12 col-sm-6 col-md-4 col-lg-3 p-2">
<div class="p-3 h-100"> <div class="p-3 h-100">
<div aria-hidden="true"> <div aria-hidden="true">
<a href="{{ path('app_main_application_intl', {'_locale': locale, 'category': category.name | lower, 'application' : application.id }) }}"> <a href="{{ path('app_main_application_intl', {'_locale': locale, 'application' : application.simplifiedId }) }}">
<img width="48" height="48" src="{{ asset('icons/' ~ application.icon) }}" <img width="48" height="48" src="{{ asset('icons/' ~ application.icon) }}"
loading="lazy" loading="lazy"
alt="{{ application.name | l10n(locale) }}" title="{{ application.name | l10n(locale) }}"/> alt="{{ application.name | l10n(locale) }}" title="{{ application.name | l10n(locale) }}"/>
</a> </a>
</div> </div>
<a href="{{ path('app_main_application_intl', {'_locale': locale, 'category': category.name | lower, 'application' : application.id }) }}"> <a href="{{ path('app_main_application_intl', {'_locale': locale, 'application' : application.simplifiedId }) }}">
{{ application.name | l10n(locale) }} {{ application.name | l10n(locale) }}
</a> </a>
<p>{{ application.genericName | l10n(locale) }}</p> <p>{{ application.genericName | l10n(locale) }}</p>
...@@ -53,12 +53,12 @@ SPDX-License-Identifier: AGPL-3.0-or-later ...@@ -53,12 +53,12 @@ SPDX-License-Identifier: AGPL-3.0-or-later
<div class="app text-center col-12 col-sm-6 col-md-4 col-lg-3 p-2"> <div class="app text-center col-12 col-sm-6 col-md-4 col-lg-3 p-2">
<div class="p-3 h-100"> <div class="p-3 h-100">
<div aria-hidden="true"> <div aria-hidden="true">
<a href="{{ path('app_main_application_intl', {'_locale': locale, 'category': category.name | lower, 'application' : application.id }) }}"> <a href="{{ path('app_main_application_intl', {'_locale': locale, 'application' : application.simplifiedId }) }}">
<img width="48" height="48" src="{{ asset('icons/' ~ application.icon) }}" <img width="48" height="48" src="{{ asset('icons/' ~ application.icon) }}"
alt="{{ application.name | l10n(locale) }}" title="{{ application.name | l10n(locale) }}"/> alt="{{ application.name | l10n(locale) }}" title="{{ application.name | l10n(locale) }}"/>
</a> </a>
</div> </div>
<a href="{{ path('app_main_application_intl', {'_locale': locale, 'category': category.name | lower, 'application' : application.id }) }}"> <a href="{{ path('app_main_application_intl', {'_locale': locale, 'category': category.name | lower, 'application' : application.simplifiedId }) }}">
{{ application.name | l10n(locale) }} {{ application.name | l10n(locale) }}
</a> </a>
<p>{{ application.genericName | l10n(locale) }}</p> <p>{{ application.genericName | l10n(locale) }}</p>
......
...@@ -11,13 +11,13 @@ SPDX-License-Identifier: AGPL-3.0-or-later ...@@ -11,13 +11,13 @@ SPDX-License-Identifier: AGPL-3.0-or-later
{% block title %}{{ name }}{% endblock %} {% block title %}{{ name }}{% endblock %}
{% block description %}{{ application.summary | l10n(locale) }}{% endblock %} {% block description %}{{ application.summary | l10n(locale) }}{% endblock %}
{% block image %}{% if application.screenshots | length > 0 %}{{ application.screenshots[0].sourceImage }}{% else %}https://kde.org/products/apps.png{% endif %}{% endblock %} {% block image %}{% if application.screenshots | length > 0 %}{{ application.screenshots[0].sourceImage }}{% else %}https://kde.org/products/apps.png{% endif %}{% endblock %}
{% block canonical %}https://kde.org{{ path('app_main_application_intl', {'_locale': locale, 'category': category, 'application': application.id}) }}{% endblock %} {% block canonical %}https://kde.org{{ path('app_main_application_intl', {'_locale': locale, 'application': application.simplifiedId}) }}{% endblock %}
{% block donation %}#{{ name }}{% endblock %} {% block donation %}#{{ name }}{% endblock %}
{% block hreflang %} {% block hreflang %}
<link rel="alternate" href="https://kde.org{{ path('app_main_application_intl', {'_locale': 'en', 'category': category | lower, 'application' : application.id }) }}" hreflang="en" /> <link rel="alternate" href="https://kde.org{{ path('app_main_application_intl', {'_locale': 'en', 'application' : application.simplifiedId }) }}" hreflang="en" />
{% for translation in translations %} {% for translation in translations %}
<link rel="alternate" href="https://kde.org{{ path('app_main_application_intl', {'_locale': translation, 'category': category, 'application' : application.id }) }}" hreflang="{{ translation }}" /> <link rel="alternate" href="https://kde.org{{ path('app_main_application_intl', {'_locale': translation, 'application' : application.simplifiedId }) }}" hreflang="{{ translation }}" />
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
...@@ -37,7 +37,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later ...@@ -37,7 +37,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
<a href="{{ path('app_main_index', {'_locale': locale}) }}">{% trans %}KDE's Applications{% endtrans %}</a> <a href="{{ path('app_main_index', {'_locale': locale}) }}">{% trans %}KDE's Applications{% endtrans %}</a>
{{ name }} {{ name }}
</h1> </h1>
<a href="{{ path('app_main_category_intl', {'_locale': locale, 'category': category}) }}"> <a href="{{ path('app_main_category_intl', {'_locale': locale, 'category': application.primaryCategory | lower }) }}">
{{ application.primaryCategory | trans }} {{ application.primaryCategory | trans }}
</a> </a>
</div> </div>
...@@ -171,7 +171,7 @@ AppStream application stores. You can also use your distribution's package manag ...@@ -171,7 +171,7 @@ AppStream application stores. You can also use your distribution's package manag
<h2 class="mb-0">{% trans %}Releases{% endtrans %}</h2> <h2 class="mb-0">{% trans %}Releases{% endtrans %}</h2>
{% endif %} {% endif %}
{% for release in application.releases %} {% for release in application.releases %}
<details class="release mb-5" {% if loop.first %}open="true"{% endif %}> <details class="release" {% if loop.first %}open="true"{% endif %}>
<summary class="mt-1 h5">{{ release.version }} <small class="text-muted">{{ release.timestamp | format_date('long', locale=locale) }}</small></summary> <summary class="mt-1 h5">{{ release.version }} <small class="text-muted">{{ release.timestamp | format_date('long', locale=locale) }}</small></summary>
{% if release.description %} {% if release.description %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment