Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open_graph.py's _create_absolute_fileurl method does not honor a SITEURL with a subdirectory #66

Open
fluid217 opened this issue Oct 17, 2022 · 4 comments

Comments

@fluid217
Copy link

Given

SITEURL = 'mysite.com/blog' in the Pelican settings file.
and a fileurl of 'posts/my_article/index.html`

the _create_absolute_fileurl method in open_graph.py will return a file_url missing the SITEURLs subdirectory.
This is due to the way that urllib's parse.urljoin works.

My quick workaround for now is to append a slash to the siteurl. If it's redundant, it will be stripped out by urljoin

def __init__(
       self, siteurl, fileurl, file_type, title, description, image, locale
      ) -> None:
          self.siteurl = siteurl + "/"
@buanzo
Copy link

buanzo commented Jun 23, 2023

I am having the same issue. My Pelican is in a subfolder of my domain, example.com/blog, and the image/og_image attributes begin with /images/... - The resulting image url lacks the /blog before /images/.

@buanzo
Copy link

buanzo commented Jun 23, 2023

Maybe something like this, to avoid making sure SITEURL ends with '/':

def _create_absolute_fileurl(self):
    """Join site URL and file path."""
    # Ensure fileurl is a relative path
    if self.fileurl.startswith('/'):
        relative_fileurl = self.fileurl[1:]
    else:
        relative_fileurl = self.fileurl

    file_url = parse.urljoin(self.siteurl, relative_fileurl)
    return file_url

@MaevaBrunelles
Copy link
Collaborator

Hello @buanzo,

Feel free to open a PR with the patch and tests that ensure the canonical URL is well generated :)

@buanzo
Copy link

buanzo commented Jun 24, 2023

Absolutely! I'm working on the injector plugin, then tackle some bugs. Is there a devs mailing list ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants