-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
executable file
·34 lines (28 loc) · 880 Bytes
/
plugin.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
<?php
class pluginPrefetchStaticPages extends Plugin {
// Hook for head of document
public function siteHead()
{
global $page;
global $site;
global $staticContent;
global $WHERE_AM_I;
$theURL = $page->permalink();
// Prolly overkill. Build static pages array if $staticContent is empty
$pages = empty( $staticContent ) ? buildStaticPages() : $staticContent;
// make a link for root/home if not the current page
$html = $WHERE_AM_I !== 'home' ? self::makeLink( DOMAIN ) : '';
// generate html links for static pages
foreach ( $pages as $resource ){
$permalink = $resource->permalink();
// skip if current page
if ( $permalink === $theURL ) continue;
$html .= self::makeLink( $permalink );
}
return $html;
}
private static function makeLink( $url )
{
return '<link rel="prefetch" as="document" href="' . $url . '">'.PHP_EOL;
}
}