Skip to content

Commit

Permalink
rough draft
Browse files Browse the repository at this point in the history
  • Loading branch information
atuttle committed Feb 6, 2021
1 parent f44eab8 commit a6a6c6f
Show file tree
Hide file tree
Showing 53 changed files with 18,145 additions and 10 deletions.
49 changes: 49 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 11ty configuration
const dev = (global.dev = process.env.ELEVENTY_ENV === "development"),
now = new Date();

module.exports = (config) => {
/* --- PLUGINS --- */
// navigation
config.addPlugin(require("@11ty/eleventy-navigation"));

/* --- TRANSFORMS -- */
// inline assets
config.addTransform("inline", require("./lib/transforms/inline"));
// minify HTML
config.addTransform("htmlminify", require("./lib/transforms/htmlminify"));
// CSS processing
config.addTransform("postcss", require("./lib/transforms/postcss"));

/* --- FILTERS --- */
// format dates
const dateformat = require("./lib/filters/dateformat");
config.addFilter("datefriendly", dateformat.friendly);
config.addFilter("dateymd", dateformat.ymd);
// format word count and reading time
config.addFilter("readtime", require("./lib/filters/readtime"));

/* --- SHORTCODES --- */
// page navigation
config.addShortcode("navlist", require("./lib/shortcodes/navlist.js"));

/* --- CUSTOM COLLECTIONS --- */
// post collection (in src/episodes)
config.addCollection("post", (collection) =>
collection
.getFilteredByGlob("./src/episodes/*.md")
.filter((p) => dev || (!p.data.draft && p.date <= now))
);

/* --- WATCH FOLDERS --- */
config.addWatchTarget("./src/scss/");
config.addWatchTarget("./src/js/");

// 11ty defaults
return {
dir: {
input: "src",
output: "build",
},
};
};
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
node_modules
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Craig Buckler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Working Code Podcast

https://workingcode.dev

Built with [Eleventy](https://www.11ty.dev/).

---

Based on: https://github.com/craigbuckler/11ty-starter

## Development

`$ npm start` and navigate to http://localhost:8080

## Production

`npm run production` outputs to `./build` as the hosting root.
10 changes: 0 additions & 10 deletions index.html

This file was deleted.

20 changes: 20 additions & 0 deletions lib/filters/dateformat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// date formatting functions
const toMonth = new Intl.DateTimeFormat('en', { month: 'long' });


// format a date to YYYY-MM-DD
module.exports.ymd = date => (

date instanceof Date ?
`${ date.getUTCFullYear() }-${ String(date.getUTCMonth() + 1).padStart(2, '0') }-${ String(date.getUTCDate()).padStart(2, '0') }` : ''

);


// format a date to DD MMMM, YYYY
module.exports.friendly = date => (

date instanceof Date ?
date.getUTCDate() + ' ' + toMonth.format(date) + ', ' + date.getUTCFullYear() : ''

);
15 changes: 15 additions & 0 deletions lib/filters/readtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// format number of words and reading time
const
roundTo = 10,
readPerMin = 200,
numFormat = new Intl.NumberFormat('en');

module.exports = count => {

const
words = Math.ceil(count / roundTo) * roundTo,
mins = Math.ceil(count / readPerMin);

return `${ numFormat.format(words) } words, ${ numFormat.format(mins) }-minute read`;

};
48 changes: 48 additions & 0 deletions lib/shortcodes/navlist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// generates a page navigation list
const
listType = 'ul',
elementActive = 'strong',
classActive = 'active',
classOpen = 'open';

// pass in collections.all | eleventyNavigation, (current) page, and maximum depth level
module.exports = (pageNav, page, maxLevel = 999) => {

function navRecurse(entry, level = 1) {

let childPages = '';

if (level < maxLevel) {
for (let child of entry.children) {
childPages += navRecurse(child, level++);
}
}

let
active = (entry.url === page.url),
classList = [];

if ((active && childPages) || childPages.includes(`<${ elementActive }>`)) classList.push(classOpen);
if (active) classList.push(classActive);

return (
'<li' +
(classList.length ? ` class="${ classList.join(' ') }"` : '') +
'>' +
(active ? `<${ elementActive }>` : `<a href="${ entry.url }">`) +
entry.title +
(active ? `</${ elementActive }>` : '</a>') +
(childPages ? `<${ listType }>${ childPages }</${ listType }>` : '') +
'</li>'
);

}

let nav = '';
for (let entry of pageNav) {
nav += navRecurse(entry);
}

return `<${ listType }>${ nav }</${ listType }>`;

};
14 changes: 14 additions & 0 deletions lib/transforms/htmlminify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// minify HTML
const htmlmin = require('html-minifier');

module.exports = (content, outputPath = '.html') => {

if (!String(outputPath).endsWith('.html')) return content;

return htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});

};
13 changes: 13 additions & 0 deletions lib/transforms/inline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// inline data
const { inlineSource } = require('inline-source');

module.exports = async (content, outputPath) => {

if (!String(outputPath).endsWith('.html')) return content;

return await inlineSource(content, {
compress: true,
rootpath: './build/'
});

};
26 changes: 26 additions & 0 deletions lib/transforms/postcss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// PostCSS CSS processing

/* global dev */

const
postcss = require('postcss'),
postcssPlugins = [
require('postcss-advanced-variables'),
require('postcss-nested'),
require('cssnano')
],
postcssOptions = {
from: 'src/scss/entry.scss',
syntax: require('postcss-scss'),
map: dev ? { inline: true } : false
};

module.exports = async (content, outputPath) => {

if (!String(outputPath).endsWith('.css')) return content;

return (
await postcss(postcssPlugins).process(content, postcssOptions)
).css;

};
Loading

0 comments on commit a6a6c6f

Please sign in to comment.