Implement page structure for blog
This commit is contained in:
@@ -1,14 +1,58 @@
|
||||
import pugPlugin from "@11ty/eleventy-plugin-pug";
|
||||
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
|
||||
import { EleventyRenderPlugin } from '@11ty/eleventy';
|
||||
import * as fs from 'fs';
|
||||
import * as opml from 'opml';
|
||||
|
||||
export default function (eleventyConfig) {
|
||||
eleventyConfig.setInputDirectory("src")
|
||||
eleventyConfig.addPlugin(pugPlugin);
|
||||
eleventyConfig.addPlugin(eleventyImageTransformPlugin);
|
||||
eleventyConfig.addPassthroughCopy("assets/img/markmark-light.svg")
|
||||
eleventyConfig.addPassthroughCopy("assets/font/obsidian/Obsidian-Roman.otf")
|
||||
eleventyConfig.addPassthroughCopy("assets/font/reckless/WEB/Reckless-Bold.woff2")
|
||||
eleventyConfig.addPassthroughCopy("assets/font/reckless/WEB/Reckless-Regular.woff2")
|
||||
eleventyConfig.addPassthroughCopy("assets/font/reckless/WEB/Reckless-RegularItalic.woff2")
|
||||
eleventyConfig.addPlugin(EleventyRenderPlugin);
|
||||
eleventyConfig.addPassthroughCopy("src/assets/**")
|
||||
|
||||
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].push(post)
|
||||
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