Skip to content

Commit

Permalink
Make metadata.author.email optional in virtual templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jun 12, 2024
1 parent 38b3a21 commit a36711c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/virtualTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ ${stylesheet ? `<?xml-stylesheet href="${stylesheet}" type="text/xsl"?>\n` : ""}
<id>{{ metadata.base | addPathPrefixToFullUrl }}</id>
<author>
<name>{{ metadata.author.name }}</name>
{%- if metadata.author.email %}
<email>{{ metadata.author.email }}</email>
{%- endif %}
</author>
{%- for post in collections['${collection.name}'] | reverse | head(${collection.limit}) %}
{%- set absolutePostUrl %}{{ post.url | htmlBaseUrl(metadata.base) }}{% endset %}
Expand All @@ -67,8 +69,9 @@ ${stylesheet ? `<?xml-stylesheet href="${stylesheet}" type="text/xsl"?>\n` : ""}
"description": "{{ metadata.description }}",
"authors": [
{
"name": "{{ metadata.author.name }}",
"url": "{{ metadata.author.url }}"
"name": "{{ metadata.author.name }}"{% if metadata.author.email %},
"url": "mailto:{{ metadata.author.email }}"
{%- endif %}
}
],
"items": [
Expand All @@ -91,18 +94,19 @@ ${stylesheet ? `<?xml-stylesheet href="${stylesheet}" type="text/xsl"?>\n` : ""}
}

async function eleventyFeedPlugin(eleventyConfig, options = {}) {
eleventyConfig.versionCheck(">=3.0.0-alpha.11");
eleventyConfig.versionCheck(pkg["11ty"].compatibility);

// Guaranteed unique
// Guaranteed unique, first add wins
const pluginRss = require("../.eleventy.js");
eleventyConfig.addPlugin(pluginRss, options.rssPluginOptions || {});

// Guaranteed unique
// Guaranteed unique, first add wins
const pluginHtmlBase = await eleventyConfig.resolvePlugin("@11ty/eleventy/html-base-plugin");
eleventyConfig.addPlugin(pluginHtmlBase, options.htmlBasePluginOptions || {});

let slugifyFilter = eleventyConfig.getFilter("slugify");
let inputPathSuffix = options?.metadata?.title ? `-${slugifyFilter(options?.metadata?.title)}` : "";

options = DeepCopy({
// rss and json also supported
type: "atom",
Expand All @@ -120,7 +124,7 @@ async function eleventyFeedPlugin(eleventyConfig, options = {}) {
base: "https://example.com/",
author: {
name: "Your Name",
email: "[email protected]"
email: "", // Optional
}
}
}, options);
Expand Down

0 comments on commit a36711c

Please sign in to comment.