fix: absolute link (188)

This commit is contained in:
Will Rossiter 2023-07-19 21:38:47 +12:00
parent 9b0e0f1064
commit 81b8d870a4
No known key found for this signature in database
GPG Key ID: 7FD2A809B22259EF
11 changed files with 39 additions and 123 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
.DS_Store .DS_Store
/vendor
/public
/composer.lock

View File

@ -1,69 +0,0 @@
inherit: true
checks:
php:
verify_property_names: true
verify_argument_usable_as_reference: true
verify_access_scope_valid: true
useless_calls: true
use_statement_alias_conflict: true
variable_existence: true
unused_variables: true
unused_properties: true
unused_parameters: true
unused_methods: true
unreachable_code: true
too_many_arguments: true
sql_injection_vulnerabilities: true
simplify_boolean_return: true
side_effects_or_types: true
security_vulnerabilities: true
return_doc_comments: true
return_doc_comment_if_not_inferrable: true
require_scope_for_properties: true
require_scope_for_methods: true
require_php_tag_first: true
psr2_switch_declaration: true
psr2_class_declaration: true
property_assignments: true
prefer_while_loop_over_for_loop: true
precedence_mistakes: true
precedence_in_conditions: true
phpunit_assertions: true
php5_style_constructor: true
parse_doc_comments: true
parameter_non_unique: true
parameter_doc_comments: true
param_doc_comment_if_not_inferrable: true
optional_parameters_at_the_end: true
one_class_per_file: true
no_unnecessary_if: true
no_trailing_whitespace: true
no_property_on_interface: true
no_non_implemented_abstract_methods: true
no_error_suppression: true
no_duplicate_arguments: true
no_commented_out_code: true
newline_at_end_of_file: true
missing_arguments: true
method_calls_on_non_object: true
instanceof_class_exists: true
foreach_traversable: true
fix_line_ending: true
fix_doc_comments: true
duplication: true
deprecated_code_usage: true
deadlock_detection_in_loops: true
code_rating: true
closure_use_not_conflicting: true
catch_class_exists: true
blank_line_after_namespace_declaration: false
avoid_multiple_statements_on_same_line: true
avoid_duplicate_types: true
avoid_conflicting_incrementers: true
avoid_closing_tag: true
assignment_of_null_return: true
argument_type_checks: true
filter:
paths: [code/*, tests/*]

View File

@ -1,29 +0,0 @@
# Changelog
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Older releases can be found on Github.
## 2.1.7
- Adds legacy file for migration from Silverstripe 3
Full changelog: https://github.com/wilr/silverstripe-googlesitemaps/compare/2.1.6...2.1.7
## 2.1.6
- Fixes incorrect priority calculations
Full changelog: https://github.com/wilr/silverstripe-googlesitemaps/compare/2.1.5...2.1.6
## 2.1.5
- FIX: enable stream context to pass through CWP egres proxy, fixes #156
Full changelog: https://github.com/wilr/silverstripe-googlesitemaps/compare/2.1.4...2.1.5
## 2.1.4
- Fixes extending alterSiteMap to support falsey values
Full changelog: https://github.com/wilr/silverstripe-googlesitemaps/compare/2.1.3...2.1.4

View File

@ -12,6 +12,10 @@
> composer require "wilr/silverstripe-googlesitemaps" > composer require "wilr/silverstripe-googlesitemaps"
If you're using Silverstripe 5 then version 3 or `dev-main` will work.
For Silverstripe 4 use the `2.x` branch line.
## Documentation ## Documentation
Provides support for the [Sitemaps XML Protocol](http://www.sitemaps.org/protocol.html), Provides support for the [Sitemaps XML Protocol](http://www.sitemaps.org/protocol.html),

View File

@ -4,9 +4,8 @@ namespace Wilr\GoogleSitemaps\Control;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config; use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Manifest\ModuleResourceLoader;
use Wilr\GoogleSitemaps\GoogleSitemap; use Wilr\GoogleSitemaps\GoogleSitemap;
use SilverStripe\View\ArrayData; use SilverStripe\View\ArrayData;
@ -52,7 +51,7 @@ class GoogleSitemapController extends Controller
$this->extend('updateGoogleSitemaps', $sitemaps); $this->extend('updateGoogleSitemaps', $sitemaps);
return $this->customise(new ArrayData([ return $this->customise(new ArrayData([
'Sitemaps' => $sitemaps 'Sitemaps' => $sitemaps,
]))->renderWith(__CLASS__); ]))->renderWith(__CLASS__);
} else { } else {
return new HTTPResponse('Page not found', 404); return new HTTPResponse('Page not found', 404);
@ -76,7 +75,8 @@ class GoogleSitemapController extends Controller
} }
} }
if (GoogleSitemap::enabled() if (
GoogleSitemap::enabled()
&& $class && $class
&& ($page > 0) && ($page > 0)
&& ($class == SiteTree::class || $class == 'GoogleSitemapRoute' || GoogleSitemap::is_registered($class)) && ($class == SiteTree::class || $class == 'GoogleSitemapRoute' || GoogleSitemap::is_registered($class))
@ -129,4 +129,10 @@ class GoogleSitemapController extends Controller
return $html; return $html;
} }
public function AbsoluteLink($action = null)
{
return Controller::join_links(Director::absoluteBaseURL(), 'sitemap.xml', $action);
}
} }

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='{$AbsoluteBaseURL}/sitemap.xml/styleSheetIndex'?> <?xml-stylesheet type='text/xsl' href='{$AbsoluteLink('styleSheetIndex')}'?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><% loop Sitemaps %> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><% loop Sitemaps %>
<sitemap> <sitemap>
<loc>{$AbsoluteBaseURL}/sitemap.xml/sitemap/$ClassName/$Page.xml</loc> <loc>{$AbsoluteLink('sitemap')}/{$ClassName}/{$Page.xml}</loc>
<% if $LastModified %><lastmod>$LastModified</lastmod><% end_if %> <% if $LastModified %><lastmod>{$LastModified}</lastmod><% end_if %>
</sitemap><% end_loop %> </sitemap><% end_loop %>
</sitemapindex> </sitemapindex>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='{$AbsoluteBaseURL}/sitemap.xml/styleSheet'?> <?xml-stylesheet type='text/xsl' href='{$AbsoluteLink('styleSheet')}'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<% loop $Items %> <% loop $Items %>
<url> <url>
<loc>$AbsoluteLink</loc> <loc>{$AbsoluteLink}</loc>
<% if $LastEdited %><lastmod>$LastEdited.Rfc3339()</lastmod><% end_if %> <% if $LastEdited %><lastmod>{$LastEdited.Rfc3339()}</lastmod><% end_if %>
<% if $ChangeFrequency %><changefreq>$ChangeFrequency</changefreq><% end_if %> <% if $ChangeFrequency %><changefreq>$ChangeFrequency</changefreq><% end_if %>
<% if $GooglePriority %><priority>$GooglePriority</priority><% end_if %> <% if $GooglePriority %><priority>$GooglePriority</priority><% end_if %>
<% if $ImagesForSitemap %><% loop $ImagesForSitemap %> <% if $ImagesForSitemap %><% loop $ImagesForSitemap %>

View File

@ -4,7 +4,6 @@ namespace Wilr\GoogleSitemaps\Tests;
use Exception; use Exception;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
@ -25,6 +24,8 @@ class GoogleSitemapTest extends FunctionalTest
'GoogleSitemapPageTest.yml', 'GoogleSitemapPageTest.yml',
]; ];
protected $usesDatabase = true;
protected static $extra_dataobjects = [ protected static $extra_dataobjects = [
TestDataObject::class, TestDataObject::class,
OtherDataObject::class, OtherDataObject::class,
@ -131,8 +132,8 @@ class GoogleSitemapTest extends FunctionalTest
$page2->publishSingle(); $page2->publishSingle();
$page2->flushCache(); $page2->flushCache();
DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-03-14 00:00:00' WHERE \"ID\"='".$page->ID."'"); DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-03-14 00:00:00' WHERE \"ID\"='" . $page->ID . "'");
DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-01-01 00:00:00' WHERE \"ID\"='".$page2->ID."'"); DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-01-01 00:00:00' WHERE \"ID\"='" . $page2->ID . "'");
$response = $this->get('sitemap.xml'); $response = $this->get('sitemap.xml');
$body = $response->getBody(); $body = $response->getBody();
@ -309,7 +310,7 @@ class GoogleSitemapTest extends FunctionalTest
Versioned::set_reading_mode($oldMode); Versioned::set_reading_mode($oldMode);
throw $ex; throw $ex;
} // finally { } // finally {
Versioned::set_reading_mode($oldMode); Versioned::set_reading_mode($oldMode);
// } // }
} }
} }

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='http://localhostsitemap.xml/styleSheetIndex'?> <?xml-stylesheet type='text/xsl' href='http://localhost/sitemap.xml/styleSheetIndex'?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap> <sitemap>
<loc>http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1</loc> <loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1</loc>
<lastmod>2023-02-13</lastmod> <lastmod>2023-02-13</lastmod>
</sitemap> </sitemap>
<sitemap> <sitemap>
<loc>http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-OtherDataObject/1</loc> <loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-OtherDataObject/1</loc>
<lastmod>2023-02-13</lastmod> <lastmod>2023-02-13</lastmod>
</sitemap> </sitemap>
</sitemapindex> </sitemapindex>

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='http://localhostsitemap.xml/styleSheetIndex'?> <?xml-stylesheet type='text/xsl' href='http://localhost/sitemap.xml/styleSheetIndex'?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap> <sitemap>
<loc>http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1</loc> <loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1</loc>
<lastmod>2023-02-13</lastmod> <lastmod>2023-02-13</lastmod>
</sitemap> </sitemap>
<sitemap> <sitemap>
<loc>http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/2</loc> <loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/2</loc>
<lastmod>2023-02-13</lastmod> <lastmod>2023-02-13</lastmod>
</sitemap> </sitemap>
<sitemap> <sitemap>
<loc>http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/3</loc> <loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/3</loc>
<lastmod>2023-02-13</lastmod> <lastmod>2023-02-13</lastmod>
</sitemap> </sitemap>
</sitemapindex> </sitemapindex>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='http://localhostsitemap.xml/styleSheetIndex'?> <?xml-stylesheet type='text/xsl' href='http://localhost/sitemap.xml/styleSheetIndex'?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap> <sitemap>
<loc>http://localhostsitemap.xml/sitemap/GoogleSitemapRoute/1</loc> <loc>http://localhost/sitemap.xml/sitemap/GoogleSitemapRoute/1</loc>
</sitemap> </sitemap>
</sitemapindex> </sitemapindex>