Plugin markdown update (#211)
This commit is contained in:
@@ -12,16 +12,19 @@
|
||||
//Retrieve posts
|
||||
console.debug(`metrics/compute/${login}/plugins > posts > processing with source ${source}`)
|
||||
let posts = null
|
||||
let link = null
|
||||
switch (source) {
|
||||
//Dev.to
|
||||
case "dev.to":{
|
||||
console.debug(`metrics/compute/${login}/plugins > posts > querying api`)
|
||||
posts = (await imports.axios.get(`https://dev.to/api/articles?username=${user}&state=fresh`)).data.map(({title, description, published_at:date, cover_image:image}) => ({title, description, date, image}))
|
||||
posts = (await imports.axios.get(`https://dev.to/api/articles?username=${user}&state=fresh`)).data.map(({title, description, published_at:date, cover_image:image, url:link}) => ({title, description, date, image, link}))
|
||||
link = `https://dev.to/${user}`
|
||||
break
|
||||
}
|
||||
//Hashnode
|
||||
case "hashnode":{
|
||||
posts = (await imports.axios.post("https://api.hashnode.com", {query:queries.posts.hashnode({user})}, {headers:{"Content-type":"application/json"}})).data.data.user.publication.posts.map(({title, brief:description, dateAdded:date, coverImage:image}) => ({title, description, date, image}))
|
||||
posts = (await imports.axios.post("https://api.hashnode.com", {query:queries.posts.hashnode({user})}, {headers:{"Content-type":"application/json"}})).data.data.user.publication.posts.map(({title, brief:description, dateAdded:date, coverImage:image, slug}) => ({title, description, date, image, link:`https://hashnode.com/post/${slug}`}))
|
||||
link = `https://hashnode.com/@${user}`
|
||||
break
|
||||
}
|
||||
//Unsupported
|
||||
@@ -42,7 +45,7 @@
|
||||
posts = await Promise.all(posts.map(async({image, ...post}) => ({image:await imports.imgb64(image, {width:144, height:-1}), ...post})))
|
||||
}
|
||||
//Results
|
||||
return {source, descriptions, covers, list:posts}
|
||||
return {source, link, descriptions, covers, list:posts}
|
||||
}
|
||||
|
||||
//Unhandled error
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
query PostsHashnode {
|
||||
user(username: "$user"){
|
||||
publication{
|
||||
posts(page: 1) {
|
||||
posts(page: 0) {
|
||||
slug
|
||||
title
|
||||
brief
|
||||
coverImage
|
||||
|
||||
@@ -46,11 +46,17 @@
|
||||
//Medias
|
||||
if (tweet.attachments)
|
||||
tweet.attachments = await Promise.all(tweet.attachments.media_keys.filter(key => medias.get(key)).map(key => medias.get(key)).map(async url => ({image:await imports.imgb64(url, {height:-1, width:450})})))
|
||||
else if (linked) {
|
||||
if (linked) {
|
||||
const {result:{ogImage, ogSiteName:website, ogTitle:title, ogDescription:description}} = await imports.opengraph({url:linked})
|
||||
const image = await imports.imgb64(ogImage?.url, {height:-1, width:450, fallback:false})
|
||||
if (image)
|
||||
tweet.attachments = [{image, title, description, website}]
|
||||
if (image) {
|
||||
if (tweet.attachments)
|
||||
tweet.attachments.unshift([{image, title, description, website}])
|
||||
else
|
||||
tweet.attachments = [{image, title, description, website}]
|
||||
}
|
||||
else
|
||||
tweet.text = `${tweet.text}\n${linked}`
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -68,7 +74,7 @@
|
||||
//Line breaks
|
||||
.replace(/\n/g, "<br/>")
|
||||
//Links
|
||||
.replace(new RegExp(`${tweet.urls.size ? "" : "noop^"}(${[...tweet.urls.keys()].map(url => `(?:${url})`).join("|")})`, "gi"), (_, url) => `<span class="link">${tweet.urls.get(url)}</span>`), {"&":true})
|
||||
.replace(new RegExp(`${tweet.urls.size ? "" : "noop^"}(${[...tweet.urls.keys()].map(url => `(?:${url})`).join("|")})`, "gi"), (_, url) => `<a href="${url}" class="link">${tweet.urls.get(url)}</a>`), {"&":true})
|
||||
}))
|
||||
|
||||
//Result
|
||||
|
||||
Reference in New Issue
Block a user