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
/** | |
* Serialize all form data into an object | |
* {@link https://gist.github.com/kieranbarker/245182a6e6af0b05be4233881c0aa60b} | |
* @param {HTMLFormElement} form The form to serialize | |
* @returns {Object} The serialized form data | |
*/ | |
function serializeObject (form) { | |
// Create a new FormData object | |
const formData = new FormData(form); |
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
/** | |
* Serialize all form data into a query string | |
* {@link https://gist.github.com/kieranbarker/bb7c54bd12156c069419f64a22e61552} | |
* @param {HTMLFormElement} form The form | |
* @returns {String} The query string | |
*/ | |
function serialize (form) { | |
// Create a new FormData object | |
const formData = new FormData(form); |
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 last word in a string | |
* @param {String} str The string | |
* @returns {String} The last word | |
*/ | |
function getLastWord (str) { | |
return str.trim().split(/\s+/).pop(); | |
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
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
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
/** | |
* 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") { |