diff --git a/_config.yml b/_config.yml index cd51b3b..d97ad4d 100644 --- a/_config.yml +++ b/_config.yml @@ -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 diff --git a/_notes/your-first-note.md b/_notes/your-first-note.md index babafaf..b93c1c5 100644 --- a/_notes/your-first-note.md +++ b/_notes/your-first-note.md @@ -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. diff --git a/_plugins/embed_tweets.rb b/_plugins/embed_tweets.rb new file mode 100644 index 0000000..19c1b33 --- /dev/null +++ b/_plugins/embed_tweets.rb @@ -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 +
+ This tweet could not be embedded. View it on Twitter instead. +
+ + HTML + ) + end + end +end