More work - revert 11ty cfg to JS, implement go-links, humans.txt, robots.txt, and footnotes
This commit is contained in:
100
eleventy.config.js
Normal file
100
eleventy.config.js
Normal file
@@ -0,0 +1,100 @@
|
||||
import fetch from "node-fetch";
|
||||
import pugPlugin from "@11ty/eleventy-plugin-pug";
|
||||
import rssPlugin from "@11ty/eleventy-plugin-rss";
|
||||
import brokenLinksPlugin from "eleventy-plugin-broken-links";
|
||||
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
|
||||
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
|
||||
import footnote from "markdown-it-footnote";
|
||||
import { EleventyRenderPlugin, IdAttributePlugin } from '@11ty/eleventy';
|
||||
import * as fs from 'fs';
|
||||
import * as opml from 'opml';
|
||||
|
||||
const OUTLINE = {
|
||||
url: 'https://outline.garrettmills.dev/api',
|
||||
apiKey: 'ol_api_oyqeX4YSeUe8L1GKvrcGusYpHjyjIAtrSqUHJt',
|
||||
documentId: '2abb5ebe-f856-4566-a21b-eab845f8dfdd',
|
||||
}
|
||||
|
||||
export default function (eleventyConfig) {
|
||||
eleventyConfig.setInputDirectory("src")
|
||||
eleventyConfig.addPlugin(brokenLinksPlugin);
|
||||
eleventyConfig.addPlugin(pugPlugin);
|
||||
eleventyConfig.addPlugin(rssPlugin);
|
||||
eleventyConfig.addPlugin(syntaxHighlight);
|
||||
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
|
||||
htmlOptions: {
|
||||
imgAttributes: {
|
||||
alt: '',
|
||||
},
|
||||
},
|
||||
});
|
||||
eleventyConfig.addPlugin(IdAttributePlugin);
|
||||
eleventyConfig.addPlugin(EleventyRenderPlugin);
|
||||
eleventyConfig.addPassthroughCopy("src/assets/**")
|
||||
eleventyConfig.amendLibrary("md", md => md.use(footnote))
|
||||
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 []
|
||||
})
|
||||
|
||||
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] = []
|
||||
postsByYear[year] = [post, ...postsByYear[year]]
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user