Для ресурсов добавлены версии по содержимому
This commit is contained in:
parent
f131f53ea7
commit
d1b9124405
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use Homepage\HtmlPrettierBundle\HtmlPrettierBundle;
|
use Homepage\HtmlPrettierBundle\HtmlPrettierBundle;
|
||||||
use Homepage\SiteMapBundle\SiteMapBundle;
|
use Homepage\SiteMapBundle\SiteMapBundle;
|
||||||
|
use Homepage\TwigExtensionBundle\TwigExtensionBundle;
|
||||||
use Sculpin\Bundle\SculpinBundle\HttpKernel\AbstractKernel;
|
use Sculpin\Bundle\SculpinBundle\HttpKernel\AbstractKernel;
|
||||||
|
|
||||||
class SculpinKernel extends AbstractKernel
|
class SculpinKernel extends AbstractKernel
|
||||||
@ -9,6 +10,7 @@ class SculpinKernel extends AbstractKernel
|
|||||||
protected function getAdditionalSculpinBundles(): array
|
protected function getAdditionalSculpinBundles(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
TwigExtensionBundle::class,
|
||||||
SiteMapBundle::class,
|
SiteMapBundle::class,
|
||||||
HtmlPrettierBundle::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: Личный сайт Антона Вахрушева
|
description: Личный сайт Антона Вахрушева
|
||||||
---
|
---
|
||||||
{% block css %}
|
{% block css %}
|
||||||
<link rel="stylesheet" href="/static/index.css?v={{ date().timestamp }}">
|
<link rel="stylesheet" href="{{ hashed_asset('/static/index.css') }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% extends 'internal.html.twig' %}
|
{% extends 'internal.html.twig' %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
<link rel="stylesheet" href="/static/layout_album.css?v={{ date().timestamp }}">
|
<link rel="stylesheet" href="{{ hashed_asset('/static/layout_album.css') }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
{% include 'head.twig' %}
|
{% 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 %}
|
{% block css %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
{% include 'counters.twig' %}
|
{% 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 %}
|
{% block js %}{% endblock %}
|
||||||
|
|
||||||
{% include 'font-awesome.twig' %}
|
{% include 'font-awesome.twig' %}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
{% include 'head.twig' %}
|
{% 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 %}
|
{% block css %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
{% include 'counters.twig' %}
|
{% 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 %}
|
{% block js %}{% endblock %}
|
||||||
|
|
||||||
{% include 'font-awesome.twig' %}
|
{% include 'font-awesome.twig' %}
|
||||||
|
@ -5,11 +5,11 @@ description: Несколько фактов об авторе
|
|||||||
---
|
---
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
<script async src="/static/about_me.js?v={{ date().timestamp }}"></script>
|
<script async src="{{ hashed_asset('/static/about_me.js') }}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
<link rel="stylesheet" href="/static/about_me.css?v={{ date().timestamp }}">
|
<link rel="stylesheet" href="{{ hashed_asset('/static/about_me.css') }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -3,7 +3,7 @@ layout: default
|
|||||||
description: Личный сайт Антона Вахрушева
|
description: Личный сайт Антона Вахрушева
|
||||||
---
|
---
|
||||||
{% block css %}
|
{% block css %}
|
||||||
<link rel="stylesheet" href="/static/index.css?v={{ date().timestamp }}">
|
<link rel="stylesheet" href="{{ hashed_asset('/static/index.css') }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -5,11 +5,11 @@ description: Демо-версия электронной гадалки Шен
|
|||||||
---
|
---
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
<script async src="/static/predictor.js?v={{ date().timestamp }}"></script>
|
<script async src="{{ hashed_asset('/static/predictor.js') }}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
<link rel="stylesheet" href="/static/predictor.css?v={{ date().timestamp }}">
|
<link rel="stylesheet" href="{{ hashed_asset('/static/predictor.css') }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
Loading…
Reference in New Issue
Block a user