Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migratre shortcodes and filters to ESM
- Loading branch information
1 parent
e7102f0
commit b325dd1
Showing
5 changed files
with
58 additions
and
48 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'dotenv/config'; | ||
import lightningCSSPlugin from '@11tyrocks/eleventy-plugin-lightningcss'; | ||
import RSSPlugin from '@11ty/eleventy-plugin-rss'; | ||
import markdownIt from 'markdown-it'; | ||
import mdAnchor from 'markdown-it-anchor'; | ||
import dateFilter from './src/_filters/date.js'; | ||
import starFilter from './src/_filters/stars.js'; | ||
import responsiveImage from './src/_shortcodes/image.js'; | ||
|
||
const config = (eleventy) => { | ||
// Eleventy plugins | ||
eleventy.addPlugin(lightningCSSPlugin, { nesting: true }); | ||
eleventy.addPlugin(RSSPlugin); | ||
|
||
// Custom filters | ||
eleventy.addFilter('formatDate', dateFilter); | ||
eleventy.addFilter('starRating', starFilter); | ||
|
||
// Custom shortcodes | ||
eleventy.addAsyncShortcode('image', responsiveImage); | ||
|
||
eleventy.addCollection('postsWithoutNotes', (collectionAPI) => collectionAPI.getFilteredByTag('post').filter((item) => item.data.type !== 'Note')); | ||
eleventy.addCollection('notes', (collectionAPI) => collectionAPI.getFilteredByTag('post').filter((item) => item.data.type === 'Note')); | ||
|
||
const mdOptions = { html: true, typographer: true }; | ||
const md = markdownIt(mdOptions).use(mdAnchor); | ||
|
||
eleventy.setLibrary('md', md); | ||
|
||
eleventy.addPairedShortcode('sidenote', (content, number) => { | ||
const result = md.render(content); | ||
return `<aside id="sn-${number}" class="sidenote"> | ||
<small> | ||
${result} | ||
</small> | ||
</aside>`; | ||
}); | ||
|
||
// Options | ||
return { | ||
dir: { | ||
input: 'src', | ||
}, | ||
markdownTemplateEngine: 'njk', | ||
}; | ||
}; | ||
|
||
export default config; |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
module.exports = function formattedDate(date) { | ||
const formattedDate = (date) => { | ||
const input = new Date(date); | ||
const niceDate = new Intl.DateTimeFormat( | ||
'en-US', | ||
{ day: '2-digit', month: 'short', year: 'numeric' }, | ||
).format(input); | ||
return niceDate; | ||
}; | ||
|
||
export default formattedDate; |
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