site data, twitter/opengraph headers

This commit is contained in:
Joshua Seigler 2024-06-07 15:39:27 -04:00
parent 42818405c1
commit 7cd73f703f
14 changed files with 52 additions and 16 deletions

View file

@ -4,7 +4,9 @@ const md = require("markdown-it");
const mdAnchor = require("markdown-it-anchor");
const mdFootnote = require("markdown-it-footnote");
const prettier = require("prettier");
const dayjs = require("dayjs")
const clean = require("eleventy-plugin-clean");
const site = require("./site/_data/site");
module.exports = (config) => {
const slugify = config.getFilter("slugify");
@ -21,10 +23,10 @@ module.exports = (config) => {
symbol: "",
}),
})
.use(mdFootnote)
.use(mdFootnote);
config.setLibrary("md", mdLib);
config.addPassthroughCopy({
"assets": "/"
assets: "/",
});
// collection from music folder
@ -52,8 +54,8 @@ module.exports = (config) => {
});
config.addTransform("prettier", (content, outputPath) => {
if (typeof outputPath !== 'string') {
return content
if (typeof outputPath !== "string") {
return content;
}
const extname = path.extname(outputPath);
switch (extname) {
@ -66,7 +68,17 @@ module.exports = (config) => {
default:
return content;
}
})
});
config.addFilter("absoluteURL", (url) => {
return new URL(url, site.baseUrl).href;
});
config.addFilter("toISOString", (dateString) => {
return new Date(dateString).toISOString()
});
config.addFilter("formatDate", (date, format) => {
return dayjs(date).format(format);
});
clean.updateFileRecord("dist");
return {

View file

@ -12,6 +12,7 @@
"license": "ISC",
"dependencies": {
"@11ty/eleventy": "^2.0.1",
"dayjs": "^1.11.11",
"eleventy-plugin-clean": "^1.2.6",
"markdown-it-anchor": "^9.0.1",
"markdown-it-footnote": "^4.0.0",

8
pnpm-lock.yaml generated
View file

@ -11,6 +11,9 @@ importers:
'@11ty/eleventy':
specifier: ^2.0.1
version: 2.0.1
dayjs:
specifier: ^1.11.11
version: 1.11.11
eleventy-plugin-clean:
specifier: ^1.2.6
version: 1.2.6(@11ty/eleventy@2.0.1)
@ -291,6 +294,9 @@ packages:
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
engines: {node: '>= 8'}
dayjs@1.11.11:
resolution: {integrity: sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg==}
debug@2.6.9:
resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==}
peerDependencies:
@ -1244,6 +1250,8 @@ snapshots:
shebang-command: 2.0.0
which: 2.0.2
dayjs@1.11.11: {}
debug@2.6.9:
dependencies:
ms: 2.0.0

9
site/_data/site.js Normal file
View file

@ -0,0 +1,9 @@
const isDev = process.env.ELEVENTY_ENV === "development";
const baseUrl = isDev ? "localhost:8080" : "https://joshua.seigler.net/";
module.exports = {
title: "joshua.seigler.net",
description: "Personal homepage of Joshua Seigler",
baseUrl,
};

View file

@ -1,7 +1,7 @@
<header>
<nav>
<div class="nav-categories">
<a href="{{ "/" | url }}">joshua.seigler.net</a>
<a href="{{ "/" | url }}">{{ site.title }}</a>
<a href="{{ "/posts" | url }}">/posts</a>
<a href="{{ "/timeline" | url }}">/timeline</a>
<a href="{{ "/recipes" | url }}">/recipes</a>
@ -31,8 +31,8 @@
{%-if author -%}
<author>{{ author }}</author>
{%- endif -%}
{%- if dateString -%}
<date>{{ dateString }}</date>
{%- if date -%}
<date>{{ date | formatDate("MMMM D, YYYY") }}</date>
{%- endif -%}
</div>
</header>

View file

@ -1,14 +1,22 @@
---
title: Joshua's Homepage
---
{%- set computedTitle = tag | capitalize if tag else title -%}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ "/site.css" | url }}"/>
<title>{{ tag | capitalize if tag else title }} - joshua.seigler.net</title>
<title>{{ computedTitle }} - {{ site.title }}</title>
<meta property="og:title" content="{{ computedTitle }}" />
<meta property="og:type" content="{{ article }}" />
<meta property="og:url" content="{{ url | absoluteURL }}" />
{# <meta property="og:image" content="https://....jpg" /> #}
<meta name="twitter:title" content="{{ computedTitle }}">
<meta name="twitter:description" content="{{ description }}">
{# <meta name="twitter:image" content="https://....jpg"> #}
<meta name="twitter:card" content="summary">
</head>
<body data-font="english" data-path="{{page.url}}">
{% include "-header.njk" %}

View file

@ -10,7 +10,7 @@ eleventyComputed:
{% for item in collections[tag] | reverse %}
<article class="item-summary">
<a href="{{ item.url }}">{{ item.data.title }}</a>
{% if item.data.dateString %}<aside>{{item.data.dateString}}</aside>{% endif %}
{% if item.data.date %}<aside>{{item.data.date | formatDate("MMMM DD, YYYY")}}</aside>{% endif %}
<p class="item-summary-description">{{ item.data.description }}</p>
</article>
{% endfor %}

View file

@ -1,11 +1,9 @@
const { DateTime } = require("luxon");
module.exports = {
layout: "post.njk",
permalink: "/posts/{{ title | slugify }}/",
tags: ["posts"],
author: "Joshua Seigler",
eleventyComputed: {
dateString: ({ page }) => DateTime.fromJSDate(page.date, { zone: 'utc' }).toLocaleString(DateTime.DATE_FULL)
},
author: "Joshua Seigler"
date: "{{ page.date }}"
}
};