Skip to content

Commit

Permalink
Merge pull request #37 from MWDelaney/main-updates
Browse files Browse the repository at this point in the history
Merge latest from main
  • Loading branch information
MWDelaney authored Nov 5, 2024
2 parents 2be413c + eb2be5c commit 5ec6b5a
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 203 deletions.
262 changes: 115 additions & 147 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const siteName = "ZeroPoint";

/**
* Wait! Before you edit this file!
* This Eleventy-based project abstracts the traditional `.eleventy.js` file to help keep things clean and tidy.
Expand All @@ -9,209 +11,176 @@
* - `src/config/watchtargets.js`
* - `src/config/templateLanguages.js`
* - `src/config/filters.js`
* - `src/config/transforms.js`
*/

/**
* Passthroughs and file copies are defined as named exports in /src/config/passthroughs.js
*/
const passthroughs = require('./src/config/passthroughs');
import passthroughs from './src/config/passthroughs.js';

/**
* Collections are defined as named exports in /src/config/collections.js
*/
const collections = require('./src/config/collections');
import collections from './src/config/collections.js';

/**
* Watch targets are defined as named exports in /src/config/watchtargets.js
*/
const watchtargets = require('./src/config/watchtargets');
import watchtargets from './src/config/watchtargets.js';

/**
* Plugins are defined as named exports in /src/config/plugins.js
*/
const plugins = require('./src/config/plugins');
import plugins from './src/config/plugins.js';

/**
* Shortcodes are defined as named exports in /src/config/shortcodes.js
*/
const shortcodes = require('./src/config/shortcodes');
import shortcodes from './src/config/shortcodes.js';

/**
* Custom template languages are defined as named exports in /src/config/templateLanguages.js
*/
const templateLanguages = require('./src/config/templateLanguages');
import templatelanguages from './src/config/templateLanguages.js';

/**
* Filters are defined as named exports in /src/config/filters.js
*/
const filters = require('./src/config/filters');
import filters from './src/config/filters.js';

/**
* Import the bundler configuration from /src/config/build.js
*/
const build = require('./src/config/build');
import build from './src/config/build.js';

/**
* Import transforms from /src/config/transforms.js
*/
import transforms from './src/config/transforms.js';

/**
* Any additional requirements can be added here
*/
const fs = require("fs");
const chalk = require("chalk");
const htmlmin = require("html-minifier");
import chalk from 'chalk';

/**
* Eleventy configuration
* https://www.11ty.dev/docs/config/
*/
module.exports = function (eleventyConfig) {
export default function(eleventyConfig) {

// An array of the tasks to be run, in order, with an icon and a pretty name for each
// Put the tasks in the order you want them to run, and set echo to false if you don't want to log the task to the console
let tasks = [
{
icon: "📚",
name: "Collections",
config: collections,
echo: true,
},
{
icon: "🔌",
name: "Plugins",
config: plugins,
echo: true,
},
{
icon: "⏩",
name: "Shortcodes",
config: shortcodes,
echo: true,
},
{
icon: "🎛️ ",
name: "Filters",
config: filters,
echo: true,
},
{
icon: "🚗",
name: "Transforms",
config: transforms,
echo: true,
},
{
icon: "📂",
name: "Passthroughs",
config: passthroughs,
echo: false,
},
{
icon: "📜",
name: "Template Languages",
config: templatelanguages,
echo: false,
},
{
icon: "👀",
name: "Watch Targets",
config: watchtargets,
echo: false,
}
];

/**
* Start pretty console output
*/
console.group("\n", " 🪐");
console.log(chalk.white(" |"));

/**
* Echo the registered collections in the terminal
* Create collections from /src/config/collections.js
*/
console.group(
chalk.white(" ├── ") +
chalk.yellow("📚 Collections ") +
chalk.gray("(/src/config/collections.js)")
);

Object.keys(collections).forEach((collectionName, index) => {
let len = Object.keys(collections).length - 1;
let pre = (index === len ? "└── " : "├── ");
console.log(
chalk.white("│ " + pre) +
chalk.green(collectionName)
);

collections[collectionName](eleventyConfig);
});

console.groupEnd();
console.log(chalk.white(" |"));

/**
* Echo the registered collections in the terminal
* Add Eleventy plugins from /src/config/plugins.js
*/
console.group(
chalk.white(" ├── ") +
chalk.yellow("🔌 Plugins ") +
chalk.gray("(/src/config/plugins.js)")
);

Object.keys(plugins).forEach((pluginName, index) => {
let len = Object.keys(plugins).length - 1;
let pre = (index == len ? "└── " : "├── ");
console.log(
chalk.white("│ " + pre) +
chalk.green(pluginName)
);

plugins[pluginName](eleventyConfig);
});
console.group("\n", " 🪐", chalk.magenta(siteName));
console.log(chalk.white(" │"));

for (let task of tasks) {
let tree = tasks.indexOf(task) === tasks.length - 1;

// If the next tasks's echo is false, don't log the tree
tree = (tasks[tasks.indexOf(task) + 1] && !tasks[tasks.indexOf(task) + 1].echo);

if(task.echo) {
console.group(
chalk.white((tree) ? " └── " : " ├── ") +
chalk.yellow(task.icon) +
chalk.yellow(" " + task.name) +
chalk.gray(" (/src/config/" + task.name.toLowerCase().replace(/\s/g, '') + ".js)")
);
}

console.groupEnd();
console.log(chalk.white(" |"));
/**
* Echo the registered shortcodes in the terminal
* Add shortcodes from /src/config/shortcodes.js
*/
console.group(
chalk.white(" └── ") +
chalk.yellow("⏩ Shortcodes ") +
chalk.gray("(/src/config/shortcodes.js)")
);

Object.keys(shortcodes).forEach((shortcodeName, index) => {
let len = Object.keys(shortcodes).length - 1;
let pre = (index === len ? "└── " : "├── ");
console.log(
chalk.white(" " + pre) +
chalk.green(shortcodeName)
);

shortcodes[shortcodeName](eleventyConfig);
});
Object.keys(task.config).forEach((taskName, index) => {
let len = Object.keys(task.config).length - 1;
let pre = (index === len ? "└── " : "├── ");

let branch = tasks.indexOf(task) === tasks.length - 1;
branch = (tasks[tasks.indexOf(task) + 1] && !tasks[tasks.indexOf(task) + 1].echo);
if(task.echo) {
console.log(
chalk.white((branch) ? " " : "│ ") + pre +
chalk.green(taskName)
);
}

// Run the task
task.config[taskName](eleventyConfig);
});

if(task.echo) {
if(!tree) {
console.log(chalk.white("│"));
}
console.groupEnd();
}
}

console.log("\n");
console.groupEnd();

/**
* Add passthrough copy from /src/config/passthroughs.js
*/
Object.keys(passthroughs).forEach((passthroughName) => {
eleventyConfig.addPassthroughCopy(passthroughs[passthroughName]())
});

/**
* Add watch targets from /src/config/watchtargets.js
*/
Object.keys(watchtargets).forEach((watchtargetName) => {
eleventyConfig.addWatchTarget(watchtargets[watchtargetName]())
});

/**
* Add template languages from /src/config/templateLanguages.js
*/
Object.keys(templateLanguages).forEach((templateLanguageName) => {
eleventyConfig.addTemplateFormats(templateLanguageName);
eleventyConfig.addExtension(templateLanguageName, templateLanguages[templateLanguageName]())
});

/**
* Add filters from /src/config/filters.js
*/
Object.keys(filters).forEach((filterName) => {
filters[filterName](eleventyConfig);
});

/**
* End pretty console output
*/
console.log("\n");
console.groupEnd();


/**
* Add build configuration from /src/config/build.js
*/
build(eleventyConfig);

/**
* Minify HTML output
*/
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
if (this.outputPath && this.outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}

return content;
});

/**
* Minify XML output
*/
eleventyConfig.addTransform("xmlmin", function (content, outputPath) {
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
if (this.outputPath && this.outputPath.endsWith(".xml")) {
let minified = htmlmin.minify(content, {
collapseWhitespace: true
});
return minified;
}

return content;
});


/**
* Configure dev server
Expand All @@ -226,7 +195,6 @@ module.exports = function (eleventyConfig) {
*/
eleventyConfig.setQuietMode(true);


/**
* Return the config to Eleventy
*/
Expand All @@ -240,4 +208,4 @@ module.exports = function (eleventyConfig) {
},
templateFormats: ['njk', 'md', '11ty.js'],
};
};
}
14 changes: 7 additions & 7 deletions README.ZeroPoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Create and edit your site **right from this readme file!**.

Or edit your entire site in a web-based editor by [clicking here](https://github.dev/MWDelaney/ZeroPoint/).
🪐 Or edit your entire site in a web-based editor by [clicking here](https://github.dev/MWDelaney/ZeroPoint/).

<details>
<summary><strong>📝 Creating and editing pages</strong></summary>
Expand All @@ -15,15 +15,15 @@ Create and edit your site **right from this readme file!**.

Create your site's main content! Pages can be written in HTML or [Markdown](https://www.markdownguide.org/basic-syntax/)!

* [Edit the homepage](https://github.com/MWDelaney/zeropoint/edit/main/src/pages/index.md)
* [Create a new page](https://github.com/MWDelaney/zeropoint/new/main/?filename=/src/pages/&value=---%0Atitle%3A%20Enter%20page%20title%20here%0A---)
* [Edit the homepage](https://github.com/MWDelaney/ZeroPoint/edit/main/src/content/pages/index.md)
* [Create a new page](https://github.com/MWDelaney/ZeroPoint/new/main/?filename=/src/content/pages/&value=---%0Atitle%3A%20Enter%20page%20title%20here%0A---)

<!--
---
#### Posts
Blog posts
* [Create a new post](https://github.com/MWDelaney/zeropoint/new/main/?filename=/src/posts/&value=----%0Atitle%3A%20%22Enter%20post%20title%22%0Adate%3A%20%222025-01-01%0A---)
* [Create a new post](https://github.com/MWDelaney/ZeroPoint/new/main/?filename=/src/content/posts/&value=----%0Atitle%3A%20%22Enter%20post%20title%22%0Adate%3A%20%222025-01-01%0A---)
-->
</details>
Expand All @@ -37,7 +37,7 @@ Blog posts

Your site's navigation is how your users will get around! Edit the site's navigation menu in [JSON format](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON)!

* [Edit the navigation](https://github.com/MWDelaney/zeropoint/edit/main/src/data/navigation.json)
* [Edit the navigation](https://github.com/MWDelaney/ZeroPoint/edit/main/src/data/navigation.json)

### Styles

Expand Down Expand Up @@ -92,7 +92,7 @@ Once you set up deployment, any time you commit to your repository's `main` bran
Ready to go deeper? Here's how ZeroPoint is laid out:

```sh
example.com # → Root of your ZeroPoint-based project
example.com # → Root of your project
├── src/ # → Source directory
│ ├── assets/ # → Site assets
│ │ ├── fonts/
Expand Down Expand Up @@ -120,7 +120,7 @@ example.com # → Root of your ZeroPoint-based project
│ └── site.json # → Site branding configuration
├── .eleventy.js # → Core Eleventy config file
├── netlify.toml # → Netlify deployment and plugin configuration (optional)
├── README.ZeroPoint.md #ZeroPoint readme
├── README.ZeroPoint.md #Template repository readme
└── README.md
```

Expand Down
Loading

0 comments on commit 5ec6b5a

Please sign in to comment.