mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 01:35:56 +01:00
[IndieKit] Add peopletag parsing
Allows me to reference @People in Indiekit-powered posts, so I don't need to write {{< friend "people" >}} in longhand.
This commit is contained in:
parent
aac4d1184b
commit
e964c41899
2 changed files with 23 additions and 2 deletions
|
@ -103,7 +103,8 @@ export const getPostTemplate = (properties, frontMatterFormat = "yaml") => {
|
|||
return frontMatter + content;
|
||||
};
|
||||
|
||||
const tagFinder = /(?<=\s|^)#[a-z0-9]+\b/ig;
|
||||
const hashtagFinder = /(?<=\s|^)#[a-z0-9]+\b/ig;
|
||||
const peopletagFinder = /(?<=\s|^)@[a-z]+\b/ig;
|
||||
|
||||
/**
|
||||
* Replaces all #HashTags with [HashTags](/tags/hashtags) and returns a compact array of the tags used
|
||||
|
@ -112,10 +113,12 @@ const tagFinder = /(?<=\s|^)#[a-z0-9]+\b/ig;
|
|||
*/
|
||||
const replaceTags = (content) => {
|
||||
let tags = [];
|
||||
content = content.replace(tagFinder, (tag) => {
|
||||
content = content.replace(hashtagFinder, (tag) => {
|
||||
tag = tag.substring(1);
|
||||
tags.push(tag);
|
||||
return `[${tag}](/tags/${tag.toLowerCase()})`;
|
||||
}).replace(peopletagFinder, (tag) => {
|
||||
return `{{< friend "${tag.substring(1).toLowerCase()}" >}}`;
|
||||
});
|
||||
|
||||
return { content, tags }
|
||||
|
|
|
@ -232,6 +232,24 @@ tags:
|
|||
---
|
||||
|
||||
[some](/tags/some) posts might have [hashtags](/tags/hashtags), even [MultiCasedOnes](/tags/multicasedones) but [fragment URLs](#heading) must be left alone.
|
||||
`,
|
||||
);
|
||||
});
|
||||
|
||||
it("Renders posts with people tags correctly", () => {
|
||||
const result = getPostTemplate({
|
||||
published: "2024-10-02",
|
||||
content: "Sometimes I reference @People, but [@fedi@example.com](https://example.com/@fedi) links and email@example.com shouldn't be changed.",
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
result,
|
||||
`---
|
||||
date: 2024-10-02
|
||||
publishDate: 2024-10-02
|
||||
---
|
||||
|
||||
Sometimes I reference {{< friend "people" >}}, but [@fedi@example.com](https://example.com/@fedi) links and email@example.com shouldn't be changed.
|
||||
`,
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue