-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrates from Gatsby to Eleventy (#104)
* WIP: initial eleventy blog setup * WIP: adds content back in new directory structure * WIP: adds footer, with some shortcodes * WIP: attempt to fix build * limit blogs on home to 5, display tags * clean up footer, blog post header, tag list * adds projects to home * adds read time * adds list of all tags with post counts * adds links to all tags/posts * roughs in dark mode toggle * WIP: css styles roughed in * styles toggle color mode button * background color mode animation * WIP: header styles * better style organization with sass * merges in latest blog post * disable prettier html formatting * styling improvements * rename index to html, styles project list * updated intro * adds social media icons with 11ty image plugin * update website description * filter 'posts' from tag list and cleanup formatting * blog header styling/content tweaks * adds background-highlight to header/footer and dropshadow for avatar pop-up * tweak font and margins * groups blog posts by year * lowers width of header/footer background gradient * adds meta info, canonical urls, favicon * adds nvmrc set to 18.12 * adds missing image * moves assets into static folder * renames blog folder to 'posts' * adds existing social share cards as meta image * adds site url prefix for social images * switches permalink to exclude date, and removes nunjucks specific filter * creates social share layout and build mode * adds social share card generator script * fix svg icons * removes console.log * tweaks to social-card settings * adds 404 page * updates history in about * fixes metaDesc * adds skip-nav id to h1 * adds more fallback fonts for headings * cleanup
- Loading branch information
1 parent
9ace282
commit d9f93ab
Showing
145 changed files
with
7,585 additions
and
38,064 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
const sass = require("sass") | ||
const config = require("./package.json") | ||
const { DateTime } = require("luxon") | ||
const Image = require("@11ty/eleventy-img") | ||
|
||
// inspired by https://github.com/11ty/eleventy/issues/927#issuecomment-627703544 | ||
const getAllTags = collections => { | ||
const tags = collections | ||
.getAll() | ||
.reduce((tags, item) => tags.concat(item.data.tags), []) | ||
.filter(tag => !!tag && !["posts", "all"].includes(tag)) | ||
.sort() | ||
return Array.from(new Set(tags)).map(tag => ({ | ||
title: tag, | ||
count: collections.getFilteredByTag(tag).length, | ||
})) | ||
} | ||
|
||
// inspired by https://github.com/JKC-Codes/eleventy-plugin-time-to-read | ||
const getPlainText = content => { | ||
const html = content.templateContent || content | ||
if (typeof html !== "string") { | ||
throw new Error("Time-to-read's input must be a string or template") | ||
} | ||
|
||
// Remove html | ||
const htmlTags = String.raw`<\/?[a-z0-9]+\b[^>]*>` | ||
//Regex = '<!--' + the minimal amount of 0 or more characters + '-->' | ||
const htmlComments = String.raw`<!--[^]*?-->` | ||
// Regex = htmlTags or htmlComments | ||
return html.replace( | ||
new RegExp(String.raw`${htmlTags}|${htmlComments}`, "gi"), | ||
"" | ||
) | ||
} | ||
const getReadTime = content => { | ||
const rawText = getPlainText(content) | ||
const wpm = 265 // based on medium https://help.medium.com/hc/en-us/articles/214991667-Read-time | ||
const words = rawText.trim().split(/\s+/).length | ||
const time = Math.ceil(words / wpm) | ||
return time | ||
} | ||
|
||
module.exports = function (eleventyConfig) { | ||
// css loading | ||
eleventyConfig.addTemplateFormats("scss") | ||
eleventyConfig.addExtension("scss", { | ||
outputFileExtension: "css", // optional, default: "html" | ||
|
||
// `compile` is called once per .scss file in the input directory | ||
compile: async function (inputContent) { | ||
let result = sass.compileString(inputContent) | ||
|
||
// This is the render function, `data` is the full data cascade | ||
return async data => { | ||
return result.css | ||
} | ||
}, | ||
}) | ||
|
||
// js/image loading | ||
eleventyConfig.addPassthroughCopy("./src/global.js") | ||
eleventyConfig.addPassthroughCopy("./src/static") | ||
eleventyConfig.addNunjucksAsyncShortcode("svgIcon", async filename => { | ||
const metadata = await Image(`./src/_includes/assets/${filename}`, { | ||
formats: ["svg"], | ||
dryRun: true, | ||
}) | ||
return metadata.svg[0].buffer.toString() | ||
}) | ||
|
||
// custom collections | ||
eleventyConfig.addCollection("tagList", getAllTags) | ||
// thanks to https://github.com/11ty/eleventy/issues/1284#issuecomment-1026679407 | ||
eleventyConfig.addCollection("postsByYear", collection => { | ||
const posts = collection.getFilteredByTag("posts").reverse() | ||
const years = posts.map(post => post.date.getFullYear()) | ||
const uniqueYears = [...new Set(years)] | ||
const postsByYear = uniqueYears.reduce((prev, year) => { | ||
const filteredPosts = posts.filter( | ||
post => post.date.getFullYear() === year | ||
) | ||
return [...prev, [year, filteredPosts]] | ||
}, []) | ||
return postsByYear | ||
}) | ||
|
||
// template helpers (shortcodes and filters) | ||
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`) | ||
eleventyConfig.addShortcode("version", () => config.version) | ||
eleventyConfig.addFilter("limit", (array, limit) => array.slice(0, limit)) | ||
eleventyConfig.addFilter("timeToRead", getReadTime) | ||
eleventyConfig.addFilter("postDate", dateString => | ||
DateTime.fromISO(dateString).toLocaleString(DateTime.DATE_MED) | ||
) | ||
eleventyConfig.addFilter("exclude", (collection, stringToFilter) => { | ||
if (!stringToFilter) { | ||
return collection | ||
} | ||
return (collection ?? []).filter(item => item !== stringToFilter) | ||
}) | ||
|
||
return { | ||
dir: { | ||
input: "src", | ||
output: "public", | ||
}, | ||
markdownTemplateEngine: "njk", | ||
dataTemplateEngine: "njk", | ||
htmlTemplateEngine: "njk", | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18.12 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
package.json | ||
package-lock.json | ||
public | ||
*.html |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.