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 social media cards #8441

Merged
merged 6 commits into from
Aug 8, 2024
Merged

Add support for social media cards #8441

merged 6 commits into from
Aug 8, 2024

Conversation

Jermolene
Copy link
Member

@Jermolene Jermolene commented Jul 28, 2024

As discussed in #8433, this PR adds a new raw markup template that conditionally creates Facebook/Twitter social card meta tags. The tiddlers used (alongside the existing $:/SiteTitle and $:/SiteSubtitle) are:

  • $:/SiteDomain - plain domain of the site
  • $:/SitePreviewUrl - full URL of thumbnail (relative URLs do not work)
  • $:/SiteUrl - full URL of the site

Copy link

Confirmed: Jermolene has already signed the Contributor License Agreement (see contributing.md)

simonbaird added a commit to tiddlyhost/tiddlyhost-com that referenced this pull request Jul 31, 2024
The next release of TiddlyWiki will include a
$:/core/templates/social-metadata tiddler that will produce metadata
used by social media link previews.

Provide some tiddler content to make that work for TW5 sites on
Tiddlyhost.

See TiddlyWiki/TiddlyWiki5#8441
@simonbaird
Copy link
Contributor

Tangentially related question: To inject tiddlers I'm inserting something like this into the dom:

<script class="tiddlywiki-tiddler-store" type="application/json">[{"text":"hello","title":"MyTiddler"}]</script>

Is there a way to do something like and create a shadowTiddler? In the past it was possible to add a tiddler div to the #shadowArea to create a shadow tiddler, but not sure how to do it now.

@Jermolene
Copy link
Member Author

Is there a way to do something like and create a shadowTiddler? In the past it was possible to add a tiddler div to the #shadowArea to create a shadow tiddler, but not sure how to do it now.

In TiddlyWiki Classic shadow tiddlers were stored in a single hashmap. In TiddlyWiki 5 shadows are automatically created at startup from the tiddlers within the loaded plugins.

So, the approach for TW5 would be to pack your tiddlers into a plugin, and then inject that. You'd be injecting a single tiddler with the usual plugin fields, with its content being a JSON hashmap of the constituent tiddlers.

The info mechanism in the core works similarly by dynamically creating a plugin at startup on the browser side. It uses the title $:/temp/info-plugin for the plugin. It may make sense for you to use $:/temp/tiddlyhost if you wanted to avoid the plugin being saved back to the server.

@simonbaird
Copy link
Contributor

Thanks for the info re shadow tiddlers.

@simonbaird
Copy link
Contributor

Lgtm.

simonbaird added a commit to tiddlyhost/tiddlyhost-com that referenced this pull request Aug 5, 2024
The next release of TiddlyWiki will include a
$:/core/templates/social-metadata tiddler that will produce metadata
used by social media link previews.

Provide some tiddler content to make that work for TW5 sites on
Tiddlyhost.

See TiddlyWiki/TiddlyWiki5#8441
@Jermolene
Copy link
Member Author

Great, thank you @simonbaird – I'll add the new system tiddlers to the control panel and then this can be merged.

@Jermolene
Copy link
Member Author

In 213a786 I've added a control panel user interface for setting the social media card information.

image

@Jermolene Jermolene merged commit 4da27f6 into master Aug 8, 2024
3 checks passed
simonbaird added a commit to simonbaird/TiddlyWiki5 that referenced this pull request Aug 8, 2024
The control panel name and the name in the template don't match. I
figured the shorter name is better, but let me know if you like the
longer name.

This is a small fix for recently merged PR TiddlyWiki#8441.
@simonbaird
Copy link
Contributor

simonbaird commented Aug 8, 2024

I noticed a mismatch in one of the names:

$:/SitePreviewImageUrl versus $:/SitePreviewUrl.

Create the #8496 PR to fix it, assuming the shorter name is preferred.

@simonbaird
Copy link
Contributor

I think there's a problem with a space being eaten in the meta tag. I'm seeing this:

<metaname="description" content="a non-linear personal web notebook">
<metaproperty="og:url" content="https://foo.com/">
<metaproperty="og:title" content="My TiddlyWiki">
<metaproperty="og:description" content="a non-linear personal web notebook">
<metaproperty="twitter:domain" content="foo.com">
<metaproperty="twitter:url" content="https://foo.com/">
<metaname="twitter:title" content="My TiddlyWiki">
<metaname="twitter:description" content="a non-linear personal web notebook">

(which gets even more garbled when parsed and rendered by Tiddlyhost.)

@simonbaird
Copy link
Contributor

Perhaps \whitespace trim trims too hard..?

Jermolene pushed a commit that referenced this pull request Aug 21, 2024
The control panel name and the name in the template don't match. I
figured the shorter name is better, but let me know if you like the
longer name.

This is a small fix for recently merged PR #8441.
Jermolene added a commit that referenced this pull request Aug 30, 2024
Apologies @simonbaird this is the belated fix to the issue you mentioned in #8441 (comment)
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

Successfully merging this pull request may close these issues.

2 participants