Skip to content

Commit

Permalink
opengraph
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherkenny committed Dec 7, 2024
1 parent d552905 commit 2f08038
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 21 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Imports:
httr2,
lubridate,
mime,
opengraph,
purrr,
rlang,
stringi,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export(bs_has_pass)
export(bs_has_user)
export(bs_like)
export(bs_list_records)
export(bs_new_embed_external)
export(bs_new_list)
export(bs_new_list_item)
export(bs_new_starter_pack)
Expand Down
68 changes: 68 additions & 0 deletions R/embed_external.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#' Embed external media in a post
#'
#' Embeds are not designed as standalone records, but rather as part of a post.
#' This will create a list representation of an external embed.
#'
#' @param uri a link to embed
#' @param title the title for the link
#' @param description a description of the link
#' @param thumb Optional. A thumbnail for the link
#'
#' @concept embed
#'
#' @section Lexicon references:
#' [embed/external.json (2024-12-05)](https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/embed/external.json)
#'
#' @section Function introduced:
#' `v0.2.0` (2024-12-05)
#'
#' @return a list representation of an external embed
#' @export
#'
#' @examplesIf has_bluesky_pass() & has_bluesky_user()
#' bs_new_embed_external(
#' uri = 'https://christophertkenny.com/bskyr/',
#' title = 'Interact with Bluesky Social',
#' description = 'An R package for using Bluesky Social'
#' )
bs_new_embed_external <- function(uri, title, description, thumb) {

if (missing(uri)) {
cli::cli_abort('{.arg uri} must not be missing.')
} else {

details <- opengraph::og_parse(uri)

if (missing(title)) {
if (!is.na(details$title)) {
title <- details$title
} else {
cli::cli_abort('{.arg title} must not be missing.')
}
}

if (missing(description)) {
if (!is.na(details$description)) {
description <- details$description
if (is.na(description)) {
description <- title
}
}
}
}

rec <- list(
`$type` = 'app.bsky.embed.external',
external = list(
uri = uri,
title = title,
description = description
)
)

if (!missing(thumb)) {
rec$external$thumb <- thumb
}

rec
}
24 changes: 12 additions & 12 deletions R/record_post.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#' Make a post on Bluesky Social
#'
#' @param text text of post
#' @param images character vector of paths to images to attach to post
#' @param images_alt character vector of alt text for images. Must be same length as `images` if used.
#' @param video character vector of path for up to one video to attach to post
#' @param video_alt character vector, length one, of alt text for video, if used.
#' @param langs character vector of languages in BCP-47 format
#' @param reply character vector with link to the parent post to reply to
#' @param quote character vector with link to a post to quote
#' @param emoji boolean. Default is `TRUE`. Should `:emoji:` style references be converted?
#' @param text Text of post
#' @param images Character vector of paths to images to attach to post
#' @param images_alt Character vector of alt text for images. Must be same length as `images` if used.
#' @param video Character vector of path for up to one video to attach to post
#' @param video_alt Character vector, length one, of alt text for video, if used.
#' @param langs Character vector of languages in BCP-47 format
#' @param reply Character vector with link to the parent post to reply to
#' @param quote Character vector with link to a post to quote
#' @param emoji Logical. Default is `TRUE`. Should a link card be embedded?
#' @param emoji Logical. Default is `TRUE`. Should `:emoji:` style references be converted?
#' @param max_tries `r template_var_max_tries()`
#' @param user `r template_var_user()`
#' @param pass `r template_var_pass()`
Expand Down Expand Up @@ -59,9 +60,8 @@
#' video = fs::path_package('bskyr', 'man/figures/pkgs.mp4'),
#' video_alt = 'a carousel of package logos, all hexagonal')
bs_post <- function(text, images, images_alt,
video, video_alt,
langs, reply, quote,
emoji = TRUE, max_tries,
video, video_alt, langs, reply, quote,
embed = TRUE, emoji = TRUE, max_tries,
user = get_bluesky_user(), pass = get_bluesky_pass(),
auth = bs_auth(user, pass), clean = TRUE) {
if (missing(text)) {
Expand Down
Binary file added image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions man/bs_new_embed_external.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions man/bs_post.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f08038

Please sign in to comment.