2023-12-22 12:59:16 +00:00
|
|
|
import { determineTags } from "$sb/lib/cheap_yaml.ts";
|
|
|
|
|
2023-11-09 08:26:44 +00:00
|
|
|
const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quick and dirty way to check if a page is a template or not
|
|
|
|
* @param pageText
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
export function isTemplate(pageText: string): boolean {
|
|
|
|
const frontmatter = frontMatterRegex.exec(pageText);
|
|
|
|
// Poor man's YAML frontmatter parsing
|
|
|
|
if (frontmatter) {
|
|
|
|
pageText = pageText.slice(frontmatter[0].length);
|
|
|
|
const frontmatterText = frontmatter[1];
|
2023-12-22 12:59:16 +00:00
|
|
|
const tags = determineTags(frontmatterText);
|
|
|
|
if (tags.includes("template")) {
|
|
|
|
return true;
|
2023-11-09 08:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Or if the page text starts with a #template tag
|
|
|
|
if (/^\s*#template(\W|$)/.test(pageText)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|