Upgrade to Eleventy 3.0.0
Build and copy to prod / build-and-copy (push) Has been cancelled

This commit is contained in:
Lewis Dale committed 2024-10-06 12:36:54 +01:00
1 parent 862f12b4d0
commit e0c315d837
30 files changed
+2575 -3561

No files matched your search

-110
View File
@@ -1,110 +0,0 @@
const fs = require('fs');
const merge = require('lodash/merge')
const wordpressPassword = process.env.WORDPRESS_PASSWORD;
const auth = Buffer.from(`lewis:${wordpressPassword}`).toString('base64');
class PostCache {
constructor() {
this.readCache();
}
readCache() {
if (!fs.existsSync(".cache")) {
fs.mkdirSync(".cache");
}
if (!fs.existsSync(".cache/wordpress_post_fetch.json")) {
this.last_read_date = null;
this.posts = {};
} else {
const data = JSON.parse(fs.readFileSync(".cache/wordpress_post_fetch.json"));
this.last_read_date = new Date(data.last_read_date);
this.posts = data.posts;
}
}
writeCache() {
fs.writeFileSync(".cache/wordpress_post_fetch.json", JSON.stringify(this, null, 2));
}
async fetchCommentsByType(type = "comment") {
const params = new URLSearchParams();
params.set("per_page", 100);
params.set("type", type);
if (this.last_read_date) {
params.set("modified_after", this.last_read_date.toISOString());
}
const response = await fetch(`https://cms.lewisdale.dev/wp-json/wp/v2/comments?${params.toString()}`, {
headers: {
"Authorization": `Basic ${auth}`
}
});
return await response.json()
}
async fetchComments() {
const likes = await this.fetchCommentsByType("like");
const mentions = await this.fetchCommentsByType();
const reposts = await this.fetchCommentsByType("repost");
const comments = [...likes, ...mentions, ...reposts];
comments.forEach(comment => {
if (this.posts[comment.post]) {
this.posts[comment.post].comments[comment.id] = comment;
}
});
}
async fetchPosts() {
const params = new URLSearchParams();
params.set("per_page", 100);
if (this.last_read_date) {
params.set("modified_after", this.last_read_date.toISOString());
}
const response = await fetch(`https://cms.lewisdale.dev/wp-json/wp/v2/posts?${params.toString()}`, {
headers: {
"Authorization": `Basic ${auth}`
}
});
const posts = await response.json();
posts.forEach(post => {
this.posts[post.id] = merge({ comments: {} }, this.posts[post.id], post);
});
}
async fetchLatest() {
await this.fetchPosts();
await this.fetchComments();
await this.fetchTags();
this.last_read_date = new Date();
this.writeCache();
}
async fetchTags() {
const params = new URLSearchParams();
params.set("per_page", 100);
const response = await fetch(`https://cms.lewisdale.dev/wp-json/wp/v2/tags?${params.toString()}`, {
headers: {
"Authorization": `Basic ${auth}`
}
});
const tags = await response.json();
this.tags = tags.reduce((tagMap, tag) => ({...tagMap, [tag.id]: tag }), {});
}
}
const cache = new PostCache();
// module.exports = async function() {
// await cache.fetchLatest();
// return cache;
// }
+1 -1
View File
@@ -1 +1 @@
module.exports = process.env.ELEVENTY_RUN_MODE !== 'build';
export default process.env.ELEVENTY_RUN_MODE !== 'build';
+3 -2
View File
@@ -1,4 +1,5 @@
const fs = require('node:fs');
import fs from 'node:fs';
const apiKey = process.env.OMNIVORE_API_KEY;
const cacheFile = '.cache/links.json';
@@ -89,6 +90,6 @@ const fetchLatest = async (cache = []) => {
return cache;
}
module.exports = async function() {
export default async function() {
return await fetchLatest(cachedContent());
}
+2 -2
View File
@@ -1,11 +1,11 @@
const EleventyFetch = require("@11ty/eleventy-fetch");
import EleventyFetch from '@11ty/eleventy-fetch';
const siteId = "4f1be7ef-7fb4-4b08-81f1-68fb807a3063";
const apiKey = process.env.UMAMI_API_KEY;
const postRegex = /^\/post\//;
module.exports = async function(arg) {
export default async function(arg) {
const url = new URL(`https://umami.lewisdale.dev/api/websites/${siteId}/metrics`);
url.searchParams.append("startAt", 0);
url.searchParams.append("endAt", Date.now());
+1 -1
View File
@@ -1,6 +1,6 @@
const today = new Date();
module.exports = {
export default {
year: today.getFullYear(),
month: today.getMonth(),
day: today.getDate() + 1,
+1 -1
View File
@@ -42,7 +42,7 @@
<meta name="description" content="{{ excerpt if excerpt else description }}">
<meta name="fediverse:creator" content="@lewis@social.lol" />
{% ogImage "./src/_includes/components/ogImage.njk", { title: pageTitle or title, subTitle: description } %}
{% ogImage "./_includes/components/ogImage.njk", { title: pageTitle or title, subTitle: description } %}
{% if not dev %}
<script defer src="https://umami.lewisdale.dev/script.js" data-website-id="4f1be7ef-7fb4-4b08-81f1-68fb807a3063"></script>
+1 -1
View File
@@ -1,4 +1,4 @@
module.exports = {
export default {
tags: ['posts'],
layout: 'post.njk',
permalink: "/post/{{ data.slug if data.slug else title | slugify }}/",
+3 -3
View File
@@ -1,8 +1,8 @@
const EleventyFetch = require("@11ty/eleventy-fetch");
import EleventyFetch from "@11ty/eleventy-fetch";
module.exports = {
export default{
eleventyComputed: {
content: async () => {
nowContent: async () => {
// Retrieve the /now page from the server
const body = await EleventyFetch("https://api.omg.lol/address/lewis/now", {
type: 'json',
+1 -1
View File
@@ -3,4 +3,4 @@ title: My /now page
layout: page.njk
---
{{ content | safe }}
{{ nowContent | safe }}