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 Jul 31, 2024
1 parent 725f4fe commit 395773e
Show file tree
Hide file tree
Showing 3 changed files with 14 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 included in a downloaded
# file, so set them to an empty string in that case.
'$:/SiteUrl' => (for_download ? '' : Settings.subdomain_site_url(site_name)),
'$:/SiteDomain' => (for_download ? '' : Settings.subdomain_site_host(site_name)),
# Todo maybe: Don't overwrite this if the user customized it. Creating this as a
# shadow tiddler would be a nice way to achieve that but I don't how to.
'$:/SiteThumbnailUrl' => (for_download ? '' : Settings.site_thumbnail_url(site_name)),
})

# Since every save uploads the entire TiddlyWiki I want to discourage
Expand Down
1 change: 1 addition & 0 deletions rails/lib/tw_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def to_html
def write_tiddlers(tiddlers, shadow: false)
if json_store?
# Assume we're using TW 5.2 and later
# Todo: Not sure how to create a shadow tiddler like this
append_json_store(tiddlers)

else
Expand Down

0 comments on commit 395773e

Please sign in to comment.