Tucker McKnight
Skip things that can't be done if plugins are missing RSS feed creationg, syntax highlighting, and readme display rely on other 11ty plugins being installed in order for them to work. If those plugins are not installed, skip those parts of the site generation.
15 16 17
// TODO: check if the render plugin is available and throw an error otherwise
// TODO: check if the highlight function is available
// TODO: throw an error if reposConfiguration is undefined
15 16 17
109
return eleventyConfig.javascript.functions.highlight(language, code)
109
const highlighter = eleventyConfig?.javascript?.functions?.highlight
if (highlighter) {
return highlighter(language, code)
}
else {
return code
}
})
eleventyConfig.addAsyncFilter("renderContentIfAvailable", async (contentString, contentType) => {
const renderer = eleventyConfig?.javascript?.functions?.renderContent
if (renderer) {
return await renderer.bind({})(contentString, contentType)
}
else {
return `<pre>${contentString}</pre>`
}
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
const feedTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/feed.njk`).toString()
eleventyConfig.addTemplate(
`repos/feed.njk`,
feedTemplate,
{
pagination: {
data: "branches",
size: 1,
alias: "branch",
},
permalink: (data) => {
const repoName = data.branch.repoName
const branchName = data.branch.branchName
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/branches/${eleventyConfig.getFilter("slugify")(branchName)}/patches.xml`
},
eleventyExcludeFromCollections: true,
}
)
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
// htmlBaseUrl is a function defined by the 11ty RSS plugin.
// Skip this virtual template if the 11ty RSS plugin is not being used.
let rssAvailable = false
if (eleventyConfig?.javascript?.functions?.htmlBaseUrl) {
rssAvailable = true
const feedTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/feed.njk`).toString()
eleventyConfig.addTemplate(
`repos/feed.njk`,
feedTemplate,
{
pagination: {
data: "branches",
size: 1,
alias: "branch",
},
permalink: (data) => {
const repoName = data.branch.repoName
const branchName = data.branch.branchName
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/branches/${eleventyConfig.getFilter("slugify")(branchName)}/patches.xml`
},
eleventyExcludeFromCollections: true,
}
)
}
// This is used to show/hide the RSS feed link on the landing page.
eleventyConfig.addGlobalData('rssAvailable', rssAvailable)
1
{{ branch.repoName | getReadMe(branch.branchName) | renderContent("md") | safe }}
1
{{ branch.repoName | getReadMe(branch.branchName) | renderContentIfAvailable("md") | safe }}
9 10 11
<div class="col-auto">
<a href="{{reposPath}}/{{ branch.repoName | slugify }}/branches/{{ branch.branchName | slugify }}/patches.xml" class="initialism">RSS<i class="bi bi-rss-fill ms-2" style="color: orange;"></i></a>
</div>
9 10 11
{% if rssAvailable %}
<div class="col-auto">
<a href="{{reposPath}}/{{ branch.repoName | slugify }}/branches/{{ branch.branchName | slugify }}/patches.xml" class="initialism">RSS<i class="bi bi-rss-fill ms-2" style="color: orange;"></i></a>
</div>
{% endif %}