From d5458c484d07eceb16e15ec773dc7c8e54246bf6 Mon Sep 17 00:00:00 2001 From: Val <59399970+Ruulul@users.noreply.github.com> Date: Thu, 26 May 2022 14:02:28 -0300 Subject: [PATCH 1/2] YAML consideration into excerpt function --- lib.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib.js b/lib.js index c5f8516..dc5e106 100644 --- a/lib.js +++ b/lib.js @@ -30,9 +30,14 @@ export function parseFilename (filename) { } function excerpt (content) { - let excerpt_ = content.slice(0, 100) + let start = 0; + if (content.slice(0, 3) === '---') { + let secondMark = content.indexOf('---', 3) + start = secondMark > 0 ? secondMark : 0 + } + let excerpt_ = content.slice(start, 100) if (excerpt_.indexOf('\n') > 0) { - excerpt_ = excerpt_.slice(0, excerpt_.indexOf('\n') + 1) + excerpt_ = excerpt_.slice(start, excerpt_.indexOf('\n') + 1) } return excerpt_ } From 1ee537c62d62061ac780d48cac8d326a1090793e Mon Sep 17 00:00:00 2001 From: Val <59399970+Ruulul@users.noreply.github.com> Date: Thu, 26 May 2022 14:23:29 -0300 Subject: [PATCH 2/2] Run standard JS on it --- lib.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib.js b/lib.js index dc5e106..c90370e 100644 --- a/lib.js +++ b/lib.js @@ -15,7 +15,7 @@ export async function publish (cid) { body: cid }) - if(!publishResponse.ok) throw new Error("Unable to publish: " + await publishResponse.text()) + if (!publishResponse.ok) throw new Error('Unable to publish: ' + await publishResponse.text()) window.localStorage.ipns = ipnsRoot window.localStorage.ipnsCid = cid @@ -30,10 +30,13 @@ export function parseFilename (filename) { } function excerpt (content) { - let start = 0; + let start = 0 if (content.slice(0, 3) === '---') { - let secondMark = content.indexOf('---', 3) - start = secondMark > 0 ? secondMark : 0 + const secondMark = content.indexOf('---', 3) + start = + secondMark > 0 + ? secondMark + : 0 } let excerpt_ = content.slice(start, 100) if (excerpt_.indexOf('\n') > 0) { @@ -193,7 +196,7 @@ export async function mediaAdd (file) { async function _fetchPosts (cid) { const request = await fetch(`ipfs://${cid}/ipmb-db/?noResolve`, { headers: { - Accept: "application/json" + Accept: 'application/json' } }) let dirList = await request.json()