Skip to content

Commit

Permalink
Fix page URL trailing slashes. Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokke- committed Oct 14, 2022
1 parent 9b10bc7 commit f5e172e
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions MarkupMetadata.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MarkupMetadata extends WireData implements Module, ConfigurableModule {
public static function getModuleInfo() : array {
return [
'title' => 'Markup Metadata',
'version' => 120,
'version' => 121,
'summary' => 'Set and render meta tags for head section.',
'author' => 'Ville Fokke Saarivaara',
'singular' => true,
Expand Down Expand Up @@ -116,22 +116,21 @@ public function setMeta(string $tag, ?array $attrs = [], ?string $content = null
private function getPageUrl (?\ProcessWire\Language $language = null) : ?string {
if (empty($this->base_url)) return null;

// Add base URL
$url = rtrim($this->base_url, '/');
$url = implode('/', array_filter([
rtrim($this->base_url, '/'),
trim((!empty($language)) ? $this->page->localUrl($language) : $this->page->url, '/'),
$this->page->template->urlSegments === 1 ? $this->input->urlSegmentStr : null,
]));

// Add page URL
$url .= (!empty($language)) ? $this->page->localUrl($language) : $this->page->url;

// Add URL segments
if ($this->input->urlSegmentStr) {
$url .= $this->input->urlSegmentStr;

if ($this->page->template->slashUrlSegments == 1) {
$url .= '/';
}
}
// Add trailing slash if required
if (
($this->page->template->urlSegments === 1 && $this->page->template->slashUrlSegments === 1 && $this->input->urlSegmentStr) ||
($this->page->template->slashUrls === 1 && !$this->input->urlSegmentStr)
) {
$url .= '/';
}

return $url;
return $url;
}

/**
Expand Down

0 comments on commit f5e172e

Please sign in to comment.