Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwhiting committed Dec 16, 2023
1 parent d363ce6 commit c9e66ac
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/site_libs/quarto-contrib/twitter-0.0.1/_extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: social-embeds
author: Mark Sellors
version: 0.0.2
contributes:
shortcodes:
- gists.lua
- loom.lua
- twitter.lua
- vimeo.lua
- youtube.lua
- mastodon.lua
24 changes: 24 additions & 0 deletions docs/site_libs/quarto-contrib/twitter-0.0.1/gists.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function gist(args)
if quarto.doc.isFormat('html') then
local user = pandoc.utils.stringify(args[1])
local gist_id = pandoc.utils.stringify(args[2])
local file_fragment = ''
if args[3] ~= nil then
local file = pandoc.utils.stringify(args[3])
file_fragment = '?file=' .. file
end

-- Assemble HTML to be returned
local html = '<script src="https://gist.github.com/'
.. user
.. '/'
.. gist_id
.. '.js'
.. file_fragment
.. '"></script>'

return pandoc.RawInline('html', html)
else
return pandoc.Null()
end
end
15 changes: 15 additions & 0 deletions docs/site_libs/quarto-contrib/twitter-0.0.1/loom.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function loom(args)
if quarto.doc.isFormat('html') then
local videoid = pandoc.utils.stringify(args[1])

-- Assemble HTML to be returned
local html = '<div style="position: relative; padding-bottom: 56.25%; height: 0;"><iframe src="https://www.loom.com/embed/'
.. videoid
.. '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div>'

return pandoc.RawInline('html', html)
else
return pandoc.Null()
end
end

12 changes: 12 additions & 0 deletions docs/site_libs/quarto-contrib/twitter-0.0.1/mastodon.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function mastodon(args)
if quarto.doc.isFormat('html') then
local status_url = pandoc.utils.stringify(args[1])
print(status_url)
-- Assemble HTML to be returned
local html = '<div style="position: relative; padding-bottom: 56.25%; height: 0;"> <iframe src="'.. status_url ..'/embed" class="mastodon-embed" style="max-width: 100%; border: 0;" width="100%" height="400" allowfullscreen="allowfullscreen"></iframe><script src="https://mastodon.social/embed.js" async="async"></script></div> '

return pandoc.RawInline('html', html)
else
return pandoc.Null()
end
end
57 changes: 57 additions & 0 deletions docs/site_libs/quarto-contrib/twitter-0.0.1/twitter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
local function ensureHtmlDeps()
quarto.doc.addHtmlDependency({
name = 'twitter',
version = '0.0.1',
scripts = {
{
path = "",
attribs = {src="https://platform.twitter.com/widgets.js"},
afterBody = true
}
}
})
end

local function isEmpty(s)
return s == nil or s == ''
end

function tweet(args, kwargs)
if quarto.doc.isFormat('html') then
ensureHtmlDeps()

if isEmpty(args[1]) then
user = pandoc.utils.stringify(kwargs["user"])
status_id = pandoc.utils.stringify(kwargs["id"])
else
user = pandoc.utils.stringify(args[1])
status_id = pandoc.utils.stringify(args[2])
end

-- Assemble the twitter oembed API URL from the user inputs
local tweet_embed = 'https://publish.twitter.com/oembed?url=https://twitter.com/'
.. user
.. '/status/'
.. status_id
.. '&align=center'

print(tweet_embed)

local mt, api_resp = pandoc.mediabag.fetch(tweet_embed)

-- generate a random number to append to the html div ID to avoid re-use
local id = math.random(10000, 99999)

local tweet_data = '<div id="tweet-'
.. id
.. '"></div><script>tweet='
.. api_resp
.. ';document.getElementById("tweet-'
.. id
.. '").innerHTML = tweet["html"];</script>'

return pandoc.RawInline('html', tweet_data)
else
return pandoc.Null()
end
end
14 changes: 14 additions & 0 deletions docs/site_libs/quarto-contrib/twitter-0.0.1/vimeo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function vimeo(args)
if quarto.doc.isFormat('html') then
local videoid = pandoc.utils.stringify(args[1])

-- Assemble HTML to be returned
local html = '<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"> <iframe src="https://player.vimeo.com/video/'
.. videoid
.. '" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="vimeo video" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> </div> '

return pandoc.RawInline('html', html)
else
return pandoc.Null()
end
end
14 changes: 14 additions & 0 deletions docs/site_libs/quarto-contrib/twitter-0.0.1/youtube.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function youtube(args)
if quarto.doc.isFormat('html') then
local videoid = pandoc.utils.stringify(args[1])

-- Assemble HTML to be returned
local html = '<div id="youtube-frame" style="position: relative; padding-bottom: 56.25%; /* 16:9 */ height: 0;"><iframe width="100%" height="" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" src="https://www.youtube.com/embed/'
.. videoid
.. '" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>'

return pandoc.RawInline('html', html)
else
return pandoc.Null()
end
end

0 comments on commit c9e66ac

Please sign in to comment.