changes to hashtags and frontmatter
This commit is contained in:
parent
1b64bffe3f
commit
8e913d915b
1 changed files with 22 additions and 2 deletions
|
@ -95,13 +95,33 @@ async function handleLol(body, env) {
|
||||||
emoji: status.emoji,
|
emoji: status.emoji,
|
||||||
background: status.background,
|
background: status.background,
|
||||||
external_url: status.external_url,
|
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
|
// this is the content
|
||||||
let content = status.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
|
// 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
|
// make sure we have the env variables defined
|
||||||
if(env.FORGEJO_TOKEN && env.FORGEJO_URL && env.GIT_REPO) {
|
if(env.FORGEJO_TOKEN && env.FORGEJO_URL && env.GIT_REPO) {
|
||||||
|
|
Loading…
Reference in a new issue