Skip to content

Commit

Permalink
Search engine indexing support
Browse files Browse the repository at this point in the history
  • Loading branch information
vitkutny committed Mar 7, 2017
1 parent a5690e5 commit 0763191
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,25 @@ services:
setup:
- Pd\AsyncControl\UI\AsyncControlLink::setDefault('Load content', {class: [btn, ajax]})
```

## Search engines

To allow indexing of your site by crawlers you need to add meta tag to your page.

```latte
<meta name="fragment" content="!" n:if="$presenter->getParameter('_escaped_fragment_') === NULL">
```

> If you place into the page www.example.com, the crawler will temporarily map this URL to www.example.com?_escaped_fragment_= and will request this from your server. Your server should then return the HTML snapshot corresponding to www.example.com
When parameter `_escaped_fragment_` is present in url `AsyncControlTrait` will always render its content.

If you want the same behaviour for visitors of your page with disabled JS, add additional meta tag within noscript tag:

```latte
<noscript n:if="$presenter->getParameter('_escaped_fragment_') === NULL">
<meta http-equiv="refresh" content="0;url=?_escaped_fragment_="/>
</noscript>
```

To avoid extra load on your servers and crawlers use these tags only on pages containing controls with trait `AsyncControlTrait`.
6 changes: 5 additions & 1 deletion src/UI/AsyncControlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public function handleAsyncLoad()

public function renderAsync(string $linkMessage = NULL, array $linkAttributes = NULL)
{
if ($this instanceof Control && strpos((string) $this->getPresenter()->getParameter(Presenter::SIGNAL_KEY), sprintf('%s-', $this->getUniqueId())) !== 0) {
if (
$this instanceof Control
&& $this->getPresenter()->getParameter('_escaped_fragment_') === NULL
&& strpos((string) $this->getPresenter()->getParameter(Presenter::SIGNAL_KEY), sprintf('%s-', $this->getUniqueId())) !== 0
) {
$template = $this->createTemplate();
$template->link = new AsyncControlLink($linkMessage, $linkAttributes);
$template->setFile(__DIR__ . '/templates/asyncLoadLink.latte');
Expand Down
2 changes: 1 addition & 1 deletion src/UI/templates/asyncLoadLink.latte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div n:snippet="async">
<a n:href="asyncLoad!" n:attr="(expand) $link->getAttributes()" data-async>
<a n:href="asyncLoad!" n:attr="(expand) $link->getAttributes()" data-async rel="nofollow">
{$link->getMessage()|translate}
</a>
</div>

0 comments on commit 0763191

Please sign in to comment.