Skip to content

Commit

Permalink
Merge pull request #55 from AristurtleDev/convert-to-11ty
Browse files Browse the repository at this point in the history
Convert Site Generator to 11ty
  • Loading branch information
tomspilman authored Jan 10, 2024
2 parents 60fe9f4 + baa0cfc commit d7b1f4c
Show file tree
Hide file tree
Showing 292 changed files with 7,374 additions and 3,508 deletions.
29 changes: 29 additions & 0 deletions .config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# **/.config/** Directory
This directory contains all of the configurations setup for 11ty. 11ty can have various configurations such as which files to ignore, which files to watch, which files to copy only and not process, etc.

Reference: https://www.11ty.dev/docs/config/

Instead of creating a single monolithic configuration file, each of these possible configurations are broken down into their own files in this directory.

When a specific configuration relies on an external module or plug-in that has been created, that module lives inside of a directory named after the configuration type it is for. For example. 11ty `Filter`s that have been created live inside the `/_config/filters` directory.

The following table is a demonstration of how the files and directories contained here are structured:

| File/Directory Name | Description | Reference |
| ------------------------------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| eleventy.config.**collections**.js | Contains the 11ty configuration for all collections added | https://www.11ty.dev/docs/collections/ |
| eleventy.config.**dataExtensions**.js | Contains the 11ty configuration logic for all data extensions. | https://www.11ty.dev/docs/data-custom/ |
| eleventy.config.**filters**.js | Contains the 11ty configuration logic for all custom template filters. | https://www.11ty.dev/docs/filters/ |
| eleventy.config.**ignores**.js | Contains the 11ty configuration for all file ignore logic. | https://www.11ty.dev/docs/ignores/ |
| eleventy.config.**libraries**.js | Contains the 11ty configuration logic for all libraries used in 11ty. | https://www.11ty.dev/docs/languages/markdown/#add-your-own-plugins |
| eleventy.config.**passthrough**.js | Contains the 11ty configuration logic for all file pass through copies. | https://www.11ty.dev/docs/copy/ |
| eleventy.config.**plugins**.js | Contains the 11ty configuration for all 11ty plugins used. | https://www.11ty.dev/docs/plugins/#add-the-plugin-to-eleventy-in-your-config-file |
| eleventy.config.**transforms**.js | Contains the 11ty configuration for all transforms. | https://www.11ty.dev/docs/config/#transforms |
| eleventy.config.**watchtargets**.js | Contains the 11ty configuration for all watch targets during development. | https://www.11ty.dev/docs/watch-serve/#add-your-own-watch-targets |
| **/collections/** | Each file contains the logic to build the data for that specific collection | |
| **/filters/** | Each file contains the logic to handle that specific filter. | |
| **/markdownit-plugins/** | Custom plugins written for the markdown-it markdown renderer to handle difference scenarios. | |
| **/transforms/** | Each file contains the transform logic used to transform input data before it is output. | |


This directory also contains the `dotnet-tools.json` manifest file for the dotnet tools installation.
62 changes: 62 additions & 0 deletions .config/collections/apiToc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

const fs = require('fs');
const yaml = require('js-yaml');

function filterElementsWithoutHref(element) {
if (!element || !element.hasOwnProperty('href')) {
return true;
}

if (element.items) {
element.items = element.items.filter((item) => !filterElementsWithoutHref(item));
}

return false;
}

function removeMDExtension(json) {
json.forEach((element) => {
if (element.href) {
element.href = element.href.replace(/\.md$/, '');
}

if (element.items) {
element.items.forEach((item) => {
if (item.href) {
item.href = item.href.replace(/\.md$/, '');
}
});
removeMDExtension(element.items);
}
});
}

function sortElements(elements) {
elements.forEach((element) => {
if (element.items) {
element.items.sort((a, b) => a.name.localeCompare(b.name));
sortElements(element.items);
}
});
}

/** @param {import("@11ty/eleventy/src/TemplateCollection")} api */
function apiToc(api) {
try {
const data = fs.readFileSync('./content/api/toc.yml', 'utf-8');
let json = yaml.load(data);
json = json.filter((element) => !filterElementsWithoutHref(element));
removeMDExtension(json);
sortElements(json);
return json;
} catch (err) {
console.warn("'/content/api/toc.yml' is missing. API documentation will not be generated");
console.warn("If you wanted to include API documentation in your local build run the following command");
console.warn("npm run docfx");
console.warn("Note: including API documentation in local builds may increase build times");
return [];
}
}

module.exports = apiToc;
17 changes: 17 additions & 0 deletions .config/collections/articlesToc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const fs = require('fs');
const yaml = require('js-yaml');

/** @param {import("@11ty/eleventy/src/TemplateCollection")} api */
function articlesToc(api) {
try {
const data = fs.readFileSync('./content/articles/toc.yml', 'utf-8');
return yaml.load(data);
} catch(err) {
console.error(err);
return [];
}
}

module.exports = articlesToc;
8 changes: 8 additions & 0 deletions .config/collections/blogPosts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

/** @param {import("@11ty/eleventy/src/TemplateCollection")} api */
function blogPosts(api) {
return api.getFilteredByGlob('./content/blog/*.md').sort((a, b) => a.date - b.date);
}

module.exports = blogPosts;
18 changes: 18 additions & 0 deletions .config/collections/blogTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

/** @param {import("@11ty/eleventy/src/TemplateCollection")} api */
function blogTags(api) {
let tags = [];
let posts = api.getFilteredByGlob('./content/blog/*.md');

posts.forEach((post) => {
if(post.data.tags) {
tags.push(...post.data.tags);
}
});

tags = tags.filter((value, index) => tags.indexOf(value) === index).sort();
return ['all'].concat(tags);
}

module.exports = blogTags;
19 changes: 19 additions & 0 deletions .config/collections/gameTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const games = require('../../_data/games.json');

/** @param {import("@11ty/eleventy/src/TemplateCollection")} api */
function gameTags(api) {
let tags = [];

games.forEach((game) => {
if(game.tags) {
tags.push(...game.tags);
}
});

tags = tags.filter((value, index) => tags.indexOf(value) === index).sort();
return ['all'].concat(tags);
}

module.exports = gameTags;
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"docfx": {
"version": "2.70.4",
"version": "2.74.1",
"commands": [
"docfx"
]
Expand Down
17 changes: 17 additions & 0 deletions .config/eleventy.config.collections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const blogPosts = require('./collections/blogPosts');
const blogTags = require('./collections/blogTags');
const gameTags = require('./collections/gameTags');
const apiToc = require('./collections/apiToc');
const articlesToc = require('./collections/articlesToc');


/** @param {import("@11ty/eleventy").UserConfig} config */
module.exports = function (config) {
config.addCollection('blogPosts', blogPosts);
config.addCollection('blogTags', blogTags);
config.addCollection('gameTags', gameTags);
config.addCollection('apiToc', apiToc);
config.addCollection('articlesToc', articlesToc);
}
10 changes: 10 additions & 0 deletions .config/eleventy.config.dataExtensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const yaml = require('js-yaml');

/** @param {import("@11ty/eleventy").UserConfig} config */
module.exports = function (config) {
config.addDataExtension('yml', function (content) {
return yaml.load(content);
});
}
18 changes: 18 additions & 0 deletions .config/eleventy.config.filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const readableDate = require('./filters/readableDate');
const htmlDateString = require('./filters/htmlDateString');
const tableOfContents = require('./filters/tableOfContents');
const cssmin = require('./filters/cssmin');

/** @param {import("@11ty/eleventy").UserConfig} config */
module.exports = function (config) {
// Convert date values into human readable dates
config.addFilter('readableDate', readableDate);
config.addFilter('htmlDateString', htmlDateString);

// Creates a table of contents based on a given toc collection
config.addFilter('tableOfContents', tableOfContents);

config.addFilter('cssmin', cssmin);
}
6 changes: 6 additions & 0 deletions .config/eleventy.config.ignores.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @param {import("@11ty/eleventy").UserConfig} config */
module.exports = function(config) {
config.setUseGitIgnore(false);
config.ignores.add('./public/css/**/*.css');
config.ignores.add('./public/js/**/*.js');
}
24 changes: 24 additions & 0 deletions .config/eleventy.config.libraries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

const mdAnchor = require('markdown-it-anchor');
const mdLink = require('./markdownit-plugins/link');
const mdAdmonitions = require('./markdownit-plugins/admonitions');

/** @param {import("@11ty/eleventy").UserConfig} config */
module.exports = function (config) {
config.amendLibrary('md', md => md.use(mdAnchor, {
slugify: (s) => config.getFilter('slugify')(s.replace(/\d+/g, '')),
permalink: mdAnchor.permalink.headerLink()
}));

// Setup external links to open in new tab
config.amendLibrary('md', md => md.use(mdLink, {eleventyConfig: config}));

// Setup admonition support
config.amendLibrary('md', md => md.use(mdAdmonitions));

// Setup tables to be formatted by default using bootstrap styling
config.amendLibrary('md', md => md.use((m) => {
m.renderer.rules.table_open = (tokens, id) => '<table class="table table-bordered table-condensed">';
}));
}
17 changes: 17 additions & 0 deletions .config/eleventy.config.passthrough.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

/** @param {import("@11ty/eleventy").UserConfig} config */
module.exports = function (config) {
config.addPassthroughCopy({ "static": "/" });
config.addPassthroughCopy('content/articles/**/*.{png, jpg, jpeg}');
config.addPassthroughCopy('content/blog/**/*.{png, jpg, jpeg}');
config.addPassthroughCopy({ "content/public/images": "/images" });
config.addPassthroughCopy({ "content/static/**/*": "/"});
config.addPassthroughCopy({ "content/public/js/**/*.js": "/js" });
config.addPassthroughCopy({
"node_modules/bootstrap-icons/font/fonts": "/fonts"
});
config.addPassthroughCopy({
"node_modules/bootstrap/dist/js/bootstrap.bundle.min.js": "/js/bootstrap.bundle.min.js"
});
}
20 changes: 20 additions & 0 deletions .config/eleventy.config.plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'
const navigation = require('@11ty/eleventy-navigation');
const syntaxhighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const nesting = require('eleventy-plugin-nesting-toc');
const { EleventyHtmlBasePlugin } = require('@11ty/eleventy');


/** @param {import("@11ty/eleventy").UserConfig} config */
module.exports = function (config) {
config.addPlugin(navigation);
config.addPlugin(syntaxhighlight);
config.addPlugin(nesting, {
tags: ['h2', 'h3'],
wrapper: 'nav',
wrapperClass: 'nav flex-column',
headingText: 'In This Article',
headingTag: 'h5'
});
config.addPlugin(EleventyHtmlBasePlugin);
}
13 changes: 13 additions & 0 deletions .config/eleventy.config.transforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

const xref = require('./transforms/xref');

/** @param {import("@11ty/eleventy").UserConfig} config */
module.exports = function (config) {
config.addTransform('xref', function(content) {
if(this.page.inputPath.includes('.md') && this.page.outputPath.endsWith('.html')) {
return xref(content);
}
return content;
});
}
6 changes: 6 additions & 0 deletions .config/eleventy.config.watchtargets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @param {import("@11ty/eleventy").UserConfig} config */
module.exports = function(config) {
config.addWatchTarget('./content/public/css/**/*.css');
config.addWatchTarget('./content/public/js/**/*.js');
config.addWatchTarget('./content/public/images/**/*');
}
9 changes: 9 additions & 0 deletions .config/filters/cssmin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const cleanCss = require("clean-css");

function cssmin(css) {
return new cleanCss({}).minify(css).styles;
}

module.exports = cssmin;
7 changes: 7 additions & 0 deletions .config/filters/htmlDateString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const { DateTime } = require('luxon');

module.exports = function(date) {
return DateTime.fromJSDate(date, {zone: 'utc'}).toFormat('yyyy-LL-dd');
}
7 changes: 7 additions & 0 deletions .config/filters/readableDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const { DateTime } = require('luxon');

module.exports = function(date) {
return DateTime.fromJSDate(date).toLocaleString(DateTime.DATE_MED);
}
Loading

0 comments on commit d7b1f4c

Please sign in to comment.