Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC-2608: Add an RSS feed for the TinyMCE Changelog #3566

Open
wants to merge 18 commits into
base: tinymce/7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
97f0693
DOC-2608: Initial prototype - no posts yet
FarzadHayat Dec 20, 2024
867d112
DOC-2608: Add extension to antora-playbook.yml
FarzadHayat Dec 20, 2024
a26c44c
DOC-2608: Populate RSS with changelog.adoc content
FarzadHayat Dec 20, 2024
c4a2a78
DOC-2608: Attempt to fix <li> tag rendering issue
FarzadHayat Dec 20, 2024
68e654b
DOC-2608: Add purl.org's content module for encoded content
FarzadHayat Dec 20, 2024
629e422
DOC-2608: Move rssfeed.cjs to lib folder and add error handling to pr…
FarzadHayat Dec 21, 2024
f99263d
DOC-2608: Fix error in item description
FarzadHayat Dec 21, 2024
3c275a7
DOC-2608: Move input and output file names into Antora playbook config
FarzadHayat Dec 21, 2024
32e5a8d
DOC-2608: Normalize version if it's missing the minor or patch version
FarzadHayat Dec 21, 2024
7b1599a
DOC-2608: Add copyright info to RSS
FarzadHayat Dec 21, 2024
9c88453
Fix code scanning alert no. 35: Incomplete string escaping or encoding
FarzadHayat Dec 23, 2024
088e542
DOC-2608: Time the RSS feed generation and log it
FarzadHayat Dec 25, 2024
daadb63
DOC-2608: Rename 'lib' folder to 'extensions'
FarzadHayat Jan 1, 2025
6d8218b
DOC-2608: Add link to RSS feed in changelog page
FarzadHayat Jan 2, 2025
b8cb65d
DOC-2608: Make changelog RSS url into an Antora attribute
FarzadHayat Jan 2, 2025
6653816
DOC-2608: Use {site-url} attribute instead of hard-coded RSS link
FarzadHayat Jan 2, 2025
c29fe34
DOC-2608: Generate RSS file in tinymce/latest folder
FarzadHayat Jan 2, 2025
852e77b
DOC-2608: Fix Atom link
FarzadHayat Jan 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions antora-playbook-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ ui:
asciidoc:
extensions:
- '@tinymce/antora-extension-livedemos'
antora:
extensions:
- require: './extensions/rssfeed.cjs'
input_file: 'changelog.adoc'
output_file: 'rss.xml'
runtime:
fetch: true
5 changes: 5 additions & 0 deletions antora-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ ui:
asciidoc:
extensions:
- '@tinymce/antora-extension-livedemos'
antora:
extensions:
- require: './extensions/rssfeed.cjs'
input_file: 'changelog.adoc'
output_file: 'rss.xml'
runtime:
fetch: true
120 changes: 120 additions & 0 deletions extensions/rssfeed.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"use strict";

const cheerio = require("cheerio");

module.exports.register = function ({ config }) {
this.on("beforePublish", ({ siteCatalog, contentCatalog, playbook }) => {
const startTime = Date.now(); // Start the timer

try {
// Find the changelog page
const page = contentCatalog.findBy({
basename: config.inputFile,
})[0];

if (!page) {
throw new Error(`${config.inputFile} page not found.`);
}

// Destructure page attributes
const {
productname: productName,
productmajorversion: productMajorVersion,
doctitle: pageTitle,
description: pageDescription,
docname: pageName,
"page-component-name": pageComponentName,
"page-component-version": pageComponentVersion,
} = page.asciidoc.attributes;

// Construct site links
const siteLink = playbook.site.url;
const siteLinkWithVersion = `${siteLink}/${pageComponentName}/${pageComponentVersion}`;

// Load page content with cheerio
const $ = cheerio.load(page.contents.toString());

// Extract releases
const releases = $(".sect1")
.map((_, element) => {
const $element = $(element);
const linkElement = $element.find("a.xref");
let [version, date] = linkElement.text().split(" - ");

// Normalize version if it's missing the minor or patch version
const versionParts = version.split(".");
if (versionParts.length === 1) {
version += ".0.0";
} else if (versionParts.length === 2) {
version += ".0";
}

// Remove <p> tags inside <li> tags to fix rendering issues
const contentElement = $element.find(".sectionbody");
contentElement.find("li > p").each((_, pElem) => {
$(pElem).replaceWith($(pElem).html());
});
const content = contentElement.html();

return {
title: linkElement.text(),
link: `${siteLinkWithVersion}/${linkElement
.attr("href")
.replace(/\.\.\//g, "")}`,
Dismissed Show dismissed Hide dismissed
description: `Changelog for TinyMCE ${version}`,
guid: version,
pubDate: new Date(date).toUTCString(),
content,
};
})
.get();

// Generate RSS feed items
const rssItems = releases
.map(
({ title, link, description, guid, pubDate, content }) => `
<item>
<title>${title}</title>
<link>${link}</link>
<description>${description}</description>
<guid isPermaLink="false">${guid}</guid>
<pubDate>${pubDate}</pubDate>
<content:encoded><![CDATA[${content}]]></content:encoded>
</item>`
)
.join("\n");

// Assemble the complete RSS feed
const rss = `<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
>
<channel>
<title>${productName} ${productMajorVersion} ${pageTitle}</title>
<link>${siteLinkWithVersion}/${pageName}</link>
<description>${pageDescription}</description>
<language>en</language>
<copyright>Creative Commons Legal Code - Attribution-NonCommercial-ShareAlike 3.0 Unported</copyright>
<atom:link href="${siteLink}/rss.xml" rel="self" type="application/rss+xml" />
${rssItems}
</channel>
</rss>`;

// Add RSS feed to site catalog
siteCatalog.addFile({
contents: Buffer.from(rss),
out: { path: config.outputFile },
});

const endTime = Date.now(); // End the timer
const duration = endTime - startTime; // Calculate the duration
console.log(
`RSS feed generated at ${config.outputFile} in ${duration}ms`
);
} catch (error) {
// Catch any errors to allow the build to continue
console.error("Error generating RSS feed:", error);
}
});
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@antora/site-generator-default": "^3.0.1",
"@tinymce/antora-extension-livedemos": "^0.1.0",
"@tinymce/moxiedoc": "^0.3.0",
"cheerio": "^1.0.0",
"dotenv": "^16.0.0",
"ecstatic": "^4.1.4",
"http-server": "^0.12.3",
Expand Down
Loading
Loading