mkdocs-rss-plugin icon indicating copy to clipboard operation
mkdocs-rss-plugin copied to clipboard

Interaction with mkdocs-material, images produces by Social plugin cause error

Open holgerflick opened this issue 1 year ago β€’ 2 comments

When using the social plugin in conjunction with the RSS plugin, I get a huge amount of these errors.

WARNING:root:Remote image could not been reached: http://127.0.0.1:8000/assets/images/social/blog/posts/14-results.png. Trying again with GET and disabling SSL verification. Attempt: 1. Trace: <urlopen error [Errno 61] Connection refused> WARNING:root:Remote image could not been reached: http://127.0.0.1:8000/assets/images/social/blog/posts/14-results.png. Trying again with GET and disabling SSL verification. Attempt: 2. Trace: <urlopen error [Errno 61] Connection refused>

The author of Material for MkDocs analyzed the following @squidfunk :

The RSS plugin fetches the image and that seems to run into an error with SSL. Please report this upstream.

holgerflick avatar Mar 23 '24 15:03 holgerflick

Hitting this as well

domenkozar avatar Apr 10 '24 11:04 domenkozar

To help debug this, I created a minimal reproduction following the Material for MkDocs process. Hope this helps.

9.5.19-social-cards-images.zip

Run mkdocs serve or remove the info plugin and mkdocs build to reproduce.

alexvoss avatar Apr 29 '24 07:04 alexvoss

Hi there,

Is the issue the same in community and insiders edition?

Guts avatar Jun 10 '24 20:06 Guts

The reproduction was done with the public version but I am getting the same error message with 9.5.26+insiders.4.53.11. For the sheer fun of it, I also tested with public version 9.5.26 and getting the same.

alexvoss avatar Jun 10 '24 21:06 alexvoss

Thanks you for having fun cases testing. It's a pretty tricky bug but I've got a lead to the guilty!

Guts avatar Jun 11 '24 05:06 Guts

In the meantime, downgrading to 1.6.0 solved the issue for me. I'm not sure in which version this issue was introduced πŸ˜…

squidfunk avatar Jun 11 '24 09:06 squidfunk

@alexvoss in fact your example can't work out of the box since the plugin tries to read image length (required for RSS compliance) from the file created/moved by the social plugin into the mkdocs site dir. But, since the image is often created after the RSS plugin run, there is a race condition. In that case, the RSS plugin tries to fetch the content-length from the online image .

In the meantime, downgrading to 1.6.0 solved the issue for me. I'm not sure in which version this issue was introduced πŸ˜…

Downgrading to 1.9.* should be enough, before the Social Cards integration in 1.10 (https://guts.github.io/mkdocs-rss-plugin/changelog/#1100---2023-12-17 ) or even 1.10 should work before the HTTP mechanism.

Well, this not the more reliable and robust code I wrote in my life but I felt lazy back in December :sweat_smile:. I'm going to improve it in some ways:

  • [x] using requests instead of standard lib to get the an upper-level and out-of-the-box special cases handling like SSL verification etc.
  • [x] trying to retrieve image from the local .cache folder of social plugin
  • [ ] extending the social plugin manifest (in a separate file) to store image length, relying on the same cache key.

Guts avatar Jun 11 '24 10:06 Guts

The big problem with social cards is that the link referring to the og:image must be absolute per spec. Now, if the authors adds a new page and builds it, the URL referenced in og:image will definitely point to a non-existing image, because the page has not been deployed to the site_url yet. Race conditions might be a problem, but an even bigger problem is the aforementioned catch-22.

  1. Without the new page being deployed, no social card image
  2. Without the social card image, no successful build without warnings

I'm not sure what the best way forward could be.

squidfunk avatar Jun 11 '24 10:06 squidfunk

Interesting.

extending the social plugin manifest (in a separate file) to store image length, relying on the same cache key.

Hmm it seems that the manifest.json is not systematically generated by the social plugin?

Guts avatar Jun 11 '24 10:06 Guts

The social plugin differs between the community and Insiders edition, and only Insiders has a manifest to properly implementing caching. It will be merged once the attached funding goals are hit ☺️

squidfunk avatar Jun 11 '24 10:06 squidfunk

Yes, I was coming to the same conclusion. I hope the sponsors are going in the right direction, it can't be easy maintaining 2 substantially different code bases!

Does the theme or theme plugins expose a variable to indicate whether it's the community or insiders version?

Something easily checkable like config.plugins.social.edition == "community" for 3rd party plugins?

Guts avatar Jun 11 '24 10:06 Guts

You can check the version of Material for MkDocs.

# Community
material.__version__ = "9.5.26"

# Insiders
material.__version__ = "9.5.26+insiders-4.53.11"

squidfunk avatar Jun 11 '24 10:06 squidfunk

Thanks for the tip!

Guts avatar Jun 11 '24 12:06 Guts

Hi @squidfunk,

Any hint on how to determine the matching hash between page filename and generated image filename in community edition I mean?

Guts avatar Jun 14 '24 14:06 Guts

Ok, I've found the related piece of code:

        hash = md5("".join([
            site_name,
            str(title),
            description
        ]).encode("utf-8"))

Guts avatar Jun 14 '24 14:06 Guts

It's much more predictable in Insiders πŸ˜…

squidfunk avatar Jun 14 '24 19:06 squidfunk

Sure! But I'll try to do my best to have a similar experience in both editions.

Guts avatar Jun 14 '24 19:06 Guts

Released as part of 1.13.1. Please test the shipped improvements and give feedback here :pray:. Ping @alexvoss @holgerflick @domenkozar .

Guts avatar Jun 15 '24 22:06 Guts

Works, thanks!

On Sat, Jun 15, 2024 at 11:05β€―PM Julien @.***> wrote:

Released as part 1.13.1 https://github.com/Guts/mkdocs-rss-plugin/releases/tag/1.13.1. Please test the shipped improvements and give feedback here πŸ™. Ping @alexvoss https://github.com/alexvoss @holgerflick https://github.com/holgerflick @domenkozar https://github.com/domenkozar .

β€” Reply to this email directly, view it on GitHub https://github.com/Guts/mkdocs-rss-plugin/issues/257#issuecomment-2170940396, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA63AZTFNNWL4PYQSV2FNTZHS3CNAVCNFSM6AAAAABFEXSWA2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZQHE2DAMZZGY . You are receiving this because you were mentioned.Message ID: @.***>

domenkozar avatar Jun 19 '24 13:06 domenkozar