From efe16511bd9a19f8b4781969144a4ef0a6134fcf Mon Sep 17 00:00:00 2001 From: Max Pfeiffer Date: Wed, 19 Mar 2025 21:48:37 +0100 Subject: [PATCH 1/3] Made _create_absolute_fileurl() function more resilient --- .gitignore | 2 ++ .../seo_enhancer/html_enhancer/open_graph.py | 5 +++++ pelican/plugins/seo/tests/test_open_graph.py | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/.gitignore b/.gitignore index 068ef7c..43bea68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .vscode/ +.idea *__pycache__ .pdm-python pdm.lock +.venv 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", [ From 746af55d05d93412c66f87a0f851ec4a149b6a6d Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Wed, 19 Mar 2025 16:09:20 -0700 Subject: [PATCH 2/3] Revert .gitignore changes --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 43bea68..068ef7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ .vscode/ -.idea *__pycache__ .pdm-python pdm.lock -.venv From cb740e01b50fbdfde58540534d116afc96813838 Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Wed, 19 Mar 2025 16:11:58 -0700 Subject: [PATCH 3/3] Prepare release --- RELEASE.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 RELEASE.md 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