Compare commits
2 Commits
bfdb9f8419
...
8ad99a35d4
Author | SHA1 | Date | |
---|---|---|---|
8ad99a35d4 | |||
a908843984 |
@ -28,6 +28,7 @@ My blog, originally based on the very helpful eleventy-base-blog v8, although it
|
|||||||
* Mastodon comment
|
* Mastodon comment
|
||||||
* Profile picture
|
* Profile picture
|
||||||
* Embedded toot
|
* Embedded toot
|
||||||
|
* Embed audio
|
||||||
|
|
||||||
### Quality of Life
|
### Quality of Life
|
||||||
* Copyright notice, default post image, alt text, and author details defined in `metadata.js`.
|
* Copyright notice, default post image, alt text, and author details defined in `metadata.js`.
|
||||||
|
@ -2,32 +2,43 @@ import { DateTime } from "luxon";
|
|||||||
import markdownIt from "markdown-it";
|
import markdownIt from "markdown-it";
|
||||||
import markdownItFootnote from "markdown-it-footnote";
|
import markdownItFootnote from "markdown-it-footnote";
|
||||||
import markdownItAnchor from "markdown-it-anchor";
|
import markdownItAnchor from "markdown-it-anchor";
|
||||||
import mdfigcaption from 'markdown-it-image-figures';
|
import mdfigcaption from "markdown-it-image-figures";
|
||||||
import pluginRss from "@11ty/eleventy-plugin-rss";
|
import pluginRss from "@11ty/eleventy-plugin-rss";
|
||||||
import pluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
|
import pluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
|
||||||
import pluginBundle from "@11ty/eleventy-plugin-bundle";
|
import pluginBundle from "@11ty/eleventy-plugin-bundle";
|
||||||
import pluginNavigation from "@11ty/eleventy-navigation";
|
import pluginNavigation from "@11ty/eleventy-navigation";
|
||||||
import prettier from "prettier";
|
import prettier from "prettier";
|
||||||
import { EleventyHtmlBasePlugin } from "@11ty/eleventy";
|
import { EleventyHtmlBasePlugin } from "@11ty/eleventy";
|
||||||
import {dateSuffixAdder, monthMap, timeFormatter} from "./public/js/modules/mastodonDateTools.js";
|
import {
|
||||||
|
dateSuffixAdder,
|
||||||
|
monthMap,
|
||||||
|
timeFormatter,
|
||||||
|
} from "./public/js/modules/mastodonDateTools.js";
|
||||||
|
|
||||||
const figoptions = {
|
const figoptions = {
|
||||||
figcaption: true
|
figcaption: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function(eleventyConfig) {
|
export default async function (eleventyConfig) {
|
||||||
|
|
||||||
// Helper Functions
|
// Helper Functions
|
||||||
const multiReplace = (text, replacementTable) => {
|
const multiReplace = (text, replacementTable) => {
|
||||||
let newText = text;
|
let newText = text;
|
||||||
replacementTable.forEach(x => { newText = newText.replace(x[0], x[1]) });
|
replacementTable.forEach((x) => {
|
||||||
|
newText = newText.replace(x[0], x[1]);
|
||||||
|
});
|
||||||
return newText;
|
return newText;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Transforms
|
// Transforms
|
||||||
eleventyConfig.addTransform("prettier", function (content, outputPath) {
|
eleventyConfig.addTransform("prettier", function (content, outputPath) {
|
||||||
if (outputPath && outputPath.endsWith(".html")) {
|
if (outputPath && outputPath.endsWith(".html")) {
|
||||||
return prettier.format(content, {parser: "html", bracketSameLine: true, vueIndentScriptAndStyle: true, singleAttributePerLine: true, htmlWhitespaceSensitivity: "css"});
|
return prettier.format(content, {
|
||||||
|
parser: "html",
|
||||||
|
bracketSameLine: true,
|
||||||
|
vueIndentScriptAndStyle: true,
|
||||||
|
singleAttributePerLine: true,
|
||||||
|
htmlWhitespaceSensitivity: "css",
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
@ -38,7 +49,7 @@ export default async function(eleventyConfig) {
|
|||||||
// Official plugins
|
// Official plugins
|
||||||
eleventyConfig.addPlugin(pluginRss);
|
eleventyConfig.addPlugin(pluginRss);
|
||||||
eleventyConfig.addPlugin(pluginSyntaxHighlight, {
|
eleventyConfig.addPlugin(pluginSyntaxHighlight, {
|
||||||
preAttributes: { tabindex: 0 }
|
preAttributes: { tabindex: 0 },
|
||||||
});
|
});
|
||||||
eleventyConfig.addPlugin(pluginNavigation);
|
eleventyConfig.addPlugin(pluginNavigation);
|
||||||
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
|
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
|
||||||
@ -47,37 +58,42 @@ export default async function(eleventyConfig) {
|
|||||||
// Filters
|
// Filters
|
||||||
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
|
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
|
||||||
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
|
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
|
||||||
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(format || "dd LLLL yyyy");
|
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(
|
||||||
|
format || "dd LLLL yyyy",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
|
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
|
||||||
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
|
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
|
||||||
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd');
|
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat("yyyy-LL-dd");
|
||||||
});
|
});
|
||||||
|
|
||||||
eleventyConfig.addFilter("removeMostRecent", arr => {
|
eleventyConfig.addFilter("removeMostRecent", (arr) => {
|
||||||
return arr.slice(0, arr.length-1);
|
return arr.slice(0, arr.length - 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Shortcodes
|
// Shortcodes
|
||||||
|
|
||||||
// Cowsay
|
// Cowsay
|
||||||
eleventyConfig.addFilter("cowsay", cowText => {
|
eleventyConfig.addFilter("cowsay", (cowText) => {
|
||||||
const cowCaptionReplacementTable = [
|
const cowCaptionReplacementTable = [
|
||||||
[`
|
[
|
||||||
|
`
|
||||||
o ^__^
|
o ^__^
|
||||||
o (oo)\\_______
|
o (oo)\\_______
|
||||||
(__)\\ )\\/\\
|
(__)\\ )\\/\\
|
||||||
||----w |
|
||----w |
|
||||||
|| ||`, ''],
|
|| ||`,
|
||||||
[/\(\s+/g, ''],
|
"",
|
||||||
[/\s+\(/g, ''],
|
],
|
||||||
[/_{3,}/g, ''],
|
[/\(\s+/g, ""],
|
||||||
[/-{3,}/g, ''],
|
[/\s+\(/g, ""],
|
||||||
[/\s\)/g, ''],
|
[/_{3,}/g, ""],
|
||||||
[/\n/g, ''],
|
[/-{3,}/g, ""],
|
||||||
[/\s{2,}/g, ' '],
|
[/\s\)/g, ""],
|
||||||
[/^ /, '']
|
[/\n/g, ""],
|
||||||
|
[/\s{2,}/g, " "],
|
||||||
|
[/^ /, ""],
|
||||||
];
|
];
|
||||||
|
|
||||||
return `
|
return `
|
||||||
@ -92,10 +108,8 @@ export default async function(eleventyConfig) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Embed a toot
|
// Embed a toot
|
||||||
eleventyConfig.addAsyncShortcode("toot", async function(instance, ID) {
|
eleventyConfig.addAsyncShortcode("toot", async function (instance, ID) {
|
||||||
const tootData = await fetch(
|
const tootData = await fetch(`https://${instance}/api/v1/statuses/${ID}`);
|
||||||
`https://${instance}/api/v1/statuses/${ID}`
|
|
||||||
);
|
|
||||||
|
|
||||||
const toot = await tootData.json();
|
const toot = await tootData.json();
|
||||||
|
|
||||||
@ -114,12 +128,29 @@ export default async function(eleventyConfig) {
|
|||||||
publish_date="${dateTime}"
|
publish_date="${dateTime}"
|
||||||
sharp_corner="">
|
sharp_corner="">
|
||||||
</wc-toot>
|
</wc-toot>
|
||||||
`
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Embed audio
|
||||||
|
eleventyConfig.addShortcode(
|
||||||
|
"audio",
|
||||||
|
function (title, artist, media_url, cover_url) {
|
||||||
|
return `
|
||||||
|
<wc-card>
|
||||||
|
<wc-mplayer
|
||||||
|
title="${title}"
|
||||||
|
artist="${artist}"
|
||||||
|
media_url="${media_url}"
|
||||||
|
cover_url="${cover_url}"
|
||||||
|
/>
|
||||||
|
</wc-card>
|
||||||
|
`;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Passthrough
|
// Passthrough
|
||||||
|
|
||||||
eleventyConfig.addPassthroughCopy({ './public/': "/" });
|
eleventyConfig.addPassthroughCopy({ "./public/": "/" });
|
||||||
|
|
||||||
// Get the first `n` elements of a collection.
|
// Get the first `n` elements of a collection.
|
||||||
eleventyConfig.addFilter("head", (array, n) => {
|
eleventyConfig.addFilter("head", (array, n) => {
|
||||||
@ -139,62 +170,59 @@ export default async function(eleventyConfig) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Return all the tags used in a collection
|
// Return all the tags used in a collection
|
||||||
eleventyConfig.addFilter("getAllTags", collection => {
|
eleventyConfig.addFilter("getAllTags", (collection) => {
|
||||||
let tagSet = new Set();
|
let tagSet = new Set();
|
||||||
for (let item of collection) {
|
for (let item of collection) {
|
||||||
(item.data.tags || []).forEach(tag => tagSet.add(tag));
|
(item.data.tags || []).forEach((tag) => tagSet.add(tag));
|
||||||
}
|
}
|
||||||
return Array.from(tagSet);
|
return Array.from(tagSet);
|
||||||
});
|
});
|
||||||
|
|
||||||
eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
|
eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
|
||||||
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
|
return (tags || []).filter(
|
||||||
|
(tag) => ["all", "nav", "post", "posts"].indexOf(tag) === -1,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Customize Markdown library settings:
|
// Customize Markdown library settings:
|
||||||
let markdownItOptions = {
|
let markdownItOptions = {
|
||||||
html: true,
|
html: true,
|
||||||
typographer: true
|
typographer: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mdLib = markdownIt(markdownItOptions);
|
let mdLib = markdownIt(markdownItOptions);
|
||||||
|
|
||||||
eleventyConfig.amendLibrary("md", mdLib => {
|
eleventyConfig.amendLibrary("md", (mdLib) => {
|
||||||
mdLib
|
mdLib
|
||||||
.use(markdownItAnchor, {
|
.use(markdownItAnchor, {
|
||||||
permalink: markdownItAnchor.permalink.ariaHidden({
|
permalink: markdownItAnchor.permalink.ariaHidden({
|
||||||
placement: "after",
|
placement: "after",
|
||||||
class: "header-anchor",
|
class: "header-anchor",
|
||||||
symbol: "#",
|
symbol: "#",
|
||||||
ariaHidden: false
|
ariaHidden: false,
|
||||||
}),
|
}),
|
||||||
level: [1, 2, 3, 4],
|
level: [1, 2, 3, 4],
|
||||||
slugify: eleventyConfig.getFilter("slugify")
|
slugify: eleventyConfig.getFilter("slugify"),
|
||||||
})
|
})
|
||||||
.use(markdownItFootnote)
|
.use(markdownItFootnote)
|
||||||
.use(mdfigcaption, figoptions);
|
.use(mdfigcaption, figoptions);
|
||||||
});
|
});
|
||||||
|
|
||||||
eleventyConfig.setLibrary("md", mdLib);
|
eleventyConfig.setLibrary("md", mdLib);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
templateFormats: [
|
templateFormats: ["md", "njk", "html", "liquid"],
|
||||||
"md",
|
|
||||||
"njk",
|
|
||||||
"html",
|
|
||||||
"liquid",
|
|
||||||
],
|
|
||||||
|
|
||||||
markdownTemplateEngine: "njk",
|
markdownTemplateEngine: "njk",
|
||||||
|
|
||||||
htmlTemplateEngine: "njk",
|
htmlTemplateEngine: "njk",
|
||||||
|
|
||||||
dir: {
|
dir: {
|
||||||
input: "content", // default: "."
|
input: "content", // default: "."
|
||||||
includes: "../_includes", // default: "_includes"
|
includes: "../_includes", // default: "_includes"
|
||||||
data: "../_data", // default: "_data"
|
data: "../_data", // default: "_data"
|
||||||
output: "_site"
|
output: "_site",
|
||||||
},
|
},
|
||||||
pathPrefix: "/",
|
pathPrefix: "/",
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
@ -219,6 +219,9 @@ code {
|
|||||||
background-color: var(--card-color);
|
background-color: var(--card-color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.links-nextprev > .postlist-item-container {
|
||||||
|
grid-column: var(--span-grid);
|
||||||
|
}
|
||||||
header,
|
header,
|
||||||
footer,
|
footer,
|
||||||
main {
|
main {
|
||||||
@ -448,6 +451,52 @@ table th {
|
|||||||
padding-right: 1em;
|
padding-right: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Audio Player */
|
||||||
|
wc-mplayer {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
wc-mplayer::part(artist) {
|
||||||
|
font-size: var(--meta-font-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
wc-mplayer::part(cover),
|
||||||
|
wc-mplayer::part(coverContainer) {
|
||||||
|
width: var(--space-3xl);
|
||||||
|
height: var(--space-3xl);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
wc-mplayer::part(captionAndPlayer) {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: column nowrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
wc-mplayer::part(main) {
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
display: flex;
|
||||||
|
gap: var(--space-s);
|
||||||
|
margin: 0;
|
||||||
|
padding: var(--space-m);
|
||||||
|
}
|
||||||
|
|
||||||
|
wc-mplayer::part(player) {
|
||||||
|
align-self: flex-end;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
wc-mplayer::part(title) {
|
||||||
|
font-size: var(--step-1);
|
||||||
|
font-variation-settings:
|
||||||
|
"opsz" 50,
|
||||||
|
"wght" 350,
|
||||||
|
"SOFT" 20,
|
||||||
|
"WONK" 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Comments */
|
/* Comments */
|
||||||
#comments {
|
#comments {
|
||||||
grid-column: var(--span-grid);
|
grid-column: var(--span-grid);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import './webComponents/card.js';
|
import "./webComponents/card.js";
|
||||||
import './webComponents/profilePic.js';
|
import "./webComponents/profilePic.js";
|
||||||
import './webComponents/comment.js';
|
import "./webComponents/comment.js";
|
||||||
import './webComponents/toot.js';
|
import "./webComponents/toot.js";
|
||||||
|
import "./webComponents/musicPlayer.js";
|
||||||
|
51
public/js/webComponents/musicPlayer.js
Normal file
51
public/js/webComponents/musicPlayer.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
const template = document.createElement("template");
|
||||||
|
|
||||||
|
template.innerHTML = `
|
||||||
|
<style>
|
||||||
|
.cover {
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<figure class="mplayer" part="main">
|
||||||
|
<div class="coverContainer" part="coverContainer">
|
||||||
|
<img src="" class="cover" part="cover">
|
||||||
|
</div>
|
||||||
|
<div part="captionAndPlayer">
|
||||||
|
<figcaption part="caption">
|
||||||
|
<span class="title" part="title"></span><br /><span class="artist" part="artist"></span>
|
||||||
|
</figcaption>
|
||||||
|
<audio controls src="" class="player" part="player"></audio>
|
||||||
|
</div>
|
||||||
|
</figure>
|
||||||
|
`;
|
||||||
|
|
||||||
|
class mplayer extends HTMLElement {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this._shadowRoot = this.attachShadow({ mode: "open" });
|
||||||
|
this._shadowRoot.appendChild(template.content.cloneNode(true));
|
||||||
|
this.$mplayer = this._shadowRoot.querySelector(".mplayer");
|
||||||
|
}
|
||||||
|
|
||||||
|
static get observedAttributes() {
|
||||||
|
return ["title", "artist", "media_url", "cover_url"];
|
||||||
|
}
|
||||||
|
|
||||||
|
attributeChangedCallback(name, oldVal, newVal) {
|
||||||
|
if (oldVal != newVal) {
|
||||||
|
this[name] = newVal;
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
this.$mplayer.querySelector(".title").innerHTML = this.title;
|
||||||
|
this.$mplayer.querySelector(".artist").innerHTML = this.artist;
|
||||||
|
this.$mplayer.querySelector(".player").src = this.media_url;
|
||||||
|
this.$mplayer.querySelector(".coverContainer > img").src = this.cover_url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.customElements.define("wc-mplayer", mplayer);
|
Loading…
x
Reference in New Issue
Block a user