Skip to content

Commit 629e422

Browse files
author
Farzad Hayatbakhsh
committed
DOC-2608: Move rssfeed.cjs to lib folder and add error handling to prevent build from failing
1 parent 68e654b commit 629e422

File tree

4 files changed

+104
-99
lines changed

4 files changed

+104
-99
lines changed

antora-playbook-local.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ asciidoc:
1919
- '@tinymce/antora-extension-livedemos'
2020
antora:
2121
extensions:
22-
- './rssfeed.cjs'
22+
- './lib/rssfeed.cjs'
2323
runtime:
2424
fetch: true

antora-playbook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ asciidoc:
2121
- '@tinymce/antora-extension-livedemos'
2222
antora:
2323
extensions:
24-
- './rssfeed.cjs'
24+
- './lib/rssfeed.cjs'
2525
runtime:
2626
fetch: true

lib/rssfeed.cjs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
"use strict";
2+
3+
const cheerio = require("cheerio");
4+
5+
module.exports.register = function () {
6+
this.on("beforePublish", ({ siteCatalog, contentCatalog, playbook }) => {
7+
try {
8+
// Find the changelog page
9+
const page = contentCatalog.findBy({ basename: "changelog.adoc" })[0];
10+
11+
if (!page) {
12+
console.error("changelog.adoc page not found.");
13+
return;
14+
}
15+
16+
// Destructure page attributes
17+
const {
18+
productname: productName,
19+
productmajorversion: productMajorVersion,
20+
doctitle: pageTitle,
21+
description: pageDescription,
22+
docname: pageName,
23+
"page-component-name": pageComponentName,
24+
"page-component-version": pageComponentVersion,
25+
} = page.asciidoc.attributes;
26+
27+
// Construct site links
28+
const siteLink = playbook.site.url;
29+
const siteLinkWithVersion = `${siteLink}/${pageComponentName}/${pageComponentVersion}`;
30+
31+
// Load page content with cheerio
32+
const $ = cheerio.load(page.contents.toString());
33+
34+
// Extract releases
35+
const releases = $(".sect1")
36+
.map((_, element) => {
37+
const $element = $(element);
38+
const linkElement = $element.find("a.xref");
39+
const [version, date] = linkElement.text().split(" - ");
40+
41+
// Remove <p> tags inside <li> tags to fix rendering issues
42+
const contentElement = $element.find(".sectionbody");
43+
contentElement.find("li > p").each((_, pElem) => {
44+
$(pElem).replaceWith($(pElem).html());
45+
});
46+
const content = contentElement.html();
47+
48+
return {
49+
title: linkElement.text(),
50+
link: `${siteLinkWithVersion}/${linkElement
51+
.attr("href")
52+
.replace("../", "")}`,
53+
description: `Release notes for TinyMCE ${version}`,
54+
guid: version,
55+
pubDate: new Date(date).toUTCString(),
56+
content,
57+
};
58+
})
59+
.get();
60+
61+
// Generate RSS feed items
62+
const rssItems = releases
63+
.map(
64+
({ title, link, description, guid, pubDate, content }) => `
65+
<item>
66+
<title>${title}</title>
67+
<link>${link}</link>
68+
<description>${description}</description>
69+
<guid isPermaLink="false">${guid}</guid>
70+
<pubDate>${pubDate}</pubDate>
71+
<content:encoded><![CDATA[${content}]]></content:encoded>
72+
</item>`
73+
)
74+
.join("\n");
75+
76+
// Assemble the complete RSS feed
77+
const rss = `<?xml version="1.0" encoding="UTF-8" ?>
78+
<rss version="2.0"
79+
xmlns:atom="http://www.w3.org/2005/Atom"
80+
xmlns:content="http://purl.org/rss/1.0/modules/content/"
81+
>
82+
<channel>
83+
<title>${productName} ${productMajorVersion} ${pageTitle}</title>
84+
<link>${siteLinkWithVersion}/${pageName}</link>
85+
<description>${pageDescription}</description>
86+
<language>en</language>
87+
<atom:link href="${siteLink}/rss.xml" rel="self" type="application/rss+xml" />
88+
${rssItems}
89+
</channel>
90+
</rss>`;
91+
92+
// Add RSS feed to site catalog
93+
siteCatalog.addFile({
94+
contents: Buffer.from(rss),
95+
out: { path: "rss.xml" },
96+
});
97+
} catch (error) {
98+
// Catch any errors to allow the build to continue
99+
console.error("Error generating RSS feed:", error);
100+
}
101+
});
102+
};

rssfeed.cjs

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)