Skip to content

Commit acee956

Browse files
authored
Make _create_absolute_fileurl() function more resilient (#74)
1 parent 47b6a65 commit acee956

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Release type: patch
2+
3+
Support `SITEURL` values that contain slugs after the domain

pelican/plugins/seo/seo_enhancer/html_enhancer/open_graph.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def __init__(
2121

2222
def _create_absolute_fileurl(self):
2323
"""Join site URL and file path."""
24+
if not self.siteurl.endswith("/"):
25+
self.siteurl += "/"
26+
27+
if self.fileurl.startswith("/"):
28+
self.fileurl = self.fileurl[1:]
2429

2530
file_url = parse.urljoin(self.siteurl, self.fileurl)
2631
return file_url

pelican/plugins/seo/tests/test_open_graph.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ def test_create_absolute_fileurl(self, fake_article):
2929

3030
assert fileurl == "https://www.fakesite.com/fake-title.html"
3131

32+
@pytest.mark.parametrize(
33+
"site_url", ["https://fake.github.io/blog", "https://fake.github.io/blog/"]
34+
)
35+
@pytest.mark.parametrize("file_url", ["fake-title.html", "/fake-title.html"])
36+
def test_create_absolute_fileurl_with_site_url_with_path(self, site_url, file_url):
37+
"""
38+
Test if create_absolute_fileurl() joins a site URL with or without a trailing
39+
slash and a file URL with or without a leading slash properly.
40+
"""
41+
og = OpenGraph(
42+
siteurl=site_url,
43+
fileurl=file_url,
44+
file_type=None,
45+
title=None,
46+
description=None,
47+
image=None,
48+
locale=None,
49+
)
50+
fileurl = og._create_absolute_fileurl()
51+
52+
assert fileurl == "https://fake.github.io/blog/fake-title.html"
53+
3254
@pytest.mark.parametrize(
3355
"locale,expected_result",
3456
[

0 commit comments

Comments
 (0)