diff --git a/src/Http/WebApp/WebAppView.php b/src/Http/WebApp/WebAppView.php index 5035e41ca..070c75131 100644 --- a/src/Http/WebApp/WebAppView.php +++ b/src/Http/WebApp/WebAppView.php @@ -107,6 +107,13 @@ class WebAppView */ protected $foot = []; + /** + * A map of tags to be generated. + * + * @var array + */ + protected $links = []; + /** * @var CompilerInterface */ @@ -219,6 +226,31 @@ class WebAppView $this->foot[] = $string; } + /** + * Configure a tag. + * + * @param string $relation + * @param string $target + */ + public function link($relation, $target) + { + $this->links[$relation] = $target; + } + + /** + * Configure the canonical URL for this page. + * + * This will signal to search engines what URL should be used for this + * content, if it can be found under multiple addresses. This is an + * important tool to tackle duplicate content. + * + * @param string $url + */ + public function setCanonicalUrl($url) + { + $this->link('canonical', $url); + } + /** * Set a variable to be preloaded into the app. * @@ -271,7 +303,7 @@ class WebAppView $view->cssUrls = $this->buildCssUrls($baseUrl); $view->jsUrls = $this->buildJsUrls($baseUrl); - $view->head = implode("\n", $this->head); + $view->head = $this->buildHeadContent(); $view->foot = implode("\n", $this->foot); return $view->render(); @@ -337,6 +369,17 @@ class WebAppView }, array_filter($files)); } + protected function buildHeadContent() + { + $html = implode("\n", $this->head); + + foreach ($this->links as $rel => $href) { + $html .= "\n"; + } + + return $html; + } + /** * @return CompilerInterface */