Для ресурсов добавлены версии по содержимому
This commit is contained in:
parent
f131f53ea7
commit
d1b9124405
@ -2,6 +2,7 @@
|
||||
|
||||
use Homepage\HtmlPrettierBundle\HtmlPrettierBundle;
|
||||
use Homepage\SiteMapBundle\SiteMapBundle;
|
||||
use Homepage\TwigExtensionBundle\TwigExtensionBundle;
|
||||
use Sculpin\Bundle\SculpinBundle\HttpKernel\AbstractKernel;
|
||||
|
||||
class SculpinKernel extends AbstractKernel
|
||||
@ -9,6 +10,7 @@ class SculpinKernel extends AbstractKernel
|
||||
protected function getAdditionalSculpinBundles(): array
|
||||
{
|
||||
return [
|
||||
TwigExtensionBundle::class,
|
||||
SiteMapBundle::class,
|
||||
HtmlPrettierBundle::class,
|
||||
];
|
||||
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Homepage\TwigExtensionBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
class TwigExtensionExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
8
bundle/TwigExtensionBundle/Resources/config/services.yml
Normal file
8
bundle/TwigExtensionBundle/Resources/config/services.yml
Normal file
@ -0,0 +1,8 @@
|
||||
services:
|
||||
homepage.twig_extension:
|
||||
class: \Homepage\TwigExtensionBundle\TwigExtension
|
||||
arguments:
|
||||
- '%sculpin.output_dir%'
|
||||
public: yes
|
||||
tags:
|
||||
- { name: twig.extension }
|
42
bundle/TwigExtensionBundle/TwigExtension.php
Normal file
42
bundle/TwigExtensionBundle/TwigExtension.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Homepage\TwigExtensionBundle;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class TwigExtension extends AbstractExtension
|
||||
{
|
||||
private $outputDir;
|
||||
|
||||
public function __construct(string $outputDir)
|
||||
{
|
||||
$this->outputDir = $outputDir;
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('hashed_asset', [$this, 'createHashedFileLink']),
|
||||
];
|
||||
}
|
||||
|
||||
public function createHashedFileLink(string $path): string
|
||||
{
|
||||
$fullPath = $this->join($this->outputDir, $path);
|
||||
$realPath = realpath($fullPath);
|
||||
|
||||
if (!file_exists($realPath)) {
|
||||
return sprintf('%s?v=%s', $path, time());
|
||||
}
|
||||
|
||||
$hash = md5_file($realPath);
|
||||
|
||||
return sprintf('%s?v=%s', $path, $hash);
|
||||
}
|
||||
|
||||
private function join(string $base, string $path): string
|
||||
{
|
||||
return $path ? rtrim($base, '/').'/'.ltrim($path, '/') : $base;
|
||||
}
|
||||
}
|
9
bundle/TwigExtensionBundle/TwigExtensionBundle.php
Normal file
9
bundle/TwigExtensionBundle/TwigExtensionBundle.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Homepage\TwigExtensionBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class TwigExtensionBundle extends Bundle
|
||||
{
|
||||
}
|
@ -3,7 +3,7 @@ layout: default
|
||||
description: Личный сайт Антона Вахрушева
|
||||
---
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="/static/index.css?v={{ date().timestamp }}">
|
||||
<link rel="stylesheet" href="{{ hashed_asset('/static/index.css') }}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{% extends 'internal.html.twig' %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="/static/layout_album.css?v={{ date().timestamp }}">
|
||||
<link rel="stylesheet" href="{{ hashed_asset('/static/layout_album.css') }}">
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
{% include 'head.twig' %}
|
||||
<link rel="stylesheet" href="/static/layout_default.css?v={{ date().timestamp }}">
|
||||
<link rel="stylesheet" href="{{ hashed_asset('/static/layout_default.css') }}">
|
||||
{% block css %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
{% include 'counters.twig' %}
|
||||
|
||||
<script async src="/static/layout_default.js?v={{ date().timestamp }}"></script>
|
||||
<script async src="{{ hashed_asset('/static/layout_default.js') }}"></script>
|
||||
{% block js %}{% endblock %}
|
||||
|
||||
{% include 'font-awesome.twig' %}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
{% include 'head.twig' %}
|
||||
<link rel="stylesheet" href="/static/layout_internal.css?v={{ date().timestamp }}">
|
||||
<link rel="stylesheet" href="{{ hashed_asset('/static/layout_internal.css') }}">
|
||||
{% block css %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
{% include 'counters.twig' %}
|
||||
|
||||
<script async src="/static/layout_internal.js?v={{ date().timestamp }}"></script>
|
||||
<script async src="{{ hashed_asset('/static/layout_internal.js') }}"></script>
|
||||
{% block js %}{% endblock %}
|
||||
|
||||
{% include 'font-awesome.twig' %}
|
||||
|
@ -5,11 +5,11 @@ description: Несколько фактов об авторе
|
||||
---
|
||||
|
||||
{% block js %}
|
||||
<script async src="/static/about_me.js?v={{ date().timestamp }}"></script>
|
||||
<script async src="{{ hashed_asset('/static/about_me.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="/static/about_me.css?v={{ date().timestamp }}">
|
||||
<link rel="stylesheet" href="{{ hashed_asset('/static/about_me.css') }}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -3,7 +3,7 @@ layout: default
|
||||
description: Личный сайт Антона Вахрушева
|
||||
---
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="/static/index.css?v={{ date().timestamp }}">
|
||||
<link rel="stylesheet" href="{{ hashed_asset('/static/index.css') }}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -5,11 +5,11 @@ description: Демо-версия электронной гадалки Шен
|
||||
---
|
||||
|
||||
{% block js %}
|
||||
<script async src="/static/predictor.js?v={{ date().timestamp }}"></script>
|
||||
<script async src="{{ hashed_asset('/static/predictor.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="/static/predictor.css?v={{ date().timestamp }}">
|
||||
<link rel="stylesheet" href="{{ hashed_asset('/static/predictor.css') }}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
Loading…
Reference in New Issue
Block a user