diff --git a/seance.js b/seance.js index ff602a0..5881c62 100644 --- a/seance.js +++ b/seance.js @@ -181,10 +181,13 @@ class Seance { const outStream = fs.createWriteStream(postOutput, { encoding: 'utf-8' }) - var titleSkipped = false; + // We'll calculate these later since Medium messes it up sometimes + let title = null + let subtitle = null let reImage = new RegExp('^!\\[(.*)\\]\\((\\S+?)\\)(.*)') - let reTitle = new RegExp('^#\ .*') + let reTitle = new RegExp('^#\ (.*)') + let reSubtitle = new RegExp('^#+\ (.*)$') // Note down uploaded images var uploadedImages = [] @@ -201,9 +204,35 @@ class Seance { // Default is to make it same as input var newLine = line - // Skip the header - if (!titleSkipped && await reTitle.exec(line)) { - titleSkipped = true + // Skip the header (and preceding blank lines) + if (!title) { + + // blanks + if (!line) continue + + // starting with a # (must be the title) + let match = await reTitle.exec(line) + if (match) { + title = match[1] + continue // no need to add line; it'll come automatically + } + } else if (!subtitle) { + + // check if it's a repeat of the title (Medium does that) + if (line.endsWith(title)) continue + + // otherwise set the subtitle if it doesn't exist + // or if it's a repeat of the title (Medium does that too) + + if (!subtitle && postMeta.subtitle == postMeta.title) { + let match = await reSubtitle.exec(line) + + if (match) { + subtitle = match[1] + postMeta.subtitle = match[1] + } + } + } // check for images diff --git a/server.js b/server.js index 3fb390d..2ad7be2 100644 --- a/server.js +++ b/server.js @@ -221,9 +221,6 @@ app.ws('/ws/push-ghost', (ws, req) => { .then(() => { console.info(`"${postSlug}" pushed successfully.`) - // warn about fixing byline and description - ws.send('notification: The "make the title proper" bug is yet to be fixed! Please make sure to adjust the title and subtitle, as well as the excerpt in the sidebar.') - // send 'done' message ws.send(`done: ${postSlug}`) })