Skip to content

Commit

Permalink
Inject tiddlers for social media preview metadata
Browse files Browse the repository at this point in the history
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
  • Loading branch information
simonbaird committed Aug 5, 2024
1 parent a83bb90 commit b4e24ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rails/lib/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def self.subdomain_site_url(site_name)
ActionDispatch::Http::URL.full_url_for(Settings.url_defaults.merge(subdomain: site_name))
end

def self.site_thumbnail_url(site_name)
"#{subdomain_site_url(site_name)}/thumb.png"
end

def self.tiddlyspot_site_host(site_name)
"#{site_name}.#{Settings.tiddlyspot_host}"
end
Expand Down
9 changes: 9 additions & 0 deletions rails/lib/th_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ def apply_tw5_mods(site_name, for_download:, local_core:, use_put_saver:, is_log

# Provide a way for TiddlyWikis to detect when they're able to be saved
'$:/status/IsLoggedIn' => status_is_logged_in(is_logged_in:, for_download:),

# Used in `$:/core/templates/social-metadata` for social media preview metadata.
# (It seems like it would be unexpected for these to be set in a downloaded file,
# so set them to an empty string if we're preparing for a download.)
# Todo maybe: Allow the user to customize the preview image url, perhaps by creating
# it as a shadow tiddler
'$:/SiteUrl' => (for_download ? '' : Settings.subdomain_site_url(site_name)),
'$:/SiteDomain' => (for_download ? '' : Settings.subdomain_site_host(site_name)),
'$:/SitePreviewImageUrl' => (for_download ? '' : Settings.site_thumbnail_url(site_name)),
})

# Since every save uploads the entire TiddlyWiki I want to discourage
Expand Down
2 changes: 2 additions & 0 deletions rails/lib/tw_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def to_html
def write_tiddlers(tiddlers, shadow: false)
if json_store?
# Assume we're using TW 5.2 and later
# Note that we don't support shadow tidders for the json store,
# see https://github.com/simonbaird/tiddlyhost/issues/341
append_json_store(tiddlers)

else
Expand Down

0 comments on commit b4e24ff

Please sign in to comment.