Ignore duplicate titles and subtitles

The long-standing "make title proper" bug has finally been fixed.
Yayy! So now, basically, the title and subtitle gets set properly
even if Medium messed it up by showing some of them twice.
This commit is contained in:
Hippo 2021-03-29 21:36:09 +05:30
parent 22664a7d44
commit 1edee70807
2 changed files with 34 additions and 8 deletions

View file

@ -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

View file

@ -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}`)
})