Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow omitting of generator meta tag and x-powered-by header #2195

Merged
merged 1 commit into from
Nov 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/bolt/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ date_format: 'F j, Y H:i'
# You can set a preference to omit background images on the login screen.
omit_backgrounds: true

# If you're a party-pooper who wants to hide the `generator` meta tag and
# `x-powered-by` header, set these to true
omit_meta_generator_tag: false
omit_powered_by_header: false

# If your site is reachable under different urls (say, both blog.example.org/
# as well as example.org/), its a good idea to set one of these as the
# canonical, so its clear which is the primary address of the site.
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration/Parser/GeneralParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ protected function getDefaultConfig(): array
'forbidden' => 'helpers/page_403.html.twig',
'internal_server_error' => 'helpers/page_500.html.twig',
'omit_backgrounds' => false,
'omit_powered_by_header' => false,
'omit_meta_generator_tag' => false,
];
}
}
28 changes: 19 additions & 9 deletions src/Event/Subscriber/WidgetSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Bolt\Event\Subscriber;

use Bolt\Canonical;
use Bolt\Configuration\Config;
use Bolt\Widget\BoltHeaderWidget;
use Bolt\Widget\CanonicalLinkWidget;
use Bolt\Widget\Injector\RequestZone;
Expand All @@ -25,10 +26,14 @@ class WidgetSubscriber implements EventSubscriberInterface
/** @var Canonical */
private $canonical;

public function __construct(Widgets $widgets, Canonical $canonical)
/** @var Config */
private $config;

public function __construct(Widgets $widgets, Canonical $canonical, Config $config)
{
$this->widgets = $widgets;
$this->canonical = $canonical;
$this->config = $config;
}

/**
Expand All @@ -37,16 +42,21 @@ public function __construct(Widgets $widgets, Canonical $canonical)
public function onKernelRequest(RequestEvent $event): void
{
$this->widgets->registerWidget(new CanonicalLinkWidget($this->canonical));
$this->widgets->registerWidget(new BoltHeaderWidget());

$metaTagSnippet = new SnippetWidget(
'<meta name="generator" content="Bolt">',
'Meta Generator tag snippet',
Target::END_OF_HEAD,
RequestZone::FRONTEND
);
if (! $this->config->get('general/omit_powered_by_header')) {
$this->widgets->registerWidget(new BoltHeaderWidget());
}

if (! $this->config->get('general/omit_meta_generator_tag')) {
$metaTagSnippet = new SnippetWidget(
'<meta name="generator" content="Bolt">',
'Meta Generator tag snippet',
Target::END_OF_HEAD,
RequestZone::FRONTEND
);

$this->widgets->registerWidget($metaTagSnippet);
$this->widgets->registerWidget($metaTagSnippet);
}
}

/**
Expand Down