This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the JSON data from a Response object. | |
* @param {Response} response The Response object. | |
* @returns {Promise} The JSON data or an Error. | |
*/ | |
async function getJSON(response) { | |
if (response.ok) { | |
const data = await response.json(); | |
return Promise.resolve(data); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Escape double and single quotes inside a string | |
* @param {String} string The string | |
* @returns {String} The string with quotes escaped | |
*/ | |
function escapeQuotes (string) { | |
return string.replace(/"/g, """).replace(/'/g, "'"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Misc | |
*.log | |
npm-debug.* | |
*.scssc | |
*.swp | |
.DS_Store | |
Thumbs.db | |
.sass-cache | |
.env | |
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if a string is a valid email address | |
* {@link https://gist.github.com/kieranbarker/55a12cac034c386a5b3669b991290bf6} | |
* @param {String} str The string | |
* @returns {Boolean} Whether the string is a valid email address | |
*/ | |
function isValidEmail (str) { | |
// The regular expression used by [type="email"] | |
// https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address | |
const regex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add a class to an element | |
* @param {Object|String} selector A reference to an element or a CSS selector string | |
* @param {String} className The class name | |
*/ | |
function addClass (selector, className) { | |
if (selector instanceof Element) { | |
selector.classList.add(className); | |
} else if (typeof selector === "string") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = config => { | |
return { | |
markdownTemplateEngine: 'njk', | |
dataTemplateEngine: 'njk', | |
htmlTemplateEngine: 'njk', | |
dir: { | |
input: 'src', | |
output: 'dist' | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
layout: 'layouts/post.html', | |
eleventyComputed: { | |
permalink(data) { | |
if (!data.draft && new Date(data.date) <= new Date()) { | |
return data.permalink || '/blog/{{ title | slug }}/index.html'; | |
} | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns a collection of blog posts in reverse date order | |
config.addCollection('blog', collection => { | |
const isLive = post => !post.data.draft && post.date <= new Date(); | |
return collection.getFilteredByGlob('./src/posts/*.md').filter(isLive).reverse(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[redirects]] | |
from = "/:year/:month/:date/:slug" | |
to = "/blog/:slug" | |
status = 301 | |
force = true |
OlderNewer