diff --git a/about.11tydata.js b/about.11tydata.js new file mode 100644 index 0000000..64bf2fb --- /dev/null +++ b/about.11tydata.js @@ -0,0 +1,21 @@ +// Template data file for about.njk +// Dynamically sets permalink based on whether about.md exists in content/pages/ +import { existsSync } from "fs"; +import { resolve, dirname } from "path"; +import { fileURLToPath } from "url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +export default function() { + // Check for about.md in content/pages/ directory + const aboutPath = resolve(__dirname, "content/pages/about.md"); + const aboutExists = existsSync(aboutPath); + + return { + // If about.md exists, disable this template's permalink + // If not, use /about/ as the permalink + permalink: aboutExists ? false : "/about/", + // Also exclude from collections if about.md exists + eleventyExcludeFromCollections: aboutExists + }; +} diff --git a/about.njk b/about.njk index 7d708c8..de50fdd 100644 --- a/about.njk +++ b/about.njk @@ -1,8 +1,6 @@ --- layout: layouts/base.njk title: About -eleventyComputed: - permalink: "{% set aboutPageExists = false %}{% for page in collections.pages %}{% if page.fileSlug == 'about' %}{% set aboutPageExists = true %}{% endif %}{% endfor %}{% if aboutPageExists %}false{% else %}/about/{% endif %}" ---