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

Support open graph #178

Closed
Fil opened this issue Nov 15, 2023 · 12 comments
Closed

Support open graph #178

Fil opened this issue Nov 15, 2023 · 12 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@Fil
Copy link
Contributor

Fil commented Nov 15, 2023

Design and implement a system (template? hook? options in frontmatter?) that allows the developer to add proper tags so that their page has the relevant information to create a "card" or "summary" on social platforms. Usually:

This needs the origin and base options (#180).

@Fil Fil added the enhancement New feature or request label Nov 15, 2023
@mbostock mbostock changed the title support open graph Support open graph Nov 15, 2023
@mbostock mbostock added this to the Future milestone Nov 15, 2023
@mbostock
Copy link
Member

Same comment as #179 (comment): this issue needs further specificity to be actionable.

@mbostock mbostock added the question Further information is requested label Nov 15, 2023
@Fil
Copy link
Contributor Author

Fil commented Dec 1, 2023

This can be done with #253

@Fil
Copy link
Contributor Author

Fil commented Feb 20, 2024

Exposing meta data to the page could help in more scenarios. see #1036

@pettiross
Copy link
Contributor

OG images would also let us show thumbnails for projects and pages on the platform.

@Fil
Copy link
Contributor Author

Fil commented Mar 1, 2024

related: #168

@pettiross
Copy link
Contributor

+1 to using the front matter for this. We could expand on the front matter + observable.config.ts combination we have today so project-level defaults for OG metalabels could be set once and overridden on specific pages.

@mbostock mbostock removed this from the Future milestone Mar 24, 2024
@mbostock
Copy link
Member

Is this already done with the head option (and the ability to reference local assets in the head)?

@Fil
Copy link
Contributor Author

Fil commented Mar 27, 2024

Not quite yet. I'd like to explore a possibility for the head option (as well as header and footer) to be specified as a function, that would receive as arguments some meta data about the project config (including the origin option #180), and the current page (front matter, title, and possibly contents/files, if the user wants to insert an excerpt / summary or pick the first image from the contents) #1036. (Also mentioned #56 (comment).)

EDIT: I've now explored this and it's a pretty simple and straightforward change to getHtml() and it's not so simple.

@mbostock
Copy link
Member

I’m still not sure what this needs. Why not specify the head front matter option? Do we just want shorthand so you can specify a description front matter option (and maybe image) instead that gets promoted to the corresponding meta elements in the head?

@Fil
Copy link
Contributor Author

Fil commented Apr 27, 2024

The way I imagine this, the configuration head option, if specified as a function (#1255) would receive meta data, from the page's front matter (or first H1 if the title is not defined as front matter), and would build the og "card" from these values — it seems like a common convenience in CMS.

I did not even consider typing everything explicitly, although it (almost) works:

---
head:
  <meta property="og:title" content="Page title"/>
  <meta property="og:description" content="This is a nice page." />
  <meta property="og:image" content="heroimage.png"/>
  <meta property="og:image:width" content="1200"/>
  <meta property="og:image:height" content="630"/>
---

Unfortunately it does not work fully because og:image must be an absolute URL (per spec, even though the official website ogp.me is a bit more fuzzy on this point). But, if we make it absolute, it's not picked up by Framework as being a file attachment, and not built.

The absolute URL issue could be fixed automatically but would require the origin option (#180). If we want to make this more convenient, the title should be picked up automatically as well as the image's dimensions. (And maybe the description could be automated too.)

@Fil
Copy link
Contributor Author

Fil commented Sep 11, 2024

OpenGraph is only useful for public projects, and in that case it's much easier to point to the og:image in another web service than to try and create an absolute URL locally in the SSG. At least this is what I do now in pangea, pointing the image to jsdelivr, that serves the content from github. for instance, https://observablehq.observablehq.cloud/pangea/plot/voronoi-treemap now references jsdelivr...thumbnail/plot/voronoi-treemap.png.

See this debug view.

Supporting the other "card" or "og" fields (title, etc) is feasible within the same head() function. My implementation is certainly far from perfect, and people might want to iterate on this, but I thinkg we can do it in userland and don't need anything more from Framework. We could discuss it further in the blogging-like functionality discussion.

@mbostock
Copy link
Member

mbostock commented Oct 7, 2024

Quick update on @Fil’s current techniques… (@Fil correct me if anything in this description is wrong; sharing guidance in case anyone else similarly wants thumbnails.)

Pangea currently uses Playwright to take screenshots in generate-thumbnails.ts.

This script is run manually and the thumbnails are committed to the source repo in the thumbnails folder. This is because running Playwright is expensive (slow) and we don’t want to run it every time we build the site. (Maybe in the future these thumbnails could be stored in a cache so they automatically update then the code changes… 🤷)

The head config option is specified as a head function to generate the og:title and og:image meta data elements. It also includes a link element to ensure that the generated thumbnails are included in the built site.

A og_image function computes the SHA-256 content hash of the thumbnail so that it matches Framework’s behavior. This is necessary because Framework won’t rewrite og:image and twitter:image meta data elements automatically — and even if it did, it would need to know the origin of the site in order to produce a full URL, which would require the origin config option. #180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants