Skip to content

Consider supporting OpenGraph? #1758

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

Closed
malmaud opened this issue Oct 15, 2015 · 44 comments
Closed

Consider supporting OpenGraph? #1758

malmaud opened this issue Oct 15, 2015 · 44 comments
Labels
Accepted Accepted issue on our roadmap Improvement Minor improvement to code Needed: documentation Documentation is required

Comments

@malmaud
Copy link

malmaud commented Oct 15, 2015

As discussed here, OpenGraph support would allow Discourse forums and other popular systems to display inline previews of links to readthedocs pages, especially useful for forums about programming languages and tools.

It just takes a few <meta> tags injected into the rendered HTML, so I don't think it should be too burdensome. Plus Jeff Atwood himself is pushing for it :)

@agjohnson agjohnson added the Improvement Minor improvement to code label Oct 20, 2015
@agjohnson
Copy link
Contributor

Seems like a great addition. It should be trivial to implement on our theme overrides. Does implementing this as an article type make sense, or is there another type that would work best for something like the DIscourse onebox?

@malmaud
Copy link
Author

malmaud commented Oct 21, 2015

Yes, article type makes sense.

I think "og:description" will be the trickiest tag to get right - it along with "og:title" contain the text which is actually shown in the onebox. According to this, most sites will display between 200 and 300 characters of the og:description value, so it essentially is a 200-character summary of the doc page.

@agjohnson
Copy link
Contributor

Yeah, I'm not entirely sure how to handle the description.

The change for the meta tags is a simple addition to the template overrides RTD maintains. We do have access to the content of the page in the templates, but it's HTML, which rules out a simple truncation operation inside the templates. If we want to be more intelligent about the content truncation, we'll have to write a template filter in a Sphinx extension to break up the HTML content.

For now, this might just be the project description field in the RTD project admin, instead of per-page content for the description.

og:title should be trivial however, this can be provided by the Sphinx template easily.

@malmaud
Copy link
Author

malmaud commented Oct 23, 2015

That sounds good. And maybe set og:image to the project logo whose name is somehow exposed to the template.

As a concrete reference, here's what the meta tags for say http://docs.julialang.org/en/release-0.4/manual/variables/ could maybe end up looking like:

<meta property="og:title" content="Variables" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://docs.julialang.org/en/release-0.4/manual/variables/" />
<meta property="og:site_name" content="readthedocs: Julia" />
<meta property="og:description" content="The Julia programming language.." />
<meta property="og:image" content="http://docs.julialang.org/en/release-0.4/_static/julia-logo.svg"/>

@agjohnson
Copy link
Contributor

If we ever start collecting the project logo, that would be another good addition. Currently we aren't collecting that and don't have a great way to determine that outside of project configuration options.

This reference seems like a reasonable place to start at least

@agjohnson agjohnson added the Accepted Accepted issue on our roadmap label Sep 17, 2018
@agjohnson agjohnson added this to the 2.9 milestone Sep 17, 2018
@stsewd
Copy link
Member

stsewd commented Nov 16, 2018

I was able to do a POC here, injecting all the metatags on the rtd theme https://github.com/rtfd/sphinx_rtd_theme.

I was able to make work: title, site_name, url, type, description, image and locale (this one isn't on the same format of language_TERRITORY because of https://www.sphinx-doc.org/en/stable/usage/configuration.html#confval-language).

But, there is a design decision to take here, we depend on the theme_canonical_url value here, but on the rtd code, we inject the canonical url tag from our extension (https://github.com/rtfd/readthedocs-sphinx-ext) rather then injection those values in the html_theme_options or using the value from html_context (we populate this field on the rtd).

So, should this live on the rtd-theme or on the rtd-sphinx-extension?

@stsewd stsewd added the Needed: design decision A core team decision is required label Nov 16, 2018
@stsewd
Copy link
Member

stsewd commented Nov 16, 2018

I wasn't able to make it work with ngrok, so, I just upload it on github pages, and for some reason the _static dir doesn't work (I guess because of jekyll). But this is kind of how it looks my POC.

screenshot_2018-11-15 sharing debugger - facebook for developers

this is how it looks without og, I'll need to figureout how to get a better description p:

screenshot_2018-11-15 sharing debugger - facebook for developers 1

@stsewd
Copy link
Member

stsewd commented Nov 16, 2018

I was able to do the .nojekyll thing, but facebook doesn't support svg images p: so, it kind of looks like the same https://developers.facebook.com/tools/debug/sharing/?q=https%3A%2F%2Fstsewd.github.io%2Frtd-test%2F

@stsewd
Copy link
Member

stsewd commented Nov 16, 2018

At least on twitter it makes a LOT of o difference 😁 https://cards-dev.twitter.com/validator

screenshot_2018-11-16 card validator twitter developers 1
screenshot_2018-11-16 card validator twitter developers

@humitos
Copy link
Member

humitos commented Jan 7, 2019

So, should this live on the rtd-theme or on the rtd-sphinx-extension?

I think that our sphinx extension will be better since it will affect all the themes that are built on Read the Docs, not only our own.

Also, I think that we may sanitize the description probably to make it looks nice (without \n and as a complete sentence). In the example, the title is repeated in the description.

We may want to use the default Read the Docs logo if we don't have a project's image (html_logo in conf.py I suppose).

@agjohnson
Copy link
Contributor

I'd say no logo if the user hasn't specified. It seems odd to brand with our logo

@agjohnson
Copy link
Contributor

agjohnson commented Feb 1, 2019

So, another thing to point out is that Sphinx already has support for this natively through reST meta directive. It just outputs the meta elements in <head>, but does require authoring these pieces on each page source. Perhaps we can set default page-level meta through standard Sphinx options or and extension?

Ultimately, I want opengraph enabled across all projects. If we are hard coding the template, we'll probably break or at least override anyone using meta for opengraph already. However, setting default meta is probably the cleanest solution either way.

I haven't looked at how sphinx handles this, but my assumption is that the meta elements will be in the doctree after parsing the source, so we can use an extension to add default meta tags based on RTD context data to each document.

http://docutils.sourceforge.net/docs/ref/rst/directives.html#meta

@stsewd
Copy link
Member

stsewd commented Feb 6, 2019

@agjohnson so, I was editing the extension, with the doctree and everything, but I hit a bug that makes impossible to do the meta tag default thing https://sourceforge.net/p/docutils/bugs/281/, doctutils doesn't support : in the meta directive, even escaping doesn't work as expected.

So, another option is using the builder I guess? I didn't try but, I guess we have access to the dom

@stsewd
Copy link
Member

stsewd commented Feb 6, 2019

Sphinx issue sphinx-doc/sphinx#2645

@stsewd
Copy link
Member

stsewd commented Feb 6, 2019

We inject a template already https://github.com/rtfd/readthedocs-sphinx-ext/blob/8e545547c2c1324368406a710dd76e0534674499/readthedocs_ext/readthedocs.py#L117-L121, but I'll try to look if we can have the dom, or block this till the problem is resolved in sphinx

@humitos humitos removed this from the 2.11 milestone Feb 9, 2019
@stsewd stsewd added the Status: blocked Issue is blocked on another issue label Feb 22, 2019
@stsewd
Copy link
Member

stsewd commented Feb 22, 2019

Another sphinx related issue sphinx-doc/sphinx#6089

@humitos
Copy link
Member

humitos commented Jul 18, 2019

doctutils doesn't support : in the meta directive, even escaping doesn't work as expected.

This is already fixed on docutils, but it's not released yet. It will be on 0.15: http://docutils.sourceforge.net/RELEASE-NOTES.html#release-0-15b-dev

@humitos
Copy link
Member

humitos commented Jul 23, 2019

docutils 0.15 was released: https://pypi.org/project/docutils/

This is not blocked anymore 🎉

@humitos humitos removed Needed: design decision A core team decision is required Status: blocked Issue is blocked on another issue labels Jul 23, 2019
@humitos humitos added the Sprintable Small enough to sprint on label Jan 25, 2020
@Daltz333
Copy link

Any update on this?

@agjohnson
Copy link
Contributor

Yeah, I'd agree we don't want to install this for users. Documenting this extension would be a good first step.

I'd still like to have this as a feature across all of RTD hosted docs though, not just on some projects. I would leave this issue open because of that.

@agjohnson agjohnson removed the Needed: design decision A core team decision is required label Mar 9, 2021
@Daltz333
Copy link

Daltz333 commented Mar 9, 2021

Would this mean RTD would inject into the users HTML output or build? Would this conflict with sphinxext-opengraph or would it be a documentation only approach?

This seems to conflict with @stsewd

@stevepiercy
Copy link
Contributor

@Daltz333 I'm not sure why I was @'ed, as I have not participated in this discussion.

@Daltz333
Copy link

Daltz333 commented Mar 9, 2021

My bad, autocorrect on phone github

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: stale Issue will be considered inactive soon label Jun 2, 2021
@astrojuanlu
Copy link
Contributor

The original request was about supporting OpenGraph for sites hosted on Read the Docs by injecting some magic for our users. Now, sphinxext-opengraph exists, users can adopt it if they want, and we are moving away from injecting extensions for users.

Therefore, I propose we close this issue and open a new one (or discuss internally) on which RTD-owned projects do we want to adopt this extension.

@stale stale bot removed the Status: stale Issue will be considered inactive soon label Jun 3, 2021
@astrojuanlu astrojuanlu added the Status: stale Issue will be considered inactive soon label Jun 3, 2021
@stsewd stsewd removed the Status: stale Issue will be considered inactive soon label Jun 3, 2021
@stsewd
Copy link
Member

stsewd commented Jun 3, 2021

We should still document this solution in our docs as a guide.

@stale
Copy link

stale bot commented Jul 21, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: stale Issue will be considered inactive soon label Jul 21, 2021
@astrojuanlu astrojuanlu added the Accepted Accepted issue on our roadmap label Jul 21, 2021
@stale stale bot removed the Status: stale Issue will be considered inactive soon label Jul 21, 2021
@astrojuanlu
Copy link
Contributor

After our experience with https://github.com/readthedocs/blog/, to support OpenGraph on Read the Docs people need to

  1. Add https://pypi.org/project/sphinxext-opengraph/ to their requirements
  2. Enable sphinxext.opengraph in their Sphinx extensions

The rest is automatic, since sphinxext-opengraph does some magic if the project is hosted on Read the Docs, as explained in https://github.com/wpilibsuite/sphinxext-opengraph#options.

I think this would be quite short for a guide, but if folks still think it would be useful, I will be happy to write it.

@humitos
Copy link
Member

humitos commented Jul 26, 2021

I think this would be quite short for a guide, but if folks still think it would be useful, I will be happy to write it.

@astrojuanlu In case a guide does not quite fit here, I remember that we talked about collecting a collection of Sphinx's extensions and recommend them with a small config file ready to use. If we still want to go in that direction, we could use https://sphinx-extensions.readthedocs.io/ for that.

@astrojuanlu
Copy link
Contributor

We have expressed elsewhere that usually we don't recommend third-party extensions in our docs (see for example discussion at #8396), so I think we should close this issue and continue the discussion on humitos/sphinx-extensions#14.

On a related note, I think we should give https://sphinx-extensions.readthedocs.io/ more attention and visibility.

@agjohnson
Copy link
Contributor

On a related note, I think we should give https://sphinx-extensions.readthedocs.io/ more attention and visibility.

Yeah I agree, this might make more sense as an official RTD project even

However, if we are pointing users towards another project for this sort of content, seems like something would could also include as narrative content in our own docs. Perhaps guide content is the best avenue for this sort of guidance.

There is a lot of room for us (or Sphinx, but historically us) to highlight how to solve these specific customer/user issues when authoring documentation with Sphinx. Sphinx-extensions helps with illustration, but guide content would probably help translate problem -> solution more for customers/users -- for example, translate "how do I author documentation with multiple code examples" -> "you can use sphinx-tabs, copybutton, ..." etc.

@humitos
Copy link
Member

humitos commented Aug 23, 2021

Yeah I agree, this might make more sense as an official RTD project even

I'm happy to move to the readthedocs organization.

However, if we are pointing users towards another project for this sort of content, seems like something would could also include as narrative content in our own docs. Perhaps guide content is the best avenue for this sort of guidance.

When I created the project, I didn't want to generate too much written content due to the lack of time. I'd like to keep each page simple if possible so we can highlight extensions quicker without the need of writing a full guide about it.

@agjohnson
Copy link
Contributor

I'd like to keep each page simple if possible so we can highlight extensions quicker without the need of writing a full guide about it.

Yeah this seems fine, it might be helpful to have two separate overviews of extensions -- narrative, describing why or how authors could solve a particular problem with an extension, and illustrative, showing how each extension functions with the sphinx-extensions repo. The two seem complimentary for now

@humitos
Copy link
Member

humitos commented Dec 5, 2022

I just wanted to comment here that sphinx-opengraph is moving forward on supporting social previews (sphinx-doc/sphinxext-opengraph#66 (comment)).

If you are interested in opengraph, you should follow that repository since it's the right extension to install in your documentation.

@humitos humitos closed this as completed Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Improvement Minor improvement to code Needed: documentation Documentation is required
Projects
None yet
Development

No branches or pull requests

7 participants