diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000..6b3a9d2 --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,3 @@ +Release type: patch + +Support `SITEURL` values that contain slugs after the domain diff --git a/pelican/plugins/seo/seo_enhancer/html_enhancer/open_graph.py b/pelican/plugins/seo/seo_enhancer/html_enhancer/open_graph.py index 23184c0..58b3ac0 100644 --- a/pelican/plugins/seo/seo_enhancer/html_enhancer/open_graph.py +++ b/pelican/plugins/seo/seo_enhancer/html_enhancer/open_graph.py @@ -21,6 +21,11 @@ def __init__( def _create_absolute_fileurl(self): """Join site URL and file path.""" + if not self.siteurl.endswith("/"): + self.siteurl += "/" + + if self.fileurl.startswith("/"): + self.fileurl = self.fileurl[1:] file_url = parse.urljoin(self.siteurl, self.fileurl) return file_url diff --git a/pelican/plugins/seo/tests/test_open_graph.py b/pelican/plugins/seo/tests/test_open_graph.py index b103cae..9e8d18a 100644 --- a/pelican/plugins/seo/tests/test_open_graph.py +++ b/pelican/plugins/seo/tests/test_open_graph.py @@ -29,6 +29,28 @@ def test_create_absolute_fileurl(self, fake_article): assert fileurl == "https://www.fakesite.com/fake-title.html" + @pytest.mark.parametrize( + "site_url", ["https://fake.github.io/blog", "https://fake.github.io/blog/"] + ) + @pytest.mark.parametrize("file_url", ["fake-title.html", "/fake-title.html"]) + def test_create_absolute_fileurl_with_site_url_with_path(self, site_url, file_url): + """ + Test if create_absolute_fileurl() joins a site URL with or without a trailing + slash and a file URL with or without a leading slash properly. + """ + og = OpenGraph( + siteurl=site_url, + fileurl=file_url, + file_type=None, + title=None, + description=None, + image=None, + locale=None, + ) + fileurl = og._create_absolute_fileurl() + + assert fileurl == "https://fake.github.io/blog/fake-title.html" + @pytest.mark.parametrize( "locale,expected_result", [