Skip to content

Commit

Permalink
Converted to 11ty
Browse files Browse the repository at this point in the history
  • Loading branch information
AristurtleDev committed Dec 30, 2023
1 parent f3432b2 commit 1ffcfca
Show file tree
Hide file tree
Showing 283 changed files with 12,611 additions and 50 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.
124 changes: 124 additions & 0 deletions .config/collections/apiToc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
'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.error(err);
return [];
}
}

module.exports = apiToc;


// 'use strict';

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

// function filterElementsWithoutHref(element) {
// if(!element) {
// return false;
// }

// if(!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 > b.name ? 1 : -1);
// sortElements(element.items);
// }
// });
// }

// module.exports = function(collectionApi) {
// try {
// const data = fs.readFileSync('./src/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.error(err);
// return {};
// }
// }
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;
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"docfx": {
"version": "2.74.1",
"commands": [
"docfx"
]
}
}
}
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);
});
}
16 changes: 16 additions & 0 deletions .config/eleventy.config.filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const readableDate = require('./filters/readableDate');
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);

// 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');
}
8 changes: 8 additions & 0 deletions .config/eleventy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

function config() {

}

module.exports = config;

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">';
}));
}
16 changes: 16 additions & 0 deletions .config/eleventy.config.passthrough.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'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/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"
});
}
18 changes: 18 additions & 0 deletions .config/eleventy.config.plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'
const navigation = require('@11ty/eleventy-navigation');
const syntaxhighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const nesting = require('eleventy-plugin-nesting-toc');


/** @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'
});
}
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/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 1ffcfca

Please sign in to comment.