2025-06-02 09:52:58 -04:00
|
|
|
import fetch from "node-fetch";
|
2025-03-20 22:59:45 -04:00
|
|
|
import pugPlugin from "@11ty/eleventy-plugin-pug";
|
2025-03-26 23:04:06 -04:00
|
|
|
import rssPlugin from "@11ty/eleventy-plugin-rss";
|
2025-03-25 21:16:39 -04:00
|
|
|
import brokenLinksPlugin from "eleventy-plugin-broken-links";
|
2025-03-20 22:59:45 -04:00
|
|
|
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
|
2025-03-25 21:43:54 -04:00
|
|
|
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
|
2025-06-03 21:29:37 -04:00
|
|
|
import footnote from "markdown-it-footnote";
|
2025-03-25 21:43:54 -04:00
|
|
|
import { EleventyRenderPlugin, IdAttributePlugin } from '@11ty/eleventy';
|
2025-03-21 01:57:13 -04:00
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as opml from 'opml';
|
2025-03-20 22:59:45 -04:00
|
|
|
|
2025-06-02 09:52:58 -04:00
|
|
|
const OUTLINE = {
|
|
|
|
|
url: 'https://outline.garrettmills.dev/api',
|
|
|
|
|
apiKey: 'ol_api_oyqeX4YSeUe8L1GKvrcGusYpHjyjIAtrSqUHJt',
|
|
|
|
|
documentId: '2abb5ebe-f856-4566-a21b-eab845f8dfdd',
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 22:59:45 -04:00
|
|
|
export default function (eleventyConfig) {
|
|
|
|
|
eleventyConfig.setInputDirectory("src")
|
2025-03-25 21:16:39 -04:00
|
|
|
eleventyConfig.addPlugin(brokenLinksPlugin);
|
2025-03-20 22:59:45 -04:00
|
|
|
eleventyConfig.addPlugin(pugPlugin);
|
2025-03-26 23:04:06 -04:00
|
|
|
eleventyConfig.addPlugin(rssPlugin);
|
2025-03-25 21:43:54 -04:00
|
|
|
eleventyConfig.addPlugin(syntaxHighlight);
|
2025-03-25 21:13:49 -04:00
|
|
|
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
|
|
|
|
|
htmlOptions: {
|
|
|
|
|
imgAttributes: {
|
|
|
|
|
alt: '',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-03-25 21:43:54 -04:00
|
|
|
eleventyConfig.addPlugin(IdAttributePlugin);
|
2025-03-21 01:57:13 -04:00
|
|
|
eleventyConfig.addPlugin(EleventyRenderPlugin);
|
|
|
|
|
eleventyConfig.addPassthroughCopy("src/assets/**")
|
2025-06-03 21:29:37 -04:00
|
|
|
eleventyConfig.amendLibrary("md", md => md.use(footnote))
|
2025-06-02 09:52:58 -04:00
|
|
|
eleventyConfig.addCollection("markmark", async api => {
|
|
|
|
|
const response = await fetch(`${OUTLINE.url}/documents.info`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${OUTLINE.apiKey}`,
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
id: OUTLINE.documentId,
|
|
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if ( !response.ok ) {
|
|
|
|
|
throw new Error('Unable to load bookmarks from Outline: response was not okay')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const body = await response.json()
|
|
|
|
|
console.log('body', body)
|
|
|
|
|
return []
|
|
|
|
|
})
|
|
|
|
|
|
2025-03-21 01:57:13 -04:00
|
|
|
eleventyConfig.addCollection("blogByYear", api => {
|
|
|
|
|
const postsByYear = {}
|
|
|
|
|
const posts = api.getFilteredByTag('blog')
|
|
|
|
|
const years = []
|
|
|
|
|
for ( const post of posts ) {
|
|
|
|
|
const year = post.date.getFullYear()
|
|
|
|
|
if ( !postsByYear[year] ) postsByYear[year] = []
|
2025-03-25 21:13:49 -04:00
|
|
|
postsByYear[year] = [post, ...postsByYear[year]]
|
2025-03-21 01:57:13 -04:00
|
|
|
if ( !years.includes(year) ) years.push(year)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return years.sort().reverse().map(year => ({
|
|
|
|
|
year,
|
|
|
|
|
posts: postsByYear[year],
|
|
|
|
|
}))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
eleventyConfig.addCollection("blogByTag", api => {
|
|
|
|
|
const postsByTag = {}
|
|
|
|
|
const posts = api.getFilteredByTag('blog')
|
|
|
|
|
const tags = []
|
|
|
|
|
for ( const post of posts ) {
|
|
|
|
|
for ( const tag of post.data.blogtags || [] ) {
|
|
|
|
|
if ( !postsByTag[tag] ) postsByTag[tag] = []
|
|
|
|
|
postsByTag[tag].push(post)
|
|
|
|
|
if ( !tags.includes(tag) ) tags.push(tag)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tags.sort().map(tag => ({
|
|
|
|
|
tag,
|
|
|
|
|
posts: postsByTag[tag],
|
|
|
|
|
}))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
eleventyConfig.addCollection("opmlByCategory", async api => {
|
|
|
|
|
const xml = fs.readFileSync("./src/assets/rss_opml.xml")
|
|
|
|
|
const parsed = await new Promise((res, rej) => {
|
|
|
|
|
opml.parse(xml, (err, doc) => err ? rej(err) : res(doc))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return parsed.opml.body.subs
|
|
|
|
|
})
|
2025-03-20 22:59:45 -04:00
|
|
|
}
|
|
|
|
|
|