Allow embedding tweets
This commit is contained in:
parent
f4d4be2b60
commit
97232001be
@ -14,6 +14,11 @@ use_html_extension: false
|
||||
# set to `false` to open non-internal links in current tab.
|
||||
open_external_links_in_new_tab: true
|
||||
|
||||
# Set to `true` to replace tweet URLs with Twitter embeds.
|
||||
# Note that doing so will negatively the reader's privacy
|
||||
# as their browser will communicate with Twitter's servers.
|
||||
embed_tweets: false
|
||||
|
||||
permalink: pretty
|
||||
relative_permalinks: false
|
||||
|
||||
|
@ -25,6 +25,14 @@ Of course, you can also link to external websites, like this: [this is a link to
|
||||
|
||||
[^1]: This is a footnote. For more information about using footnotes, check out the [Markdown Guide](https://www.markdownguide.org/extended-syntax/#footnotes).
|
||||
|
||||
### Tweet embedding
|
||||
|
||||
Note: This behavior is disabled by default for privacy reasons. See "Site configuration" section below to enable it.
|
||||
|
||||
You may include a tweet URL on its own line (like below), and it would be replaced with an official Twitter embed if the site configuration demands it.
|
||||
|
||||
https://twitter.com/jack/status/20
|
||||
|
||||
### Site configuration
|
||||
|
||||
Some behavior is configurable by tweaking the `_config.yml` file.
|
||||
@ -33,6 +41,8 @@ Some behavior is configurable by tweaking the `_config.yml` file.
|
||||
|
||||
**`open_external_links_in_new_tab`**: when set to `true`, this makes external links open in new tabs. Set to `false` to open all links in the current tab.
|
||||
|
||||
**`embed_tweets`**: when set to `true`, tweet URLs on their own lines will be replaced with a Twitter embed. Default value is `false`.
|
||||
|
||||
### Automatic bi-directional links
|
||||
|
||||
Notice in the "Notes mentioning this note" section that there is another note linking to this note. This is a bi-directional link, and those are automatically created when you create links to other notes.
|
||||
|
22
_plugins/embed_tweets.rb
Normal file
22
_plugins/embed_tweets.rb
Normal file
@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
class TweetEmbedGenerator < Jekyll::Generator
|
||||
def generate(site)
|
||||
return if !site.config["embed_tweets"]
|
||||
|
||||
all_notes = site.collections['notes'].docs
|
||||
all_pages = site.pages
|
||||
all_docs = all_notes + all_pages
|
||||
|
||||
all_docs.each do |current_note|
|
||||
current_note.content.gsub!(
|
||||
/^https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(es)?\/(\d+)$/i,
|
||||
<<~HTML
|
||||
<blockquote class="twitter-tweet">
|
||||
This tweet could not be embedded. <a href="#{'\0'}">View it on Twitter instead.</a>
|
||||
</blockquote>
|
||||
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
|
||||
HTML
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user