-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
medium.php
54 lines (46 loc) · 1.52 KB
/
medium.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Grav\Theme;
use Grav\Common\Theme;
class Haywire extends Theme
{
public static function getSubscribedEvents()
{
return [
'onThemeInitialized' => ['onThemeInitialized', 0]
];
}
public function onThemeInitialized()
{
if ($this->isAdmin()) {
$this->active = false;
return;
}
$this->enable([
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onPageInitialized' => ['onPageInitialized', 0]
]);
}
public function onTwigSiteVariables()
{
// Asset cache busting handler
$manifest = __DIR__ . '/dist/mix-manifest.json';
if (file_exists($manifest)) {
$assets = json_decode(file_get_contents($manifest), true);
$this->grav['assets']->addJs('theme://dist/scripts' . $assets['/js/main.js'],10);
$this->grav['assets']->addCss('theme://dist/scripts' . $assets['/css/app.css'],10);
}
// Add jquery if debugger is enabled
if ($this->config->get('system.debugger.enabled')) {
$this->grav['assets']->addJs('jquery',101);
}
}
public function onPageInitialized()
{
// Redirect to external_url if external page template
$template = $this->grav['page']->template();
if ($template === 'external' && isset($this->grav['page']->header()->external_url)) {
$url = $this->grav['page']->header()->external_url;
$this->grav->redirect($url);
}
}
}