-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 containing cleanup eleventy config & updated de…
…pendencies
- Loading branch information
Showing
10 changed files
with
174 additions
and
133 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
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,77 @@ | ||
const slugify = require('slugify') | ||
|
||
/* Creating a collection containing all blogposts by filtering based on folder and filetype */ | ||
const getAllPosts = (collectionApi) => { | ||
return collectionApi.getFilteredByGlob('./src/blog/*.md') | ||
.reverse() | ||
} | ||
|
||
const getCategoryList = (collectionApi) => { | ||
const catPages = [] | ||
let categories = [] | ||
const blogPosts = collectionApi.getFilteredByGlob('./src/blog/*.md') | ||
|
||
blogPosts.map((item) => { | ||
categories.push(item.data.category) | ||
}) | ||
|
||
categories = categories.sort(sortAlphabetically) | ||
const temp = [...new Set(categories)] | ||
|
||
temp.forEach((category) => { | ||
const slug = strToSlug(category); | ||
|
||
if(slug !== 'in-the-spotlight') { | ||
catPages.push({ | ||
'key': slug, | ||
'name': category | ||
}) | ||
} | ||
}) | ||
|
||
return catPages | ||
} | ||
|
||
const getCategorisedPosts = (collectionApi) => { | ||
const categorisedPosts = {} | ||
|
||
collectionApi.getFilteredByGlob('./src/blog/*.md').forEach(item => { | ||
const category = item.data.category | ||
|
||
// Ignore the ones without a category | ||
if (typeof category !== 'string') | ||
return | ||
|
||
const slug = strToSlug(category) | ||
|
||
if (Array.isArray(categorisedPosts[slug])) { | ||
categorisedPosts[slug].push(item) | ||
} else { | ||
categorisedPosts[slug] = [item] | ||
} | ||
}) | ||
|
||
return categorisedPosts | ||
} | ||
|
||
module.exports = { | ||
getAllPosts, | ||
getCategoryList, | ||
getCategorisedPosts | ||
} | ||
|
||
|
||
function strToSlug(str) { | ||
const options = { | ||
replacement: "-", | ||
remove: /[&,+()$~%.'":*?<>{}]/g, | ||
lower: true, | ||
} | ||
|
||
return slugify(str, options) | ||
} | ||
|
||
|
||
function sortAlphabetically(a, b) { | ||
return a.localeCompare(b, "en", { sensitivity: "base" }) | ||
} |
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,11 @@ | ||
const { DateTime } = require('luxon') | ||
|
||
const readableDate = (dateObj) => { | ||
return DateTime.fromJSDate(dateObj, { | ||
zone: 'Europe/Paris', | ||
}).setLocale('en').toLocaleString(DateTime.DATE_FULL) | ||
} | ||
|
||
module.exports = { | ||
readableDate | ||
} |
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,30 @@ | ||
const Image = require('@11ty/eleventy-img') | ||
|
||
const imageShortcode = async (imageObj = {}) => { | ||
const widths = imageObj.widths || [300, 600, 900, 1200] | ||
const className = imageObj.className || "image" | ||
|
||
const sizes = "(min-width: 100px) 50vw, 100vw" | ||
const metadata = await Image(imageObj.src, { | ||
formats: ["webp"], | ||
outputDir: "./_site/assets/images/generated/", | ||
urlPath: "/assets/images/generated/", | ||
widths: widths | ||
}) | ||
const alt = imageObj.alt; | ||
|
||
const imageAttributes = { | ||
class: className, | ||
alt, | ||
sizes, | ||
loading: "lazy", | ||
decoding: "async", | ||
} | ||
|
||
return Image.generateHTML(metadata, imageAttributes) | ||
} | ||
|
||
|
||
module.exports = { | ||
imageShortcode | ||
} |
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 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
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