changes to hashtags and frontmatter

This commit is contained in:
Gordon Pedersen 2024-05-21 17:13:00 +10:00
parent 1b64bffe3f
commit 0ec63ea344

View file

@ -95,13 +95,34 @@ 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(/,$/gm, '')
.replace(/^tags: \[ (.*) \]$/m, "tags: $1")
.replace(/^title: "(.*)"$/m, "title: $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) {