Convert YT links in feed to embeds
This commit is contained in:
parent
c918521429
commit
f8a2d73280
2 changed files with 12 additions and 5 deletions
15
.eleventy.js
15
.eleventy.js
|
|
@ -8,7 +8,7 @@ const markdownItEleventyImg = require("markdown-it-eleventy-img");
|
|||
const pluginRss = require("@11ty/eleventy-plugin-rss");
|
||||
const embedYouTube = require("eleventy-plugin-youtube-embed");
|
||||
|
||||
module.exports = function (eleventyConfig) {
|
||||
module.exports = function(eleventyConfig) {
|
||||
eleventyConfig.addPlugin(embedYouTube);
|
||||
eleventyConfig.addPlugin(pluginRss);
|
||||
|
||||
|
|
@ -20,10 +20,10 @@ module.exports = function (eleventyConfig) {
|
|||
"node_modules/simpledotcss/simple.css": "css/simple.css",
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter("stringToDate", function (value) {
|
||||
eleventyConfig.addFilter("stringToDate", function(value) {
|
||||
return new Date(value);
|
||||
});
|
||||
eleventyConfig.addFilter("formatDatetimeForHumans", function (value) {
|
||||
eleventyConfig.addFilter("formatDatetimeForHumans", function(value) {
|
||||
const dt = new Date(value);
|
||||
const formattedDt = new Intl.DateTimeFormat("en", {
|
||||
dateStyle: "medium",
|
||||
|
|
@ -31,13 +31,20 @@ module.exports = function (eleventyConfig) {
|
|||
}).format(dt);
|
||||
return formattedDt;
|
||||
});
|
||||
eleventyConfig.addFilter("formatDateForHumans", function (value) {
|
||||
eleventyConfig.addFilter("formatDateForHumans", function(value) {
|
||||
const dt = new Date(value);
|
||||
const formattedDt = new Intl.DateTimeFormat("en", {
|
||||
dateStyle: "medium",
|
||||
}).format(dt);
|
||||
return formattedDt;
|
||||
});
|
||||
eleventyConfig.addFilter("convertYouTubeURLsToEmbeds", function(value) {
|
||||
const youtubeUrlRegex = /<p>\s*(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?!channel\/|@)([^\s&<>"']*)\s*<\/p>/gim;
|
||||
return value.replace(youtubeUrlRegex, function(match, videoId) {
|
||||
return '<iframe width="560" height="315" src="https://www.youtube.com/embed/' + videoId + '" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
const markdownLibrary = markdownIt()
|
||||
.use(markdownItAnchor, { slugify })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue