diff --git a/.eleventy.js b/.eleventy.js index b2c1082..28f22fa 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,8 +1,19 @@ /* jshint strict: false */ +import fs from 'fs/promises'; import {HtmlBasePlugin} from "@11ty/eleventy"; import pluginWebc from "@11ty/eleventy-plugin-webc"; +async function hasFiles(dirPath) { + try { + const entries = await fs.readdir(dirPath, {withFileTypes: true}); + return entries.some(entry => entry.isFile()); + } catch (err) { + console.error('Error reading directory:', err); + return false; + } +} + // noinspection JSUnusedGlobalSymbols export default async function (eleventyConfig) { eleventyConfig.addPlugin(HtmlBasePlugin); @@ -19,6 +30,9 @@ export default async function (eleventyConfig) { eleventyConfig.addGlobalData('permalink', () => { return (data) => `${data.page.filePathStem}.${data.page.outputFileExtension}`; }); + + const demoPath = await hasFiles('source/screens') ? '/demo/' : '/'; + eleventyConfig.addGlobalData('hippie', { brand: 'hippie', titlePrefix: '', @@ -30,6 +44,7 @@ export default async function (eleventyConfig) { mail: 'name@domain.tld', domain: 'https://domain.tld' }, + demoPath: demoPath, debugMode: true, legacyMode: false }); @@ -85,7 +100,6 @@ export default async function (eleventyConfig) { - `; let output = ''; @@ -124,6 +138,5 @@ export default async function (eleventyConfig) { data: '../data' }, templateFormats: ['html', 'liquid', 'md'] - // pathPrefix: './demo/' }; } diff --git a/source/screens/demo/index.liquid b/source/screens/demo/index.liquid index 684b6b3..a07c2d4 100644 --- a/source/screens/demo/index.liquid +++ b/source/screens/demo/index.liquid @@ -1,5 +1,5 @@ --- -permalink: "/" +permalink: "{{ hippie.demoPath }}" title: Index --- {% assign pageId = page.fileSlug -%}