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

Add support for generating meta tags. #1991

Merged
merged 11 commits into from
Dec 28, 2022

Conversation

ztangent
Copy link
Contributor

This PR addresses issue #1321 by adding support for generated meta tags.

As discussed in that issue, OpenGraph and Twitter meta-tags are generated to enable link previews. The following functionality is provided:

  1. Ability to specify a preview image, that auto-populates the og:image and twitter:image meta tags.
    • This is done by creating preview.{png,webp,gif,jpg,jpeg} in the assets directory. Because meta tags need to link an absolute URL, the canonical URL for the image is constructed from the canonical option in the HTML constructor.
  2. Auto-populate title, og:title and twitter:title with the same page_title value that gets used in the <title> tag.
  3. Ability to specify the description, og:description and twitter:description meta tags with a string.
    • A site-wide description can be specified as a keyword argument to makedocs, and can be over-ridden in a page-specific manner using the Description keyword in an @meta-block.
  4. Auto-populate the og:url and twitter:url metatags with the canonical URL of that page, as long as canonical is set.

Documentation has been updated accordingly. The only thing I haven't done is write test cases for this functionality, because I'm not quite sure where to add them or how to test for the existence of the correct meta-tags in some generated HTML file. Advice would be appreciated!

OpenGraph and Twitter meta-tags are generated to enable link previews.
@oxinabox
Copy link
Contributor

Can we fallback to the logo if the preview image isn't found?

@ztangent
Copy link
Contributor Author

@mortenpi suggested not having a fallback because the preview doesn't look the best (see #1321 (comment)), but it'd be an easy change either way!

@mortenpi mortenpi added Format: HTML Related to the default HTML output Type: Enhancement labels Dec 12, 2022
@mortenpi mortenpi added this to the 0.28.0 milestone Dec 12, 2022
src/makedocs.jl Outdated Show resolved Hide resolved
Copy link
Member

@mortenpi mortenpi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more things:

  1. One last thing that would be nice is to have a couple of small occursin tests, mostly to make sure that the conditional behaviors are handled correctly.
  2. It could use a CHANGELOG entry.

However, other than changing it to be an argument to HTML and the CHANGELOG, this looks great as is. Everything else is just bikeshedding.

src/html/HTMLWriter.jl Outdated Show resolved Hide resolved
src/html/HTMLWriter.jl Outdated Show resolved Hide resolved
@ztangent
Copy link
Contributor Author

ztangent commented Dec 18, 2022

Made all of the suggested changes!

I can also add this test preview image to the real documentation for Documenter.jl if you'd like:

preview

(*Note that even if I add it, it will only start showing up as a preview image with the next stable release of Documenter.jl, due to how the preview image URL is constructed from the canonical URL.)

@ztangent
Copy link
Contributor Author

Have tested that this actually works with the documentation site for PDDL.jl: https://juliaplanners.github.io/PDDL.jl/dev/

You can enter the URL above into metatags.io to check, or just inspect the meta tags of the generated docs for dev.

Copy link
Member

@mortenpi mortenpi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I can also add this test preview image to the real documentation for Documenter.jl if you'd like:

I you don't mind, that would be awesome. We can merge as soon as that is done.

CHANGELOG.md Outdated Show resolved Hide resolved
@ztangent
Copy link
Contributor Author

Done!

@mortenpi
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Format: HTML Related to the default HTML output Type: Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants