Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | /**
* Eleventy Utilities
*
* Helper functions for Eleventy operations.
*/
import fs from 'fs-extra';
import path from 'path';
/**
* EleventyUtils - Utility functions for Eleventy
*/
export class EleventyUtils {
/**
* Create a basic Eleventy site directory
*/
async createSiteDir(
directory: string,
title: string,
configFormat: 'js' | 'json' = 'js'
): Promise<void> {
// Create directory structure
await fs.ensureDir(directory);
await fs.ensureDir(path.join(directory, 'src'));
await fs.ensureDir(path.join(directory, 'src', '_includes'));
await fs.ensureDir(path.join(directory, 'src', '_data'));
await fs.ensureDir(path.join(directory, '_site'));
// Create .eleventy.js config file
if (configFormat === 'js') {
const configContent = `module.exports = function(eleventyConfig) {
// Copy static assets
eleventyConfig.addPassthroughCopy("src/css");
eleventyConfig.addPassthroughCopy("src/images");
return {
dir: {
input: "src",
output: "_site",
includes: "_includes",
data: "_data"
},
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
templateFormats: ["html", "njk", "md"]
};
};
`;
await fs.writeFile(path.join(directory, '.eleventy.js'), configContent);
}
// Create package.json
const packageJson = {
name: title.toLowerCase().replace(/\s+/g, '-'),
version: '1.0.0',
description: title,
scripts: {
build: 'eleventy',
serve: 'eleventy --serve',
},
devDependencies: {
'@11ty/eleventy': '^2.0.0',
},
};
await fs.writeFile(
path.join(directory, 'package.json'),
JSON.stringify(packageJson, null, 2)
);
// Create .gitignore
const gitignore = `node_modules/
_site/
.DS_Store
`;
await fs.writeFile(path.join(directory, '.gitignore'), gitignore);
// Create basic site data
const siteData = {
title: title,
description: `${title} - Built with Eleventy`,
url: 'http://localhost:8080',
};
await fs.writeFile(
path.join(directory, 'src', '_data', 'site.json'),
JSON.stringify(siteData, null, 2)
);
// Create basic index page
const indexContent = `---
layout: base.njk
title: Home
---
# Welcome to {{ site.title }}
This is a basic Eleventy site.
`;
await fs.writeFile(path.join(directory, 'src', 'index.md'), indexContent);
// Create base layout
const baseLayout = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }} - {{ site.title }}</title>
</head>
<body>
<header>
<h1>{{ site.title }}</h1>
</header>
<main>
{{ content | safe }}
</main>
<footer>
<p>© {{ site.title }}</p>
</footer>
</body>
</html>
`;
await fs.writeFile(
path.join(directory, 'src', '_includes', 'base.njk'),
baseLayout
);
}
}
|