Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feb 25 post - LinkedIn Api #100

Merged
merged 18 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/scripts/add_doi.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,19 @@ upload_pdf <- function(bucket, pdf_file, id){
req_throttle(rate = 30 / 60) |>
req_perform()

browser()

if (inherits(upload_response, "error")) {
request(zenodo_api_endpoint) |>
req_url_path_append(id) |>
req_auth_bearer_token(zenodo_api_token) |>
req_method("DELETE") |>
req_perform()
browser()

stop(sprintf("Failed to upload Zenodo: %s",
e),
call. = FALSE
)
}
browser()

if (!resp_status(upload_response) %in% c(200, 201)) {
request(zenodo_api_endpoint) |>
Expand Down
76 changes: 28 additions & 48 deletions .github/scripts/announce.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,28 @@ if (length(post) == 0) {
post <- post[1]
}

source(".github/scripts/linkedin.R", local = TRUE)
source(".github/scripts/kit_newsletter.R", local = TRUE)

create_message <- function(text){
glue::glue(
"📝 New post: '{frontmatter$title}'
{emoji} {text}
👀 {uri}
{tags}"
)
}

#post <- "content/blog/2025/01-01_longcovid/index.md"
frontmatter <- rmarkdown::yaml_front_matter(post)

# fix tags
tags <- paste0("#", frontmatter$tags)
tags <- sub("^#r$", "#rstats", tags)
tags <- paste(tags, collapse=", ")
tags <- paste(tags, collapse=" ")

# build URL
uri <- sprintf("https://drmowinckels.io/blog/%s/%s",
Expand All @@ -38,67 +54,31 @@ emojis <- c("🦄", "🦜", "🦣", "🦥", "🦦", "🦧", "🦨", "🦩", "
"🧻", "🧼", "🧽", "🧾", "🧿")
emoji <- sample(emojis, 1)

# Create message
message <- glue::glue(
"📝 New blog post 📝
image <- here::here(dirname(post), frontmatter$image)

'{frontmatter$title}'
{emoji} {frontmatter$seo}
👀 Read at: {uri}
{tags}"
# Post to LinkedIn
li_posts_write(
author = li_urn_me(),
media_alt = frontmatter$image_alt,
text = create_message(frontmatter$summary)
)

image <- here::here(dirname(post), frontmatter$image)

# Post to Mastodon
rtoot::post_toot(
status = message,
status = create_message(frontmatter$seo),
media = image,
alt_text = "Blogpost featured image",
alt_text = frontmatter$image_alt,
visibility = "public",
language = "US-en"
)


# Post to Bluesky
bskyr::bs_post(
text = message,
text = substr(create_message(frontmatter$seo), 1, 300),
images = image,
images_alt = "Blogpost featured image",
images_alt = frontmatter$image_alt,
langs = "US-en"
)


# Post to LinkedIn


# Send Newsletter
newsletter <- glue::glue('
<div>
<h1 class="" style="font-weight:bold;font-style:normal;font-size:1em;margin:0;font-size:2em;font-weight:normal;font-family:Georgia,Times,\'Times New Roman\',serif;color:#023f3c;line-height:1.5">{frontmatter$title}</h1>
<div style="text-align:center;padding:0.05px"><figure style="margin:1em 0;margin-top:12px;margin-bottom:12px;margin-left:0;margin-right:0;display:inline-block;max-width:800px;width:100%;vertical-align:top"><div style="display:block">​<img contenteditable="false" src="{uri}/{frontmatter$image}" width="800" style="border:0 none;display:block;height:auto;line-height:100%;outline:none;-webkit-text-decoration:none;text-decoration:none;max-width:100%;opacity:1;border-radius:4px 4px 4px 4px;width:800px;height:auto;object-fit:contain"></div>
<p class="ck-paragraph" style="margin:1em 0;font-size:18px;line-height:1.5em;font-family:-apple-system,BlinkMacSystemFont,\'Segoe UI\',Roboto,Oxygen-Sans,Ubuntu,Cantarell,\'Helvetica Neue\',sans-serif;color:#0c4848;font-size:16px;line-height:1.5">{frontmatter$summary}</p>
<div style="width:100%;display:flow-root;text-align:center;margin-top:8px;margin-bottom:8px"><a href="{uri}" target="_blank" rel="noopener noreferrer" class="ck-button" style="color:#0875c1;color:#825a83;display:inline-block;text-decoration:none;border-style:solid;text-align:center;background-color:#0f6261;color:#ffffff;font-size:16px;border-color:#0f6261;padding:12px 20px;border-radius:4px 4px 4px 4px">Read more</a></div>
</div>
')


resp <- httr2::request("https://api.convertkit.com/v3/broadcasts") |>
httr2::req_body_json(
list(
public = TRUE,
api_secret = Sys.getenv("KIT_SECRET"),
description = frontmatter$seo,
thumbnail_url = file.path(uri, frontmatter$image),
subject = frontmatter$title,
content = newsletter,
send_at = format(Sys.time(), "%Y-%m-%dT%H:%M:%SZ")
)
) |>
httr2::req_perform()
send_newsletter(frontmatter)
27 changes: 27 additions & 0 deletions .github/scripts/kit_newsletter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
send_newsletter <- function(frontmatter){
newsletter <- glue::glue('
<div>
<h1 class="" style="font-weight:bold;font-style:normal;font-size:1em;margin:0;font-size:2em;font-weight:normal;font-family:Georgia,Times,\'Times New Roman\',serif;color:#023f3c;line-height:1.5">{frontmatter$title}</h1>
<div style="text-align:center;padding:0.05px"><figure style="margin:1em 0;margin-top:12px;margin-bottom:12px;margin-left:0;margin-right:0;display:inline-block;max-width:800px;width:100%;vertical-align:top"><div style="display:block">​<img contenteditable="false" src="{uri}/{frontmatter$image}" width="800" style="border:0 none;display:block;height:auto;line-height:100%;outline:none;-webkit-text-decoration:none;text-decoration:none;max-width:100%;opacity:1;border-radius:4px 4px 4px 4px;width:800px;height:auto;object-fit:contain"></div>
<p class="ck-paragraph" style="margin:1em 0;font-size:18px;line-height:1.5em;font-family:-apple-system,BlinkMacSystemFont,\'Segoe UI\',Roboto,Oxygen-Sans,Ubuntu,Cantarell,\'Helvetica Neue\',sans-serif;color:#0c4848;font-size:16px;line-height:1.5">{frontmatter$summary}</p>
<div style="width:100%;display:flow-root;text-align:center;margin-top:8px;margin-bottom:8px"><a href="{uri}" target="_blank" rel="noopener noreferrer" class="ck-button" style="color:#0875c1;color:#825a83;display:inline-block;text-decoration:none;border-style:solid;text-align:center;background-color:#0f6261;color:#ffffff;font-size:16px;border-color:#0f6261;padding:12px 20px;border-radius:4px 4px 4px 4px">Read more</a></div>
</div>
')

httr2::request("https://api.convertkit.com/v3/broadcasts") |>
httr2::req_body_json(
list(
public = TRUE,
api_secret = Sys.getenv("KIT_SECRET"),
description = frontmatter$seo,
thumbnail_url = file.path(uri, frontmatter$image),
subject = frontmatter$title,
content = newsletter,
send_at = format(Sys.time(), "%Y-%m-%dT%H:%M:%SZ")
)
) |>
httr2::req_perform()
}
Loading
Loading