Skip to content

Commit 0763191

Browse files
committed
Search engine indexing support
1 parent a5690e5 commit 0763191

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ services:
5858
setup:
5959
- Pd\AsyncControl\UI\AsyncControlLink::setDefault('Load content', {class: [btn, ajax]})
6060
```
61+
62+
## Search engines
63+
64+
To allow indexing of your site by crawlers you need to add meta tag to your page.
65+
66+
```latte
67+
<meta name="fragment" content="!" n:if="$presenter->getParameter('_escaped_fragment_') === NULL">
68+
```
69+
70+
> 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
71+
72+
When parameter `_escaped_fragment_` is present in url `AsyncControlTrait` will always render its content.
73+
74+
If you want the same behaviour for visitors of your page with disabled JS, add additional meta tag within noscript tag:
75+
76+
```latte
77+
<noscript n:if="$presenter->getParameter('_escaped_fragment_') === NULL">
78+
<meta http-equiv="refresh" content="0;url=?_escaped_fragment_="/>
79+
</noscript>
80+
```
81+
82+
To avoid extra load on your servers and crawlers use these tags only on pages containing controls with trait `AsyncControlTrait`.

src/UI/AsyncControlTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public function handleAsyncLoad()
4343

4444
public function renderAsync(string $linkMessage = NULL, array $linkAttributes = NULL)
4545
{
46-
if ($this instanceof Control && strpos((string) $this->getPresenter()->getParameter(Presenter::SIGNAL_KEY), sprintf('%s-', $this->getUniqueId())) !== 0) {
46+
if (
47+
$this instanceof Control
48+
&& $this->getPresenter()->getParameter('_escaped_fragment_') === NULL
49+
&& strpos((string) $this->getPresenter()->getParameter(Presenter::SIGNAL_KEY), sprintf('%s-', $this->getUniqueId())) !== 0
50+
) {
4751
$template = $this->createTemplate();
4852
$template->link = new AsyncControlLink($linkMessage, $linkAttributes);
4953
$template->setFile(__DIR__ . '/templates/asyncLoadLink.latte');

src/UI/templates/asyncLoadLink.latte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div n:snippet="async">
2-
<a n:href="asyncLoad!" n:attr="(expand) $link->getAttributes()" data-async>
2+
<a n:href="asyncLoad!" n:attr="(expand) $link->getAttributes()" data-async rel="nofollow">
33
{$link->getMessage()|translate}
44
</a>
55
</div>

0 commit comments

Comments
 (0)