Verified Commit 31f1f986 authored by Carl Schwan's avatar Carl Schwan 🚴
Browse files

remove cache

parent f93e1b49
......@@ -32,10 +32,9 @@ class MainController extends AbstractController
* @Route("/{_locale}", name="app_main_index", requirements={"_locale": "%app.locales%"}, defaults={"_locale": "en"})
* @param Request $request
* @param string $_locale
* @param CdnCache $cdn
* @return Response
*/
public function index(Request $request, string $_locale, CdnCache $cdn): Response
public function index(Request $request, string $_locale): Response
{
if ($request->query->get('site_locale')) {
return $this->redirectToRoute('app_main_index', ['_locale' => $request->query->get('site_locale')]);
......@@ -43,7 +42,6 @@ class MainController extends AbstractController
$applicationsProvider = new ApplicationsProviderFile("index.json");
return $this->render('main/index.html.twig', [
'cdn' => $cdn,
'categories' => $applicationsProvider->getAllCategories(),
'locale' => $_locale
]);
......@@ -55,10 +53,9 @@ class MainController extends AbstractController
* @param Request $request
* @param string $_locale
* @param string $category
* @param CdnCache $cdn
* @return Response
*/
public function category(Request $request, string $_locale, string $category, CdnCache $cdn): Response
public function category(Request $request, string $_locale, string $category): Response
{
if ($request->query->get('site_locale')) {
return $this->redirectToRoute('app_main_category_intl', ['_locale' => $request->query->get('site_locale'), 'category' => $category]);
......@@ -66,7 +63,6 @@ class MainController extends AbstractController
$applicationsProvider = new ApplicationsProviderFile("index.json");
return $this->render('main/category.html.twig', [
'cdn' => $cdn,
'category' => $applicationsProvider->getApplicationsByCategory(ucfirst($category)),
'locale' => $_locale
]);
......@@ -79,10 +75,9 @@ class MainController extends AbstractController
* @param string $_locale
* @param string $category
* @param string $application
* @param CdnCache $cdn
* @return Response
*/
public function application(Request $request, string $_locale, string $category, string $application, CdnCache $cdn): Response
public function application(Request $request, string $_locale, string $category, string $application): Response
{
if ($request->query->get('site_locale')) {
return $this->redirectToRoute('app_main_application_intl', ['_locale' => $request->query->get('site_locale'), 'category' => $category, 'application' => $application]);
......@@ -97,7 +92,6 @@ class MainController extends AbstractController
}
return $this->render('main/application.html.twig', [
'cdn' => $cdn,
'application' => $applicationObj,
'category' => $category,
'locale' => $_locale
......@@ -111,10 +105,9 @@ class MainController extends AbstractController
* @param string $_locale
* @param string $category
* @param string $application
* @param CdnCache $cdn
* @return Response
*/
public function applicationDevelopment(Request $request, string $_locale, string $category, string $application, CdnCache $cdn): Response
public function applicationDevelopment(Request $request, string $_locale, string $category, string $application): Response
{
if ($request->query->get('site_locale')) {
return $this->redirectToRoute('app_main_application_dev_intl', ['_locale' => $request->query->get('site_locale'), 'category' => $category, 'application' => $application]);
......@@ -122,7 +115,6 @@ class MainController extends AbstractController
$application = AppData::fromName($application);
return $this->render('main/applicationDevelopment.html.twig', [
'cdn' => $cdn,
'application' => $application,
'category' => $category,
'locale' => $_locale
......
<?php
/**
* SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace App\Services;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Contracts\Cache\ItemInterface;
class CdnCache
{
/** @var array|null $cssFiles */
private $cssFiles;
/** @var array|null $jsFiles */
private $jsFiles;
public function __construct()
{
$cache = new FilesystemAdapter();
$cache->delete('cdnFiles');
$cdn = 'https://cdn.kde.org';
$cdnPathPrefix = 'aether-devel';
// carl dev config
//$cdn = 'https://kde.carlschwan.eu';
//$cdnPathPrefix = 'build';
$cdnManifest = $cdn . '/' . $cdnPathPrefix . '/version/manifest.json';
$cdnCSSFiles = ['/version/bootstrap.css', '/version/kde-org/applications.css'];
$cdnJSFiles = ['/version/bootstrap.js', '/version/piwikbanner.js', '/version/kde-org/applications.js'];
ini_set('realpath_cache_size', 0);
$cdnFiles = $cache->get('cdnFiles', function (ItemInterface $item) use ($cdnManifest, $cdnPathPrefix, $cdnCSSFiles, $cdnJSFiles) {
$item->expiresAfter(600);
$fileContent = file_get_contents($cdnManifest . "?rrere");
$manifestData = json_decode($fileContent, true);
$convertPaths = function($cdnCSSFile) use ($cdnPathPrefix, $manifestData) {
return $manifestData[$cdnPathPrefix . $cdnCSSFile];
};
return [
'css' => array_map($convertPaths, $cdnCSSFiles),
'js' => array_map($convertPaths, $cdnJSFiles),
];
});
$this->cssFiles = $cdnFiles['css'];
$this->jsFiles = $cdnFiles['js'];
}
public function getCssFiles(): array
{
return $this->cssFiles;
}
public function getJsFiles(): array
{
return $this->jsFiles;
}
}
......@@ -9,9 +9,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
<meta charset="UTF-8">
<title>{% block title %}{% trans %}KDE's Applications{% endtrans %}{% endblock %}</title>
{% block stylesheets %}
{% for file in cdn.cssFiles %}
<link href="https://cdn.kde.org{{ file }}" rel="stylesheet"/>
{% endfor %}
<link href="https://cdn.kde.org/aether-devel/bootstrap.css" rel="stylesheet"/>
<link href="https://cdn.kde.org/aether-devel/kde-org/applications.css" rel="stylesheet"/>
{% endblock %}
<link href="https://cdn.kde.org/breeze-icons/icons.css" rel="stylesheet">
</head>
......@@ -178,9 +177,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
</section>
</footer>
{% block javascripts %}
{% for file in cdn.jsFiles %}
<script src="https://cdn.kde.org{{ file }}"></script>
{% endfor %}
<script src="https://cdn.kde.org/aether-devel/bootstrap.js"></script>
{% endblock %}
<script type="text/javascript">
var _paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(['disableCookies']); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="https://stats.kde.org/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })();
......
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