Include "Edit on Ghost" button when post is pushed
Convenient, isn't it? ;)
This commit is contained in:
parent
1edee70807
commit
1d80daba64
3 changed files with 60 additions and 23 deletions
18
seance.js
18
seance.js
|
@ -325,7 +325,7 @@ class Seance {
|
||||||
loglevel: 'info'
|
loglevel: 'info'
|
||||||
})
|
})
|
||||||
|
|
||||||
this.ghostAdmin.posts.add({
|
let res = await this.ghostAdmin.posts.add({
|
||||||
title: postMeta.title,
|
title: postMeta.title,
|
||||||
custom_excerpt: postMeta.subtitle || null,
|
custom_excerpt: postMeta.subtitle || null,
|
||||||
tags: postMeta.tags,
|
tags: postMeta.tags,
|
||||||
|
@ -333,7 +333,7 @@ class Seance {
|
||||||
html: markdown.toHTML(await fs.promises.readFile(postOutput, 'utf-8')),
|
html: markdown.toHTML(await fs.promises.readFile(postOutput, 'utf-8')),
|
||||||
feature_image: featuredImagePath
|
feature_image: featuredImagePath
|
||||||
}, {source: 'html'})
|
}, {source: 'html'})
|
||||||
.then((res) => {
|
|
||||||
// Check if user was added
|
// Check if user was added
|
||||||
if (res.primary_author.id == 1) {
|
if (res.primary_author.id == 1) {
|
||||||
this.emit('notification', {
|
this.emit('notification', {
|
||||||
|
@ -347,7 +347,19 @@ class Seance {
|
||||||
message: 'Post conveyed successfully',
|
message: 'Post conveyed successfully',
|
||||||
loglevel: 'info'
|
loglevel: 'info'
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
console.log(res)
|
||||||
|
|
||||||
|
return {
|
||||||
|
slug: res.slug,
|
||||||
|
id: res.id,
|
||||||
|
uuid: res.uuid,
|
||||||
|
preview_url: res.url,
|
||||||
|
primary_author: res.primary_author,
|
||||||
|
title: res.title,
|
||||||
|
subtitle: res.custom_excerpt,
|
||||||
|
status: res.status,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
19
server.js
19
server.js
|
@ -193,7 +193,7 @@ app.ws('/ws/push-ghost', (ws, req) => {
|
||||||
|
|
||||||
command = msg.split(' ')
|
command = msg.split(' ')
|
||||||
if (command.length == 3 && command[0] == 'push') {
|
if (command.length == 3 && command[0] == 'push') {
|
||||||
const postSlug = command[1]
|
let postSlug = command[1]
|
||||||
|
|
||||||
// check password
|
// check password
|
||||||
if (command[2] != process.env.SEANCE_PW) {
|
if (command[2] != process.env.SEANCE_PW) {
|
||||||
|
@ -204,6 +204,9 @@ app.ws('/ws/push-ghost', (ws, req) => {
|
||||||
// Start the Seance session
|
// Start the Seance session
|
||||||
seance = new Seance()
|
seance = new Seance()
|
||||||
|
|
||||||
|
// catch data
|
||||||
|
let postId
|
||||||
|
|
||||||
// set up handlers
|
// set up handlers
|
||||||
seance.on('update', (e) => {
|
seance.on('update', (e) => {
|
||||||
ws.send(`update: ${e.message}`)
|
ws.send(`update: ${e.message}`)
|
||||||
|
@ -217,13 +220,19 @@ app.ws('/ws/push-ghost', (ws, req) => {
|
||||||
ws.send(`error: ${e.message}`)
|
ws.send(`error: ${e.message}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
seance.pushToGhost(postSlug)
|
// run seance and wait till it finishes
|
||||||
.then(() => {
|
let res = await seance.pushToGhost(postSlug)
|
||||||
|
|
||||||
console.info(`"${postSlug}" pushed successfully.`)
|
console.info(`"${postSlug}" pushed successfully.`)
|
||||||
|
|
||||||
// send 'done' message
|
// send 'done' message
|
||||||
ws.send(`done: ${postSlug}`)
|
let ghostSite = await seance.ghostAdmin.site.read()
|
||||||
})
|
|
||||||
|
let postEditUrl
|
||||||
|
if (!!res.id) postEditUrl = `${ghostSite.url}ghost/#/editor/post/${res.id}`
|
||||||
|
if (!!res.slug) postSlug = res.slug
|
||||||
|
ws.send(`done: ${postSlug} ${postEditUrl}`)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ws.send('error: Malformed message')
|
ws.send('error: Malformed message')
|
||||||
return
|
return
|
||||||
|
|
|
@ -96,7 +96,7 @@ function mediumFetch(e) {
|
||||||
function ghostPush(e) {
|
function ghostPush(e) {
|
||||||
if(e) { e.preventDefault() }
|
if(e) { e.preventDefault() }
|
||||||
|
|
||||||
const postSlug = document.querySelector('[data-post-slug]').dataset.postSlug
|
let postSlug = document.querySelector('[data-post-slug]').dataset.postSlug
|
||||||
var password = document.querySelector('input[name=password]').value
|
var password = document.querySelector('input[name=password]').value
|
||||||
console.log('Pushing ' + postSlug)
|
console.log('Pushing ' + postSlug)
|
||||||
const socketProtocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:')
|
const socketProtocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:')
|
||||||
|
@ -147,7 +147,23 @@ function ghostPush(e) {
|
||||||
addNotification(commandData, className='is-danger')
|
addNotification(commandData, className='is-danger')
|
||||||
} else {
|
} else {
|
||||||
// show alert
|
// show alert
|
||||||
addNotification(`${postSlug} has been pushed to Ghost. Buffer share link: <a href="https://www.snipettemag.com/${postSlug}">https://www.snipettemag.com/${postSlug}</a>`, 'is-success')
|
// TODO: don't hard-code destination URL
|
||||||
|
// (instead, fetch from server's config and display)
|
||||||
|
|
||||||
|
// first, unpack info
|
||||||
|
let postEditUrl
|
||||||
|
|
||||||
|
commandData = commandData.split(' ')
|
||||||
|
if (!!commandData[0]) postSlug = commandData[0]
|
||||||
|
if (!!commandData[1]) postEditUrl = commandData[1]
|
||||||
|
|
||||||
|
let msg = `${postSlug} has been pushed to Ghost. Buffer share link: <a href="https://www.snipettemag.com/${postSlug}" target="_blank">https://www.snipettemag.com/${postSlug}</a>`
|
||||||
|
|
||||||
|
if (!!postEditUrl) {
|
||||||
|
msg = msg + `. <a href="${postEditUrl}" class="button" target="_blank">Edit on Ghost</a>`
|
||||||
|
}
|
||||||
|
|
||||||
|
addNotification(msg, 'is-success')
|
||||||
}
|
}
|
||||||
|
|
||||||
// since it's done, clean up
|
// since it's done, clean up
|
||||||
|
|
Loading…
Reference in a new issue