From 8e913d915b427fd2af221fcc4dd33cefa49bd8de Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Tue, 21 May 2024 17:13:00 +1000 Subject: [PATCH] changes to hashtags and frontmatter --- src/worker.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/worker.js b/src/worker.js index 8dfd998..4fbb944 100644 --- a/src/worker.js +++ b/src/worker.js @@ -95,13 +95,33 @@ async function handleLol(body, env) { emoji: status.emoji, background: status.background, external_url: status.external_url, - status_url: `https://${status.address}.status.lol/${status.id}` + status_url: `https://${status.address}.status.lol/${status.id}`, + tags:[] } // this is the content let content = status.content + // let's get funky with the hashtags + content.match(/#\w+/g).filter((v,i,a) => a.indexOf(v) === i).forEach(hashtag => { + const tag = hashtag.substring(1) + const nonPascal = tag.replace(/([a-z])([A-Z])/g, "$1 $2") + const kebab = tag.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase() + frontmatter.tags.push(nonPascal) + content = content.replaceAll(hashtag, `[${hashtag}](/tag/${kebab}){.tag}`) + }) + + const yamlOptions = { + collectionStyle: 'flow', + simpleKeys: true + } + let frontmatterString = YAML.stringify(frontmatter, null, yamlOptions) + // weblog has some quirks with its yaml interpretation + frontmatterString = frontmatterString + .replace(/{\n/, '').replace(/}\n/, '').replace(/^\s\s/gm, '') + .replace(/^tags: \[ (.*) \]$/m, "tags: $1") + // this is the actual markdown - let markdown = `---\n${YAML.stringify(frontmatter)}---\n\n${content}\n` + let markdown = `---\n${frontmatterString}---\n\n${content}\n` // make sure we have the env variables defined if(env.FORGEJO_TOKEN && env.FORGEJO_URL && env.GIT_REPO) {